A counter for a monster behavior

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
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

A counter for a monster behavior

Post by Kzer-Za »

Can I have a counter in a DECORATE file (probably, calling ACS file)? I want to make Heretic's undead knights throw axes not randomly, but in order: 3 green axes, 1 red. For that, I suppose, I need something like the following in a decorate file:

Code: Select all

Missile:
	KNIG E 7 A_FaceTarget
	KNIG F 6 A_FaceTarget
	TNT1 A 0 A_JumpIf(CallACS("KnightAxeCounter") < 3, "ThrowAxeGreen")
	TNT1 A 0 A_CustomMissile("HLKnightAxeRed",40)
	Goto Refire
ThrowAxeGreen:
	TNT1 A 0 A_CustomMissile("HLKnightAxeGreen",40)
Refire:
	KNIG G 5
	KNIG F 2 A_MonsterRefire(40,"See")
	KNIG F 0 A_Jump(64,"See")
	Goto Missile
And something like this in an ACS file:

Code: Select all

Script "KnightAxeCounter" (int AxeCounter)
{
if (AxeCounter < 3)
	{AxeCounter++;}
else
	{AxeCounter = 0;}
}
But how do I pass the counter to the script from the decorate file? And is the counter going to be separate for different knights or just one for all of them (which would defeat its pupose, of course)?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: A counter for a monster behavior

Post by Apeirogon »

You can use user variable in decorate for that.
https://zdoom.org/wiki/User_variable
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A counter for a monster behavior

Post by Kzer-Za »

Apeirogon wrote:You can use user variable in decorate for that.
Thanks!

I wrote in the decorate and acs files the content that I had wrote in my opening post. I declared the variable as

Code: Select all

var int user_axecounter;
and initiated it in the Spawn state as

Code: Select all

TNT1 A 0 NoDelay A_SetUserVar("user_axecounter", 3)
However, I'm getting this error when I try to launch GZDoom:

Code: Select all

Script error, ":decorate.knight" line 47:
Integer expected for parameter 0
The line 47 is where I call the ACS script:

Code: Select all

TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult("KnightAxeCounter", user_axecounter) < 3, "ThrowAxeGreen")
What am I doing wrong? I declared the variable as integer and initiated it, why is it giving me this

Code: Select all

Integer expected for parameter 0
?
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: A counter for a monster behavior

Post by Kzer-Za »

Scratch that, I'm an idiot, I used ACS_ExecuteWithResult when I should have ACS_NamedExecuteWithResult!
Post Reply

Return to “Scripting”