if else help

Hi im new to programming but im needing help inside my if.
in the game it works it makes it so i dont have to reload and it sets the ammo amount everytime it reloads the gun, but once it gets to 0 ammo left it still reloads and freezes the game. this is what i have below.
Thanks for your time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
			if(*(int*)NoReload9 == 0){
				if(*(int*)Ammo9 == 0){
					if(SR25){
							if(*(int*)Ammo9 > 0){
								if((*(int*)Ammo9 == 0 && *(int*)NoReload9 <= 10)){
									//do nothing
									D3DNoReload = 0;
								}
								else{
									*(int*)Ammo9 = *(int*)Ammo9-10;
									*(int*)NoReload9 = 10;
							}

						}
					}
				}
			}
I am not try to criticize or help you but I feel your liberal use of * will make program maintenance much harder in future. Is it a pure C or C++ program? If C++, I am sure some of the pointer variables can be replaced with reference variables instead.
Well, on line 1/2 you ensure that 'NoReload9' and 'Ammo9' are actually 0. It does not make sense to check them against other values within that if clause where you know it's 0.

So the (*(int*)Ammo9 > 0) will never be true on line 4
ok thanks for the help i will have another look at it.
and its a .dll that gets injected
Ok i have tryed to redo my code.
But what happens is when i get down to my last shot left the game freezes.

1
2
3
4
5
6
				if((*(int*)NoReload9 == 0) && (*(int*)Ammo9 >= 10)){ //Checks If needs reload & Checks if ammo is more then 10 or =
					if(SR25){ //Checks Weapon
						*(int*)Ammo9 = *(int*)Ammo9-10; //Checks amount of ammo then takes 10 off
						*(int*)NoReload9 = 10; //Sets amount of ammo in the gun
					}
				}


NoReload9 is the amount of ammo in gun
Ammo9 is the amount of ammo left to use, so really the ammo in the clip.
Last edited on
The program usually freezes when you have an infinite loop. Probably you have contradicting expression in the head of your loop.
so i should put a sleep in it or something? will that fix it?
will that fix it?
No. It will block your game nevertheless. Fix your loop condition. (if it's actually so, since you don't show the code, I cannot say it for sure)
I don't really understand. It's in the dip.
Topic archived. No new replies allowed.