Tick changing function

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!)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Tick changing function

Post by Apeirogon »

Is there are any way to change duration of one tick/tick rate/other time related function for single actor?

I work on blood system, which implies that the more blood actor lose the slower it act.
Yes, it can be done with a_SetTics, but it require copy paste it in every single state frame, which is to tediously.
So, is zscript can do this?
User avatar
krokots
Posts: 269
Joined: Tue Jan 19, 2010 5:07 pm

Re: Tick changing function

Post by krokots »

In my mod I use a simple method that slows monsters.
So, first thing, add a integer to the monster you want to be slowed that store the amount of tics that you want to slow down monster by, and a integer that store last tic.

Code: Select all

int TicSlowdown;
int LastTic;
Now, if you want the monster to be slowed, just increase this value

Code: Select all

TicSlowdown++;
And the most important part. Inside Tick() function (you should already know how virtual functions work), you put something like this:

Code: Select all

if(LastTic < Tics)
{
Tics += TicSlowdown;
}
LastTic = Tics;
How does this work? It just adds additional tics whenever your monster starts a new frame. And you know this, by checking if the current tics are a bigger number than last stored tics. So, if a monster goes from tics = 0 to tics = 3, the "if" statement will return true, because LastTics is 0.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Tick changing function

Post by Apeirogon »

This can be used ONLY in tick() virtual function? Because blood system based on inventory item with changed do effect, for compatibility with any mods.

And can i change duration of tick itself? Change default 28 milliseconds in tick to 18/44/1.9999.../>9000 milliseconds in tick? You example works, but after several slowing actor starts noticeably twitch when he moving.
User avatar
krokots
Posts: 269
Joined: Tue Jan 19, 2010 5:07 pm

Re: Tick changing function

Post by krokots »

You can create a "dummy" actor, that controls tics of other actors. This actor will just have some function, like "SetTargetTics()". OK i write an simple example.

Code: Select all

Class MonsterSlowdown : Actor
{
	int LastTick;

	Default
	{
		+NOINTERACTION
	}
	States
	{
		Spawn:
			TNT1 A 0;
		Spawn2:
			TNT1 A 1 SetTargetTics;
			Loop;
	}

	void SetTargetTics()
	{
		if(!target)
			Destroy();
		if(target.Health <= 0)
			Destroy();
		if(target.Tics < LastTick)
			target.Tics += target.Accuracy;
		LastTick = target.Tics;
	}
}
I use the Accuracy property to store how much monster is slowed down. When you want the monster to be slowed down, you need to increase his Accuracy by 1 (or whatever), and spawn this actor (via Spawn) and assign monster to this actor's target.

Code: Select all

target.Accuracy++;
Actor slow = MonsterSlowdown(Spawn("MonsterSlowdown", pos));
if(slow)
	slow.target = target;
This is not perfect because you can create many of these "slowdown" actors and they will accumulate. So everytime you create one, you need to check if another one of these exists and check its target. You can do this with ThinkerIterator. Or you can create an array of these actors as a player variable, and store them there.

I don't know if you can change tick duration, but I think this is hard coded in Doom so it's impossible.

Return to “Scripting”