Remove Inventory On Weapon Drop?
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!)
-
- Posts: 280
- Joined: Sat Jan 27, 2018 9:12 pm
- Graphics Processor: nVidia (Modern GZDoom)
- Location: The Deepest Reaches of Space
- Contact:
Remove Inventory On Weapon Drop?
I'm wondering if it is possible to have items removed from your inventory when a weapon is dropped. As an example, I drop a weapon and in doing so the ammo I've got for that gun is removed from my inventory. Is there a way to code this in? I've looked around the ZDoom wiki and forums and haven't found much help.
Re: Remove Inventory On Weapon Drop?
If you fancy using ZScript it seems like you can override the virtual function: [wiki]OnDrop[/wiki]
here's a little zscript code using Doom's shotgun as an example:
here's a little zscript code using Doom's shotgun as an example:
Code: Select all
class customShotgun : shotgun
{
default
{
weapon.SlotNumber 3;
}
override void OnDrop(actor dropper)
{
if(dropper)
dropper.TakeInventory("shell",999);
}
}
Last edited by Mikk- on Mon Jan 11, 2021 2:36 pm, edited 1 time in total.
Re: Remove Inventory On Weapon Drop?
It's possible either with ACS or with ZScript.
With ACS you can set up a script like this:
Or you can add this override to your weapon if it's done in ZScript:
Though it's probably better to do weapon magazines this way if using ZScript.
With ACS you can set up a script like this:
Code: Select all
Script "WeaponAmmo" ENTER
{
While(true)
{
If(!CheckInventory("Weapon")){TakeInventory("Ammo",10);}
Delay(1);
}
}
Code: Select all
Override void DetachFromOwner()
{
owner.A_TakeInventory("Ammo",10);
Super.DetachFromOwner();
}
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Remove Inventory On Weapon Drop?
DetachFromOwner will also happen if the weapon is destroyed or taken away. I don't know about OnDrop but I assume from the name of the function that it will only kick in on an actual drop.
-
- Posts: 280
- Joined: Sat Jan 27, 2018 9:12 pm
- Graphics Processor: nVidia (Modern GZDoom)
- Location: The Deepest Reaches of Space
- Contact:
Re: Remove Inventory On Weapon Drop?
[quote="Jarewill"]It's possible either with ACS or with ZScript.
With ACS you can set up a script like this:
Your ACS script works perfectly for what I've in mind, thank ya!
With ACS you can set up a script like this:
Code: Select all
Script "WeaponAmmo" ENTER
{
While(true)
{
If(!CheckInventory("Weapon")){TakeInventory("Ammo",10);}
Delay(1);
}
}
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: Remove Inventory On Weapon Drop?
How does that not continuously take away ammo until you're completely out?
- Player701
-
- Posts: 1710
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Remove Inventory On Weapon Drop?
Indeed, the state needs to be saved somewhere, or the script will keep taking ammo continuously when the weapon is not present.
The fixed script can be found further below. However, unless you are limited to Zandronum compatibility, please do not use ACS to implement or modify game logic. It was once widespread only because there were no better tools, but now we have them. The solution should be implemented in ZScript, by overriding either OnDrop or DetachFromOwner, depending on your exact use case(s), as shown by Mikk- and Jarewill in the posts above.
The fixed script can be found further below. However, unless you are limited to Zandronum compatibility, please do not use ACS to implement or modify game logic. It was once widespread only because there were no better tools, but now we have them. The solution should be implemented in ZScript, by overriding either OnDrop or DetachFromOwner, depending on your exact use case(s), as shown by Mikk- and Jarewill in the posts above.
Code: Select all
#include "zcommon.acs"
bool weaponCheck[8];
script "WeaponAmmo" ENTER
{
bool hasWeapon = CheckInventory("Weapon");
int pnum = PlayerNumber();
if (!hasWeapon && weaponCheck[pnum])
{
TakeInventory("Ammo", 10);
}
weaponCheck[pnum] = hasWeapon;
delay(1);
restart;
}