Halve state durations of some monsters

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

Halve state durations of some monsters

Post by Kzer-Za »

I want to have some monsters, but not all of them, have all their state durations halved. Is there a way of achieving it without creating replacements for these monsters with all their states and specifying new state durations? I have tried giving them an item when they are spawned that would halve their tics variable, but it seems to be read-only:

Code: Select all

class Hastener : Inventory
{
	Default
	{
		Inventory.Amount 1;
		Inventory.MaxAmount 1;
	}
	override void Tick()
	{
		let myowner = owner;
		State PrevState = myowner.curState;
		if (myowner.curState != PrevState);
		{
			myowner.curState.tics = (myowner.curState.tics + 1)/2;
			Console.Printf("dur: "..myowner.curState.tics);
		}
		super.Tick();
	}
}
I get "Expression must be a modifiable value". Is there another way of achieving it?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Halve state durations of some monsters

Post by Player701 »

Try myowner.tics. curState probably refers directly to state table data which is not supposed to be modified, since it's used by every instance of each actor class.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Halve state durations of some monsters

Post by Kzer-Za »

Thanks a lot! That's it!

In case anyone needs something similar, here's the code I eventually came up with. The changes to the initial version, apart from the key change advised by Player701, are: assignment of the current state to "PrevState" of course had to be moved to after the condition; and typecasting was unnecessary, it works without it. Also I added a condition to exclude Death and Pain states, so that their animation has the unchanged speed.

Code: Select all

class Hastener : Inventory
{
	Default
	{
		Inventory.Amount 1;
		Inventory.MaxAmount 1;
	}
	
	State PrevState;
	
	override void Tick()
	{
		if (owner.CurState != PrevState)
		{
			if (owner.InStateSequence(owner.CurState, owner.ResolveState("Death")) == false && owner.InStateSequence(owner.CurState, owner.ResolveState("Pain")) == false)
				owner.tics = (owner.tics + 1)/2;
		}
		PrevState = owner.CurState;
		super.Tick();
	}
}
Post Reply

Return to “Scripting”