[ACS] GetWeapon() returns "none" [SOLVED]

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.

[ACS] GetWeapon() returns "none" [SOLVED]

Postby difficultoldstuff » Tue Oct 12, 2021 4:05 pm

Hello guys!

I've encountered a weird issue with the
Code: Select allExpand view
GetWeapon()
ACS method (https://zdoom.org/wiki/GetWeapon). In my case it always returns "None". I'm making a complex weapon modding system, replaced every weapon with a special version based on a parent superclass (ZScript), so there's no vanilla weapons around. Funny thing is that it worked... for a time, then stopped.

If I do
Code: Select allExpand view
log(s:"WEAPON: ", s:GetWeapon());
I only get
Code: Select allExpand view
WEAPON: None
every single time. Is there anything I should be aware of that would produce this result? The ZScript superclass is based on DoomWeapon and behaves correctly. I might add that this result is checked when I use the
Code: Select allExpand view
WorldThingDamaged
Event Handler.

Thank you for your time and any kind of help!
Last edited by difficultoldstuff on Thu Oct 14, 2021 2:32 am, edited 1 time in total.
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [ACS] GetWeapon() returns "none"

Postby 22alpha22 » Tue Oct 12, 2021 4:25 pm

Is the player pawn the actor that is calling the script? GetWeapon wont work if that is not the case. If the script needs to be called from something other than the player pawn, you can set the player to be the activator of the script with SetActivator provided that the player has a unique TID.

EDIT:
Rereading your post it seems that you are calling an ACS script from the WorldThingDamaged event handler which I'm going to assume means you aren't using the player to call the script. Since it seems you want to check the player's weapon when they damage something using WorldThingDamaged, you can do this entirely in ZScript, no ACS needed.

Code: Select allExpand view
Override Void WorldThingDamaged(WorldEvent e)
{
    Let Plr = YourPlayerClass(e.Inflictor);  //Cast Plr to be the player class and set the pointer to the inflictor

    If (Plr)  //Check if the Plr pointer is non null, if the inflictor wasn't a player class cast above, then this will be null
    {
        If (Plr.Player.ReadyWeapon Is 'Shotgun')  //check if the player's current weapon matches and if it does do stuff
        {
             //Do Stuff
        }
    }
}


If for some reason you really want to check the player's weapon from ACS while still calling it from ZScript, then it can be done like this.
Code: Select allExpand view
[code]Override Void WorldThingDamaged(WorldEvent e)
{
     Let Plr = YourPlayerClass(e.Inflictor);

    If (Plr)
    {
        Plr.CallACS(string script, int s_arg1, int s_arg2, int s_arg3, int s_arg4) ;
    }
User avatar
22alpha22
So lonely...
 
Joined: 21 Feb 2014
Location: Montana, USA
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: [ACS] GetWeapon() returns "none"

Postby difficultoldstuff » Tue Oct 12, 2021 5:37 pm

22alpha22 - this looks mighty helpful! Especially the second part in which you show me a very sneaky way of using CallACS. Yes, I need to go back to ACS for... about 19000 reasons (most being lines of code), figuring this out in pure ZScript wouldn't be such a problem, as I already did in the ZScript part of this whole mod. I'll test this out tomorrow, but if it works it might just solve a lot more potential problems I could have along the road.
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [ACS] GetWeapon() returns "none"

Postby difficultoldstuff » Wed Oct 13, 2021 3:28 am

Well, ok, it works with some tweaks. Some issues I found were:
    + the inflictor is always 0 / null, so it doesn't really want to be cast to the player class
    + can't use plr.CallACS directly like that (https://forum.zdoom.org/viewtopic.php?f=7&t=59250)
    + can't use a variable in CallACS for the function name, as it returns a P_StartScript: Unknown script 0 error

Made some tweaks, experimented for a bit and I've ended up with a working solution based on your help:

Code: Select allExpand view
class CustomHandler : EventHandler
{
   override void WorldThingDamaged(WorldEvent e)
   {
        let plr = CustomPlayer(e.DamageSource);
       
        if (plr)
        {
            plr.CustomACSCall(e.thing.tid, e.DamageSource.tid, e.inflictor.tid);
        }
    }
}

class CustomPlayer : DoomPlayer
{
    void CustomACSCall(int tid, int damageSource, int inflictorTid)
    {
        CallACS("OnDamageScript", tid, damageSource, inflictorTid);
    }
}


Again, thank you for the help, let's get to coding! :)
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [ACS] GetWeapon() returns "none"

Postby Blue Shadow » Wed Oct 13, 2021 5:17 am

difficultoldstuff wrote:the inflictor is always 0 / null, so it doesn't really want to be cast to the player class

The player is usually the source of damage rather than the inflictor. An inflictor is usually a puff or projectile.

can't use plr.CallACS directly like that (https://forum.zdoom.org/viewtopic.php?f=7&t=59250)

Use ACS_ScriptCall instead, which functions the same as CallACS.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [ACS] GetWeapon() returns "none"

Postby 22alpha22 » Wed Oct 13, 2021 5:30 am

Blue Shadow beat me to it, but yeah use ACS_ScriptCall. I completely forgot you can't use CallACS like that because it is treated as an expression. As for the inflictor/source mixup, I'm just gonna blame it on me being tired.
User avatar
22alpha22
So lonely...
 
Joined: 21 Feb 2014
Location: Montana, USA
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: [ACS] GetWeapon() returns "none" [SOLVED]

Postby difficultoldstuff » Fri Oct 15, 2021 5:41 pm

Revised code for the future googlers:

Code: Select allExpand view
class CustomHandler : EventHandler
{
   override void WorldThingDamaged(WorldEvent e)
   {
        let plr = CustomPlayer(e.DamageSource);
       
        if (plr)
        {
            plr.ACS_ScriptCall("CustomACSFunction", e.thing.tid, e.damage, e.DamageSource.tid, e.inflictor.tid);
        }
    }
}


Thanks guys, doom on!
difficultoldstuff
 
Joined: 17 Jul 2020
Twitch ID: difficultoldstuff
Operating System: Windows Vista/7/2008 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 1 guest