ZScript setOrigin

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
kfpopeye2
Posts: 32
Joined: Mon Jul 17, 2017 6:30 pm

ZScript setOrigin

Post by kfpopeye2 »

I'm trying to create a Marine sentry guard that will attach any monsters it sees but then walk back to its original location when the monster is dead. I seem to have everything working except the walking back to post. It seems SetOrigin doesn't interpolate properly and the marine just warps back to its original location. Am I missing something?

Below is my zscript:

Code: Select all

class MarineChatty : ScriptedMarine
{	
	Default
	{
		Health 100;
		Radius 16;
		Height 56;
		Mass 100;
		Speed 8;
		Painchance MARINE_PAIN_CHANCE;
		MONSTER;
		-COUNTKILL;
		Translation 2;
		Damage 100;
		DeathSound "*death";
		PainSound "*pain50";
	}
	
	States
	{
	Spawn:
		PLAY A 4 A_MarineLook;
		PLAY A 4 A_MarineNoise;
		PLAY A 4 setPost;
		Goto Idle;
	Idle:
		PLAY A 4 A_MarineLook;
		PLAY A 4 A_MarineNoise;
		PLAY A 4 A_MarineLook;
		PLAY B 4 A_MarineNoise;
		PLAY B 4 A_MarineLook;
		PLAY B 4 A_MarineNoise;
		Loop;
	See:
		PLAY ABC 4 A_MarineChase;
		PLAY D 4 A_JumpIf(LookForEnemies(true) == 0, "ReturnToPost");
		Loop;
	ReturnToPost:
		PLAY A 4 A_ClearTarget;
		PLAY BCD 4 A_MarineLook;
	Travelling:
		PLAY A 1 A_JumpIf(travelToPost() == 0, "Idle");
		PLAY BCD 4 A_MarineLook;
		Loop;
	Missile:
		PLAY E 3 A_M_CheckAttack;
		PLAY F 7 BRIGHT A_M_FireShotgun;
		Goto See;
	Death:
		PLAY H 1
		PLAY I 10 A_Scream;
		PLAY J 10 A_NoBlocking;
		PLAY KLM 10;
		PLAY N -1;
		Stop;
	}
	
	Vector3 postPosition;
	
	void setPost()
	{
		postPosition.x = self.Pos.x;
		postPosition.Y = self.Pos.Y;
		postPosition.Z = self.Pos.Z;
	}
	
	bool travelToPost()
	{		
		if(postPosition.x == self.Pos.x && postPosition.Y == self.Pos.Y)
		{
			return FALSE;
		}
		Vector2 v;
		v.X = postPosition.X;
		v.Y = postPosition.Y;
		if(CheckMove(v))
		{
			SetOrigin(postPosition, TRUE);
			return TRUE;
		}
		return FALSE;
	}
}
Post Reply

Return to “Scripting”