Hello everyone. I'm working on a personal addon for a gameplay mod, and I'm trying to figure out the most efficient way to determine when the player picks up specific types of Custom Inventory (from the original mod) out of a very large list of potential types. I'd rather not touch the original mod, so that I don't have to redo my code for every update, so I was trying to come up with a way to detect pickups dynamically. I was thinking using the "WorldThingSpawned" event to detect any instances of said Custom Inventory, then somehow attach a "pickup" event to it from there. IS this possible, or is there a better way short of a giant loop? I should also note, that due to how the original mod works, simply inheriting and extending the original items isn't an option.
In short, without touching or inheriting from the original mod, what is the most efficient way to detect when a player picks up a type of Custom Inventory?
Thanks.
[ZScript] Dynamically attaching code to Custom Inventory
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!)
- stainedofmind
- Posts: 233
- Joined: Sun Sep 01, 2019 10:59 am
- Caligari87
- Admin
- Posts: 6241
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
- Contact:
Re: [ZScript] Dynamically attaching code to Custom Inventory
The way I'd approach something like this is giving the player an invisible inventory item that watches their inventory and does something appropriately. The following example contains a latching value so the condition only triggers on a change; you could of course do anything else, such as destroying the checker or something. Multiple conditionals and latching variables for different items and could be included in the same checker as well.

Code: Select all
class LookForChainguns : Inventory {
int OldValue;
// DoEffect runs every tic
// if this has an owner
override void DoEffect() {
if (owner.countinv("Chaingun") != OldValue) {
console.printf("Debug: Picked up or dropped a chaingun!");
}
OldValue = owner.countinv("Chaingun");
}
}- stainedofmind
- Posts: 233
- Joined: Sun Sep 01, 2019 10:59 am
Re: [ZScript] Dynamically attaching code to Custom Inventory
Thanks for the input @Caligari87. What I ended up doing was using WorldThingSpawned, filtering out the unneeded actors via simple string indexing, then having it register into a queue for later processing through WorldTick. Not as efficient as I would have liked, but it gets the job done, avoids a gigantic ~2000 item loop, and doesn't seem to cause any excess lag on my potato-lappy.
Re: [ZScript] Dynamically attaching code to Custom Inventory
Could you share the code, please? It seems I have a similar goal: viewtopic.php?f=122&t=74320stainedofmind wrote:What I ended up doing was using WorldThingSpawned, filtering out the unneeded actors via simple string indexing, then having it register into a queue for later processing through WorldTick.
- stainedofmind
- Posts: 233
- Joined: Sun Sep 01, 2019 10:59 am
Re: [ZScript] Dynamically attaching code to Custom Inventory
Sorry about the late reply. Not sure if this is going to help your cause, but here is a demo version of the code I used:
https://drive.google.com/file/d/1nW29Zc ... sp=sharing
https://drive.google.com/file/d/1nW29Zc ... sp=sharing