"How do I ZScript?"
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!)
-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
No. The main problem being that ACS has no concept of actors. If you need interaction you should do the bulk of the work in ZScript and then use ScriptCall for interfacing.
-
Caligari87
- Admin
- Posts: 6242
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: "How do I ZScript?"
Just getting started with ZScript by way of a weapons mod, and I'm curious: What's the best way to deal with the concept of "nested" inventory items? Namely, bullets inside a magazine inside a gun.
Ideally, I want a pool of "loose" ammunition in the player's inventory that can be manually added to any arbitrary magazine (much like reloading a gun), and then obviously any of those magazines can be reloaded to the gun itself, or even dropped and picked up later with the appropriate amount still loaded inside them. Is this something I can accomplish with "real" ammo/inventory items, or will it need to be abstracted into an arrary or something?
Either way, I would really appreciate some pseudo-code at least so I can figure out the best way to approach this.

Ideally, I want a pool of "loose" ammunition in the player's inventory that can be manually added to any arbitrary magazine (much like reloading a gun), and then obviously any of those magazines can be reloaded to the gun itself, or even dropped and picked up later with the appropriate amount still loaded inside them. Is this something I can accomplish with "real" ammo/inventory items, or will it need to be abstracted into an arrary or something?
Either way, I would really appreciate some pseudo-code at least so I can figure out the best way to approach this.
-
kodi
-

- Posts: 1361
- Joined: Mon May 06, 2013 8:02 am
Re: "How do I ZScript?"
Edit: Sorry, I didn't read your whole post so this may not help much. Decided against removing the post though.Caligari87 wrote:Just getting started with ZScript by way of a weapons mod, and I'm curious: What's the best way to deal with the concept of "nested" inventory items? Namely, bullets inside a magazine inside a gun.
Ideally, I want a pool of "loose" ammunition in the player's inventory that can be manually added to any arbitrary magazine (much like reloading a gun), and then obviously any of those magazines can be reloaded to the gun itself, or even dropped and picked up later with the appropriate amount still loaded inside them. Is this something I can accomplish with "real" ammo/inventory items, or will it need to be abstracted into an arrary or something?
Either way, I would really appreciate some pseudo-code at least so I can figure out the best way to approach this.
Haphazardly cut out examples:
Spoiler:
-
Caligari87
- Admin
- Posts: 6242
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: "How do I ZScript?"
After thinking about it, let me re-word my request a little more generically:

- If an inventory object has a variable, is variable unique to that instance or is it shared across all instances? So if I define "int Num_Bullets;" in TQ_Magazine, will it be specific to that particular magazine, even if I have several magazines in my inventory?
- Assuming so, how can inventory objects interact with one another, if at all? Can I have TQ_Pistol point to a specific instance of TQ_Magazine and read or modify its variables?
- Finally, can an inventory object be subject to player keypresses and interaction, or do I need to create a dummy "weapon" for loading bullets into magazines?
-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
You cannot have several identical items in the inventory. There is only one, which counts the indivdual items with its Amount variable.
-
Caligari87
- Admin
- Posts: 6242
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: "How do I ZScript?"
Feature request then: Can we have "inventory containers" that allow other inventory to be put into them and are tracked as separate instances? Nash asked something similar and I don't believe it was ever addressed.

-
Ed the Bat
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: "How do I ZScript?"
This may be a bit of a deviation, but I just yesterday implemented a system in my project where an inventory is given to a player and told to store variables, which can then be read from inside the player's pockets. I don't know if it can be given inventory items of its own, but it can certainly be used to hold information without having to rewrite the playerclass itself.
-
AFADoomer
- Posts: 1344
- Joined: Tue Jul 15, 2003 4:18 pm
Re: "How do I ZScript?"
Would an array of item actors work? Or possibly a dynamic array of a particular class or struct that define key attributes about the inventory items?Caligari87 wrote:Feature request then: Can we have "inventory containers" that allow other inventory to be put into them and are tracked as separate instances? Nash asked something similar and I don't believe it was ever addressed.
-
Nash
-

- Posts: 17505
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
Re: extended inventory
I ended up writing my own abstraction. Items live as static thinkers (called LADItem), and pickup actors (called LADItemPickup) contain a pointer to the thinker. The items are moved around from pickup-space/world-space to actor-inventory space accordingly. My player pawn and monsters have a custom field defined, Array<LADItem>, which holds references to the thinkers. So actually, items aren't even given as Inventory items/through the Inventory give commands (although I could probably make another abstraction if I wanted to, so the user can use console commands)... the arrays are added and manipulated directly.
(LADItems are currently given to the player via the player pressing +use in front of a LADItemPickup)
It's not 100% finished yet, and it's not pretty but it does what I want... I only plan to use it for pickup-able weapons, where I need each individual weapon to keep track of its ammo count and gun durability condition. I don't plan to move actual ammunition to this system; I will still use the built-in Ammo class for that.
I ended up writing my own abstraction. Items live as static thinkers (called LADItem), and pickup actors (called LADItemPickup) contain a pointer to the thinker. The items are moved around from pickup-space/world-space to actor-inventory space accordingly. My player pawn and monsters have a custom field defined, Array<LADItem>, which holds references to the thinkers. So actually, items aren't even given as Inventory items/through the Inventory give commands (although I could probably make another abstraction if I wanted to, so the user can use console commands)... the arrays are added and manipulated directly.
(LADItems are currently given to the player via the player pressing +use in front of a LADItemPickup)
It's not 100% finished yet, and it's not pretty but it does what I want... I only plan to use it for pickup-able weapons, where I need each individual weapon to keep track of its ammo count and gun durability condition. I don't plan to move actual ammunition to this system; I will still use the built-in Ammo class for that.
-
kodi
-

- Posts: 1361
- Joined: Mon May 06, 2013 8:02 am
Re: "How do I ZScript?"
Code: Select all
use:
TNT1 A 0
{
player.ReadyWeapon.SetStateLabel("fire",false);
}
stop;-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
The correct function would be:
player.SetPsprite(PSP_WEAPON, ReadyWeapon.FindState("Fire"));
What you try to change is the actual item sprite state but since it's in an inventory that will never be displayed (and if it was, not like you want.)
player.SetPsprite(PSP_WEAPON, ReadyWeapon.FindState("Fire"));
What you try to change is the actual item sprite state but since it's in an inventory that will never be displayed (and if it was, not like you want.)
-
kodi
-

- Posts: 1361
- Joined: Mon May 06, 2013 8:02 am
Re: "How do I ZScript?"
Thank you. I figured out a safer and more controllable way to achieve what I want to, but SetPsprite will probably come in handy soon.
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
So today I made a wiki article on event handlers. https://zdoom.org/wiki/Events_and_handlers
The basic skeleton is there, but I'm not sure how to improve it, I think the text is currently hard to read. Anyone who knows how to improve is welcome to comment/improve.
The basic skeleton is there, but I'm not sure how to improve it, I think the text is currently hard to read. Anyone who knows how to improve is welcome to comment/improve.
-
Nash
-

- Posts: 17505
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
ZZYZX can you look at the code for EventHandlers and AddEventHandlers in the GAMEINFO MAPINFO section? With regards to multiple mods being loaded, it seems to randomly work or not work (sometimes previous event handlers from previous WADs will fail to fire).
-
ZZYZX
-

- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
I have no idea, I copied the code from PlayerClasses handling. Ask Graf.