[ZSCRIPT] Dynamically change player soundclass

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
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal
Contact:

[ZSCRIPT] Dynamically change player soundclass

Post by TheGameratorT »

I don't know if this is possible yet but every time I do this it throws out an error:

Code:

Code: Select all

TNT1 A 0 { Player.SoundClass = "billplayer"; }
Error:

Code: Select all

Script error, "FNAF_Core.pk3:zscript.txt" line 48:
Unknown identifier 'SoundClass'
I also tried with PlayerPawn.SoundClass instead of Player.SoundClass but it says that it isn't possible to change the context:

Code: Select all

Script error, "FNAF_Core.pk3:zscript.txt" line 48:
Unable to access 'PlayerPawn.SoundClass' in a static context
Anyone knows why this throws out errors? I have searched for about an hour and I still can't find a solution.

:|
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: [ZSCRIPT] Dynamically change player soundclass

Post by Blue Shadow »

Where are you calling that code from, from what actor class? SoundClass is a field of the PlayerPawn class and derivatives only.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZSCRIPT] Dynamically change player soundclass

Post by Player701 »

Your code doesn't work because "Player" is a reference to the Actor.Player field, which is of type PlayerInfo, not PlayerPawn.

If you're calling this code from a PlayerPawn (i.e. your player class), then remove the "Player." part.

If you're calling it from a CustomInventory or a Weapon, then you need to cast "self" to PlayerPawn like this:

Code: Select all

let pp = PlayerPawn(self);
if (pp)
{
    pp.SoundClass = "billplayer";
}
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal
Contact:

Re: [ZSCRIPT] Dynamically change player soundclass

Post by TheGameratorT »

Thanks for the help, I didn't knew it was as simple as removing the "Player." part. :)
Post Reply

Return to “Scripting”