ZScript - Intercept/Override ACS give inventory?

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

ZScript - Intercept/Override ACS give inventory?

Postby kevansevans » Wed Nov 17, 2021 1:34 pm

I need the ability to intercept an ACS function that gives the player an item. My mod uses custom weapons that replace the default. If the map calls, as an example, giveInventory("Pistol", 1);, the player will receive the vanilla pistol and not my custom pistol that replaces it in ZScript.
User avatar
kevansevans
Disciple of The Great God Imp
Spotlight Team
 
Joined: 05 Oct 2010
Github ID: kevansevans
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: ZScript - Intercept/Override ACS give inventory?

Postby Apeirogon » Mon Nov 22, 2021 4:24 am

Its impossible?? ACS works on other "plane of existence", relatively to Zscript.
Also, even CheckReplacement event are not triggered in this case?

As a workaround, you can iterate over player inventory and check is he possess any item that should be replaced.
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: ZScript - Intercept/Override ACS give inventory?

Postby Player701 » Tue Nov 23, 2021 6:10 am

Apeirogon wrote:ACS works on other "plane of existence", relatively to Zscript.

Note that, in fact, the PCD_GIVEINVENTORY ACS opcode calls ScriptUtil::GiveInventory, which in turn calls Actor::GiveInventory; both of these are defined in ZScript. The actual problem is that Giveinventory calls Actor::Spawn without specifying ALLOW_REPLACE, so CheckReplacement et al. does not run. There is no way to override this except with hacks (like the one Apeirogon suggested).
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests