[SOLVED][ZScript] Help with a custom weapon pickup system

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
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)

[SOLVED][ZScript] Help with a custom weapon pickup system

Post by Koto »

Hello people,

I have been trying to implement an ammo handling system in the weapon pickup using ZScript.

The idea is to make the ammunition obtained by the weapon depend on what the magazine has available, 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 ammunition.

Fig.2-But if the enemy manages to shoot, but we can return fire from him. we'll get whatever's left in the gun.

The pickup should work as follows.
  • A) If we don't have the weapon, the player will be able to pick it up without problems. And the ammunition obtained will only be available in the magazine, regardless of the amount present in the pickup.

    B) If we have the weapon, the player collects only the ammunition present in the magazine of the dropped weapon, which is added to the total amount that can be used, and a pickup is spawned with the empty weapon.

    C) If the weapon does not have ammunition in the magazine, the same check as in the previous points is made. That is, if you already have the weapon, the weapon is spawned without a magazine, and a message is added notifying you of the fact. Otherwise, you will have a functional weapon with no ammunition available (and a lot of bad luck :lol: ).

    D) In ​​case we want to drop the weapon, the idea is that we can drop it empty. And the ammunition present in the magazine is added to the total ammunition.
In order to implement this system, I have worked on a test WAD, using the UAC Battle Rifle downloadable from Realm667, I replaced the pickup sprite with the rifle present in Brutal Doom (in addition to including a sprite edit with the weapon without a magazine) , I rewrote the code to ZScript, and with a little help (The Wiki documentation, checking out similar help on the forum, and from the ZDoom Discord channel), I've been able to get closer to what I want to implement.

The weapon can be used by typing summon rifle in the console, by killing a Zombieman, or by picking it up on the map (replaces shotgun).

The problems I have with the current process are the following:
  • - The enemy after reloading, the dropped weapon cannot be picked up, and also drops the empty weapon.

    - Having the weapon, if I got it from an enemy, I can't interact with another weapon that has been spawned on the map, and vice versa.
I attach the test WAD, so you can review what has been tried to do, and so you can give me a hand with this mechanic that could be interesting to more than one person.

Thanks in advance.

EDIT: The attached WAD was deleted because the problem was fixed.
User avatar
Koto
Posts: 156
Joined: Fri Aug 09, 2013 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Southamerican sacrifice zone (Chile)

Re: [SOLVED][ZScript] Help with a custom weapon pickup syste

Post by Koto »

I managed to fix the problem, and the implementation can be found here.

viewtopic.php?f=37&t=74828
Post Reply

Return to “Scripting”