Spoiler: CodeCode: Select all
ACTOR InsertedClip : Ammo { Inventory.MaxAmount 12 } ACTOR Pistol2 : Pistol replaces Pistol { Weapon.AmmoType "InsertedClip" Weapon.AmmoType2 "Clip" Weapon.AmmoGive 0 Weapon.AmmoGive2 12 Weapon.AmmoUse 1 States { Fire: PISG A 2 PISG D 7 A_FirePistol PISG D 0 A_JumpIfNoAmmo("CheckAmmo") PISG C 3 PISG B 5 A_ReFire Goto Ready Flash: PISF A 2 Bright A_Light1 PISF B 3 Bright A_Light2 PISF A 2 Bright A_Light1 Goto LightDone AltFire: goto CheckAmmo CheckAmmo: TNT1 A 0 A_JumpIfInventory("Clip", 12, "ReloadStart") goto ready ReloadStart: PISG A 0 A_JumpIfInventory("Clip", 1, 1) goto NoReload PISG A 0 A_JumpIfInventory("InsertedClip", 0, "NoReload") PISG DD 3 goto ReloadLoop ReloadLoop: TNT1 A 0 A_TakeInventory("Clip", 12) PISG D 10 Offset(0,34) A_GiveInventory("InsertedClip", 12) PISG D 10 Offset(0,44) A_PlaySound("weapons/pistolload") TNT1 A 0 A_JumpIfInventory("InsertedClip", 0, "ReloadEnd") TNT1 A 0 A_JumpIfInventory("Clip", 1, "ReloadLoop") Goto ReloadEnd ReloadEnd: PISG C 3 Goto Ready NoReload: PISG D 2 PISG D 7 A_FirePistol PISG C 3 Goto Ready } }
How to reload only if you have enough ammo
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
- middlefingerman
- Posts: 52
- Joined: Mon May 04, 2020 12:55 pm
- Location: On the toilet
- Contact:
How to reload only if you have enough ammo
My code here is attempting to do this, however, if i have 11 clips, it will still reload and load 12 clips
Spoiler: Code
Last edited by middlefingerman on Wed May 27, 2020 3:42 pm, edited 3 times in total.
Re: How to reload only if you have enough ammo
So, you are trying to make this pistol reload only if the player has 12 or more clips, right?
When I copied the code and checked it, the pistol didn't reload when I had only 11 clips.
The code works properly for me, the pistol reloads only when the player has at least 12 ammo in reserve.
Maybe the issue is somewhere else?
Does the player start with this pistol?
Putting "replaces Pistol" into the weapon won't make the player start with it.
Instead a new player class has to be defined that has this weapon as a "StartItem".
For reference, here's Doomguy and here's how to add custom classes.
When I copied the code and checked it, the pistol didn't reload when I had only 11 clips.
The code works properly for me, the pistol reloads only when the player has at least 12 ammo in reserve.
Maybe the issue is somewhere else?
Does the player start with this pistol?
Putting "replaces Pistol" into the weapon won't make the player start with it.
Instead a new player class has to be defined that has this weapon as a "StartItem".
For reference, here's Doomguy and here's how to add custom classes.
- middlefingerman
- Posts: 52
- Joined: Mon May 04, 2020 12:55 pm
- Location: On the toilet
- Contact:
Re: How to reload only if you have enough ammo
I already did that DoomPlayer Stuff, but something is wrong with the Alt-Fire, Which will reload no matter how much ammo i have.
- middlefingerman
- Posts: 52
- Joined: Mon May 04, 2020 12:55 pm
- Location: On the toilet
- Contact:
Re: How to reload only if you have enough ammo
What the hell?
Apparently it works now.
It's the same code as earlier...
I don't even know.
Apparently it works now.
It's the same code as earlier...
I don't even know.
- GoosebumpsFan
- Posts: 1
- Joined: Wed May 27, 2020 12:10 pm
Re: How to reload only if you have enough ammo
oh cool would you mind if i usd this code
- middlefingerman
- Posts: 52
- Joined: Mon May 04, 2020 12:55 pm
- Location: On the toilet
- Contact:
Re: How to reload only if you have enough ammo
Sure, go ahead
Re: How to reload only if you have enough ammo
The only issue with the shotgun that I spotted was that it loads 6 shells into the gun, takes away 12 shells from the player and loops once.
So it takes away 24 shells when reloading, and if the player only has 12 shells, it only loads 6 shells into the shotgun.
Aside that, the shotgun also doesn't reload if the player only has 11 shells, so what is exactly the problem here?
Unless the problem is what I just described, in which case it can be fixed by changing this:
So it takes away 24 shells when reloading, and if the player only has 12 shells, it only loads 6 shells into the shotgun.
Aside that, the shotgun also doesn't reload if the player only has 11 shells, so what is exactly the problem here?
Unless the problem is what I just described, in which case it can be fixed by changing this:
Spoiler:Edit: And since it was edited out of the OP, then I assume the issue has already been fixed?
- middlefingerman
- Posts: 52
- Joined: Mon May 04, 2020 12:55 pm
- Location: On the toilet
- Contact:
Re: How to reload only if you have enough ammo
Yeah.
Oh well
Oh well