how use 'action' to playsound on civilian?

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!)
landstalker02
Posts: 3
Joined: Mon Feb 14, 2022 3:45 am

how use 'action' to playsound on civilian?

Post by landstalker02 »

Hello, i'm French so sorry for my English xD... So, i have this decorate and it's civilian. The characters walk around the map (A_Wander), or follow the player (A_Chase). When you hit him, he run 3 or 4 seconds and walk normaly again. there's sounds, too.

So, i would like launch random sound, when i near the civilian and when i use "action" key (spacebar for me), to hear "hello", or "what do you want", etc, etc... I tried to add "A_Playsound( "hom/act") but it doesn't work, or "Use:", but nothing.
Anyone can help me to know the correct synthaxe to do that, please?

Thanks for your advices x)

Alain

Code: Select all

// -------------------------------------------------------
actor CivilianMale1 32326
{
	//$Category DDD
	//$Title "Civil 1"

	Health 40 
    Radius 20 
    Height 40 
    Speed 8
    Damage 100
    PainChance 200
    MONSTER 
    seesound "hom/see"
    painsound "hom/pain"
    deathsound "hom/deat"
    activesound "hom/act"
    meleesound "hom/act"
	scale 0.7
	
    States
	{
	Spawn:
		CVM2 A 0 NoDelay A_SetSpecial(130,0)
		CVM2 A 0 A_SpawnItemEx("CivMarker",0,0,0,0,0,0,0,SXF_SetMaster)
		GoTo Think
	Think:
		CVM2 A 10 A_Look
		Loop
	See:
		// A_Chase 	le perso nous suit
		// A_Wander il se balade
		CVM2 AABBAACC 2 A_Wander
		CVM2 A 0 A_Chase
		Loop
	Melee:
		CVM2 EE 5 A_FaceTarget
		CVM2 E 30
		Goto See
	Pain:
		CVM2 E 3
		CVM2 E 3 A_Pain
		Goto RunAway
	RunAway:
		TNT1 A 0 A_ChangeFlag("Frightened", True)
		TNT1 A 0 A_SetSpeed(15,AAPTR_DEFAULT)
		CVM2 AAAABBBBCCCCBBBB 1 A_Chase
		CVM2 AAAABBBBCCCCBBBB 1 A_Chase
		CVM2 AAAABBBBCCCCBBBB 1 A_Chase
		CVM2 AAAABBBBCCCCBBBB 1 A_Chase
		CVM2 AAAABBBBCCCCBBBB 1 A_Chase
		TNT1 A 0 A_SetSpeed(3,AAPTR_DEFAULT)
		TNT1 A 0 A_ChangeFlag("Frightened", False)
	Goto See
	Death:
		CVM2 I 5
		CVM2 J 5 
		CVM2 K 5 
		CVM2 L 5
		CVM2 M -1
		Stop

	Idle:
		CVM2 AA 4 A_Wander
		CVM2 A 0 A_Look
		CVM2 BB 4 A_Wander
		CVM2 A 0 A_Look
		CVM2 AA 4 A_Wander
		CVM2 A 0 A_Look
		CVM2 CC 4 A_Wander
		CVM2 A 0 A_Look
		Loop
	Active:
		CVM2 A 1
		Goto Fade
	Fade:
		CVM2 A 1 A_FadeOut(0.1,FTF_REMOVE|FTF_CLAMP)
		Loop
	}
User avatar
Sir Robin
Posts: 392
Joined: Wed Dec 22, 2021 7:02 pm
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: how use 'action' to playsound on civilian?

Post by Sir Robin »

The [wiki]Used[/wiki] function is called when you "use" an actor, so you can put your sound call in there.

Also, [wiki]A_PlaySound[/wiki] is deprecated for [wiki]A_StartSound[/wiki]

Put this in your actor code:

Code: Select all

	override bool Used (Actor user)
	{
		a_StartSound("hom/act");
		return true;
	}
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: how use 'action' to playsound on civilian?

Post by Enjay »

That looks like zscript code? The code posted by OP is DECORATE.

I think the best way to do this in DECORATE, assuming the actors are going to be used in a specific map, is to include an ACS script that plays the sound at the tid of the NPC, give the NPC a special to run the script and give them the +USESPECIAL flag in their DECORATE.

Another option would be to go all out and use the Strife dialogue system to give them more extensive responses and even conversations.
landstalker02
Posts: 3
Joined: Mon Feb 14, 2022 3:45 am

Re: how use 'action' to playsound on civilian?

Post by landstalker02 »

Thanks for your answers, i will try this when i will be back at home :D

Return to “Scripting”