how to play a sound from zscript, and from an event handler?

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.

how to play a sound from zscript, and from an event handler?

Postby dosboot » Thu Jun 03, 2021 9:11 am

I'm trying to understand how to play sounds from zscript. The only reference examples and wiki pages I can find use ACS, so I've been trying to use CallACS and ACS_NamedExecuteWithResult.

The problem is that when I test the code below out in gzdoom 4.5.0 and type "netevent aaa" into the console, I get an error roughly like: P_Startscript Unknown Script "playsound".

It also isn't clear to me how you would send string parameters using CallACS or how you would get the right "tid" argument for PlaySound (e.g., if I want to have the player's actor being the "thing" that emits the sound).

Also, all these problems also makes me think CallACS isn't the best way to do this if I want to play a sound from zscript.

zscripts.txt:
Code: Select allExpand view
version "4.5.0"

class custom_bindings_class : StaticEventHandler
{
    override void NetworkProcess(ConsoleEvent e)
    {
        if (e.Name == "aaa")
        {
            //integer expected for parameter 2?
            //ACS_NamedExecuteWithResult("PlaySound",0,"weapons/plasmaf");
           
            ACS_NamedExecuteWithResult("PlaySound",0,0);
        }
    }
}
dosboot
 
Joined: 03 Jun 2021

Re: how to play a sound from zscript, and from an event hand

Postby _mental_ » Thu Jun 03, 2021 9:20 am

No need to use ACS, ZScript offers S_StartSound() function.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: how to play a sound from zscript, and from an event hand

Postby dosboot » Fri Jun 04, 2021 5:45 am

Thanks, "S_StartSound("weapons/plasmaf", CHAN_VOICE, CHANF_UI|CHANF_NOPAUSE, 1.0);" does the trick. I've figured out that https://zdoom.org/wiki/Sound_channels can be used as a reference for the 2nd and 3rd parameters, with minor modification (adding "F") for the flags in the 3rd parameter.
dosboot
 
Joined: 03 Jun 2021


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests