Help with Event Handler accessing PlayerInfo/Player Pawn code

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!)
Post Reply
User avatar
JMaszk
Posts: 10
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Help with Event Handler accessing PlayerInfo/Player Pawn code

Post by JMaszk »

Is it possible to access and modify PlayerInfo structs or PlayerPawn code in the Event Handler?

For example the current player's SoundClass or Player.WeaponSlot?

Code: Select all

class PlayerSwitch : EventHandler
{
    override void NetworkProcess (ConsoleEvent e)
    {
		let plmo = players [e.Player].mo;
		let pawn = PlayerPawn(plmo);
		
        if (e.Name ~== "PlayerSwitch_NewPlayer")
        {
        		plmo.A_StartSound("pistol/fire", 0); 
			pawn.player.mo.SoundClass == "NewPlayer";
			pawn.player.WeaponSlot 1 == "NewPistol";
			pawn.player.WeaponSlot 2 == "NewShotgun";
			...
		}
	}
}
The pistol sound plays when executed, as intended.
pawn.player.mo.SoundClass allows the game to run, but does nothing.
pawn.player.WeaponSlot 1, etc. just doesn't work; I don't know if it's possible to switch the current character's assigned weapon slot?

If I need to post an example with all the code needed, I will.
User avatar
SanyaWaffles
Posts: 843
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: Help with Event Handler accessing PlayerInfo/Player Pawn code

Post by SanyaWaffles »

try using = and not == in this block like so for the SoundClass

Code: Select all

  if (e.Name ~== "PlayerSwitch_NewPlayer")
        {
        		plmo.A_StartSound("pistol/fire", 0); 
			pawn.player.mo.SoundClass = "NewPlayer";
			...
		}
	}
The weaponSlots probably will need more work.

What are you trying to do specifically?
User avatar
JMaszk
Posts: 10
Joined: Sun Oct 30, 2022 2:01 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Help with Event Handler accessing PlayerInfo/Player Pawn code

Post by JMaszk »

That worked for the SoundClass, thank you! I'm not sure how you would even reference WeaponSlots 1-9 in the Event Handler.

I am trying to make it possible to switch characters without actually changing player class; instead just modifying the current player's variables to make it seem like you actually changed characters. I have an idea on how I could do this if it's not possible to switch WeaponSlots on the fly like I am attempting. I could make special weapon classes that have multiple weapons in a single weapon class that switches depending on who you are 'switched' to.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Help with Event Handler accessing PlayerInfo/Player Pawn code

Post by Player701 »

JMaszk wrote: Sun Jul 16, 2023 5:15 am I'm not sure how you would even reference WeaponSlots 1-9 in the Event Handler.
Weapon slots are a read-only feature in ZScript. I guess write access is not provided because it'd conflict with local slot modifications (INI settings and the setslot console command), and allowing a mod to override your custom setup is probably not a good idea.
Post Reply

Return to “Scripting”