[ZSCRIPT] Dynamically change player soundclass

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

[ZSCRIPT] Dynamically change player soundclass

Postby TheGameratorT » Fri Nov 09, 2018 4:37 pm

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

Code:
Code: Select allExpand view
TNT1 A 0 { Player.SoundClass = "billplayer"; }

Error:
Code: Select allExpand view
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 allExpand view
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.

:|
User avatar
TheGameratorT
If you read this you now like potatoes and ducks.
 
Joined: 04 Mar 2018
Location: Portugal
Discord: TheGameratorT#1850
Twitch ID: thegameratort

Re: [ZSCRIPT] Dynamically change player soundclass

Postby Blue Shadow » Fri Nov 09, 2018 5:57 pm

Where are you calling that code from, from what actor class? SoundClass is a field of the PlayerPawn class and derivatives only.
User avatar
Blue Shadow
 
 
 
Joined: 14 Nov 2010

Re: [ZSCRIPT] Dynamically change player soundclass

Postby Player701 » Sat Nov 10, 2018 2:26 am

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 allExpand view
let pp = PlayerPawn(self);
if (pp)
{
    pp.SoundClass = "billplayer";
}
User avatar
Player701
You are now breathing manually.
 
Joined: 13 May 2009
Location: Russian Federation
Discord: Player701#8214

Re: [ZSCRIPT] Dynamically change player soundclass

Postby TheGameratorT » Sat Nov 10, 2018 6:53 am

Thanks for the help, I didn't knew it was as simple as removing the "Player." part. :)
User avatar
TheGameratorT
If you read this you now like potatoes and ducks.
 
Joined: 04 Mar 2018
Location: Portugal
Discord: TheGameratorT#1850
Twitch ID: thegameratort


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest