Gamestudio Links
Zorro Links
Newest Posts
Removing outliers from files
by AndrewAMD. 12/02/26 15:26
SGT_FW
by Aku_Aku. 11/30/26 08:19
Experiences with cTrader
by JeyKey II. 11/27/26 09:04
make a complaint
by EW_bytes. 11/26/26 23:00
FXCM => AVA Trade Plugin???
by Martin_HH. 11/25/26 21:59
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
What are you working on?
by rayp. 11/20/26 18:10
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Grant), 6,791 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Reloading algorithm #401920
05/26/12 05:40
05/26/12 05:40
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Hey guys, so I am looking for a reloading algorithm. Something where...

X = Current Ammo (Maximum of 30)
Y = Ammo left

So when you activate the reload sequence...

if X=24 and Y=60, then X=30 and Y=54

if X=15 and Y=4, then X=19 and Y=0

if X=19 and Y=15, then X=30 and Y=4

I have been trying and trying to get this working and to no avail. All of the solutions I made work, but they require a ton of if/else statements and I know there is a much more simple way of doing this. So, anyone have any ideas?

Re: Reloading algorithm [Re: exile] #401922
05/26/12 07:28
05/26/12 07:28
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Code:
var ammo_reload = minv(
    ammo_left,          // Maximum is ammo_left, so we can't reload bullets we don't have
    30 - ammo_current); // Calculate missing ammo in weapon
ammo_left -= ammo_reload;
ammo_current += ammmo_reload;


Should do the stuff you want


Visit my site: www.masterq32.de
Re: Reloading algorithm [Re: MasterQ32] #401923
05/26/12 08:04
05/26/12 08:04
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Perfect! I never even knew about minv! After seeing how its used I could use this to reduce the amount of code I have. Thanks MasterQ32, With your permission would I be able to add this to a contribution I am making? Essentially, its a big contribution with code snippets and other useful things for beginning and advanced programmers alike. With credit going to you of course.

Re: Reloading algorithm [Re: exile] #401927
05/26/12 11:01
05/26/12 11:01
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
no problem, you don't need to credit me for this snippet, but if you want, you can grin


Visit my site: www.masterq32.de

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1