[ZScript] Custom weapon system with dynamic ammo drop

Sprites, textures, sounds, code, and other resources belong here. Share and share-alike!
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
  • Is the resource ENTIRELY my own work?
  • If no to the previous one, do I have permission from the original author?
  • If no to the previous one, did I put a reasonable amount of work into the resource myself, such that the changes are noticeably different from the source that I could take credit for them?
If you answered no to all three, maybe you should consider taking your stuff somewhere other than the Resources forum.

Consult the Resource/Request Posting Guidelines for more information.

Please don't put requests here! They have their own forum --> here. Thank you!
Post Reply
User avatar
Koto
Posts: 156
Joined: Fri Aug 09, 2013 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Southamerican sacrifice zone (Chile)

[ZScript] Custom weapon system with dynamic ammo drop

Post by Koto »

Hello people,

I have managed to implement an ammo handling system in a weapon pickup using ZScript.

The idea is that the ammo obtained from the weapon depends on the ammo that the magazine has, once we have killed the enemy.

I leave you an image explaining the mechanics.



Fig.1 - If we are faster than the enemy, we can get the weapon and all its ammo.

Fig.2 - But if the enemy manages to shoot, and we can return fire from him. We'll get what's left in the weapon.

The pickup works like this.
  • A) If we don't have the weapon in our arsenal, the player will be able to pick it up without problems. And the ammo obtained will be available in the magazine, regardless of the amount present when picked up.
  • B) If we have the weapon, the player collects only the ammo present in the magazine of the weapon, which is added to the total of our inventory, and the empty weapon (without the magazine) is spawned.
  • C) If the weapon doesn't have ammo in the magazine, the same verification is made as in the previous points. That is, if we already have the weapon, we will not be able to pick it up for obvious reasons. Otherwise, you'll have a functional gun with no ammunition (and a lot of bad luck :lol: ).
  • D) In ​​case we want to drop the weapon, it will come out with the ammo that is left in the magazine. Functioning the same as if the enemy dropped it.
To implement this system, I've worked on a test WAD, using the UAC Battle Rifle available in Realm667, replaced the pickup sprite with the rifle present in Brutal Doom (as well as including a sprite edit with the weapon without a mag), rewrote the code to ZScript and, with a little help (the Wiki documentation, similar implementations on the forum and direct help on the ZDoom Discord server), and after a long time of trial and error, I managed to get it working with the expected results.

The weapon can be used by typing 'summon rifle' into the console or by killing a Zombieman.

Here is a video of the system in action.


Download link.
https://www.mediafire.com/file/dwhsgcfl ... c.pk3/file

You can use it freely in your projects, I only ask for credit in return.
Post Reply

Return to “Resources”