How do you use Tick() and PostBeginPlay()?
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!)
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!)
-
- Posts: 379
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
How do you use Tick() and PostBeginPlay()?
Hello everyone, i was working on this monster and i wish he had the following behavior: He has a roll move, and i want him to do this once, when he sees the player for the first time. Meaning if he is alerted by a sound, he will just chase around, until he spots the player, checks sight (probably with the usage of a A_JumpIfTargetInLOS), then rolls. I wish he tried this every tick, until he spotted the player. But i dont have much idea how to this with a virtual function in ZScript. any help? It seems something simple enough to do, but i don't really understand how to do action functions jumps in ZSCript functions other then basic "return" stuff.
-
- Posts: 72
- Joined: Mon Aug 26, 2019 9:18 pm
- Graphics Processor: nVidia with Vulkan support
Re: How do you use Tick() and PostBeginPlay()?
This page has info on how to use virtual functions in ZScript, along with most of the virtuals exposed to it.
For Tick() you'd override it like this, and then add your own code on top.
But if you just want your actor to roll once when he is alerted by a sound, I'd suggest adding something like this in its' chase state instead:
For Tick() you'd override it like this, and then add your own code on top.
Code: Select all
Override Void Tick()
{
Super.Tick();
If (IsFrozen()) Return; //Not strictly needed, but useful to stop code that SHOULDN'T run every tick when the actor is frozen.
//Your code here
}
Code: Select all
//In the class definition.
Bool Rolled;
//The state block
See:
SPRT AABBCCDD 4
{
A_Chase();
If (!Rolled && Target && IsVisible(Target)/* && CheckFOV(Target,90/2)*/) //Can uncomment CheckFOV to also do exactly what it says.
Return FindState("DoABarrelRoll");
Return State (Null);
}
Loop;
DoABarrelRoll:
//Code goes here.
TNT1 A 0 {Rolled = True;} //One time roll done.
Goto See;
-
- Posts: 379
- Joined: Tue Dec 20, 2016 4:53 pm
- Location: MURICAA BROTHER! Just kidding, Brazil.
Re: How do you use Tick() and PostBeginPlay()?
Thank you! I think you made a mistake of not including all necessary parameters for IsVisible though, as it was error'ing me out, but i fixed it. i also added this little check of the player needing to be aiming at the enemy for him to dodge. But this works great.
Code: Select all
ZSP2 AAABBBCCCDDD 2
{
A_ZSpecChaseHealNoATK();
If (!OnSightDodge && Target && IsVisible(Target, false) && CheckFOV(Target,90/2) && CheckIfInTargetLOS(85))
Return FindState("TryRollAfterPain");
Return State(null);
}
Loop;