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.
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 8:18 am
by Caligari87
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.
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 8:36 am
by kodi
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.
Edit: Sorry, I didn't read your whole post so this may not help much. Decided against removing the post though.
Class MyWeaponName : Actor
{
int ammo_mag_cap;
int ammo_mag_cur;
int ammo_useamount;
Class<ammo> ammo_type;
override void BeginPlay()
{
ammo_useamount = 1;
ammo_mag_cap = 20;
ammo_mag_cur = 20;
ammo_type = "clip";
}
states
{
Fire:
"----" A 0
{
statelabel nextstate = "noammo";
if(invoker.ammo_mag_cur>=invoker.ammo_useamount)
{
nextstate="fire2";
invoker.ammo_mag_cur -= invoker.ammo_useamount;
}
return ResolveState(nextstate);
}
reload:
"----" A 0
{
statelabel nextstate = "noreload";
if(invoker.ammo_mag_cur < invoker.ammo_mag_cap)
{
if(countinv(invoker.ammo_type_cur)> 0)
{
nextstate = "reload_func";
}
}
return ResolveState(nextstate);
}
reload_func:
"----" A 0
{
int reloadamount = min(invoker.ammo_mag_cap - invoker.ammo_mag_cur, countinv(invoker.ammo_type_cur));
A_TakeInventory(invoker.ammo_type_cur,reloadamount);
invoker.ammo_mag_cur += reloadamount;
}
goto ready;
}
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 12:10 pm
by Caligari87
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?
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 1:44 pm
by Graf Zahl
You cannot have several identical items in the inventory. There is only one, which counts the indivdual items with its Amount variable.
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 2:47 pm
by Caligari87
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.
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 4:27 pm
by Ed the Bat
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.
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 4:43 pm
by AFADoomer
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.
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?
Re: "How do I ZScript?"
Posted: Wed Mar 29, 2017 7:01 pm
by Nash
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.
use:
TNT1 A 0
{
player.ReadyWeapon.SetStateLabel("fire",false);
}
stop;
Is there a way to do this properly in a usable inventory item? Doing it like the above plays the sounds in the fire state (at the players spawn point, not on the player actor itself) and deducts ammo, but doesn't affect the sprite.
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.)
Re: "How do I ZScript?"
Posted: Thu Mar 30, 2017 11:26 am
by kodi
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.
Re: "How do I ZScript?"
Posted: Thu Mar 30, 2017 10:11 pm
by ZZYZX
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.
Re: "How do I ZScript?"
Posted: Thu Mar 30, 2017 10:55 pm
by Nash
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).
Re: "How do I ZScript?"
Posted: Thu Mar 30, 2017 11:03 pm
by ZZYZX
I have no idea, I copied the code from PlayerClasses handling. Ask Graf.