[solved] Friendly monster teleporting to the player

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
Melodica
Posts: 75
Joined: Sun Feb 14, 2016 10:35 am
Preferred Pronouns: She/Her
Location: Chile

[solved] Friendly monster teleporting to the player

Post by Melodica »

Sooo, could anyone help me with making a monster that teleports to the player when the player goes out of sight? It's mostly to help said friendly monster stay with the player more frequently, instead of getting stuck in one area because block monster was put on a linedef, making the friendly useless once its stuck.

Code of the actor I need to do that:

Code: Select all

actor FriendlyMarine
{
	Health 120
	Speed 14
	Radius 16
	Height 56
	Species "Marine"
	PainChance 100
	Monster
	+FLOORCLIP
	-COUNTKILL
	+FRIENDLY
	+DONTHARMSPECIES
	+THRUSPECIES
	-ACTIVATEMCROSS
	+QUICKTORETALIATE
	+AVOIDMELEE
	//+DROPOFF
	+FLOORCLIP
	SeeSound "marine/HUUHUUUH"
	ActiveSound "marine/HUUHUUUH"
	DeathSound "*death"
	PainSound "*pain50"
	Translation 1
	
	var int user_shots;
	
	states
	{
	Spawn:
		PLAY AB 10 A_Look
	/*Idle:
		PLAY ABAB 10 A_Look
		PLAY ABCDABCD 4 A_Wander
		Loop*/
		Loop
	See:
		PLAY AABBCCDD 2 A_Chase
		Loop
	Missile:
		PLAY F 2 BRIGHT 
		{
			A_FaceTarget;
			A_AlertMonsters;
			A_PlaySound ("grunt/attack");
			A_CustomBulletAttack (2.5, 0, 1, random(1,5) * 3, "BulletPuff", 0, CBAF_NORANDOM);
			//A_Chase("","",CHF_NODIRECTIONTURN);
			user_shots++;
		}
		TNT1 A 0 A_Chase("","",CHF_NODIRECTIONTURN)
		PLAY E 2 A_CposRefire
		TNT1 A 0 A_Chase("","",CHF_NODIRECTIONTURN)
		PLAY E 0 A_JumpIf(user_shots > 14, "Reposition")
		Goto Missile
	Reposition:
		PLAY A 0 A_SetUserVar(user_shots, 0)
		PLAY AABBCCDD 2 
		{
			A_Chase("", "",CHF_NODIRECTIONTURN);
			A_FaceTarget;
		}
		TNT1 A 0 A_ClearTarget
		Goto Missile
	Pain:
		PLAY G 3 A_Pain
		Goto See
	Death:
		PLAY H 10
		PLAY I 10 A_Scream
		PLAY J 10 A_NoBlocking
		PLAY KLM 10
		PLAY N -1
		Stop
	XDeath:
		PLAY O 5
		PLAY P 5 A_XScream
		PLAY Q 5 A_NoBlocking
		PLAY RSTUV 5
		PLAY W -1
		Stop
	}
}
Last edited by Melodica on Mon Jan 15, 2018 9:32 am, edited 1 time in total.
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Friendly monster teleporting to the player when out of s

Post by krokots »

I actually have exactly the samething in my mod, but using ZScript (you can check the code for "Teleporting" in my Familiar Doom mod).
Without ZScript you could do this:
In "See" state:

Code: Select all

	See:
	TNT1 A 0 A_CheckSight("TeleportToPlayer")	
	PLAY AABBCCDD 2 A_Chase
	Loop
New state:

Code: Select all

	TeleportToPlayer:
	TNT1 A 0 A_SpawnItemEx("TeleportDestinationActor", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER)
You must also create special class for A_Teleport

Code: Select all

actor TeleportDestinationActor : SpecialSpot
{
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 
		{	
			A_Warp(AAPTR_PLAYER1, 0, 64);
			A_Teleport ("See", "TeleportDestinationActor", "", 0, 0, AAPTR_MASTER) 
		}
		stop
	}
}
But I have no idea if this works actually, I don't know Decorate :/. I don't even know how in Decorate get some actors (player) position, so I'd use A_Warp with player pointer. And using A_Teleport inside the spot which the actor is being teleported to...is weird. A_Warp should know radius of the player and radius of the actor being teleported, and use this value instead of "64" but i don't know how to retrieve other actors property in Decorate.
Melodica
Posts: 75
Joined: Sun Feb 14, 2016 10:35 am
Preferred Pronouns: She/Her
Location: Chile

Re: Friendly monster teleporting to the player when out of s

Post by Melodica »

Thanks for the help! I figured out how to do it based on what you posted, so thanks for that!

Here's how I ended up doing it:

Code: Select all

	See:
		PLAY E 0 A_CheckSight("TeleportCheck")
		PLAY AABBCCDD 2 
		{
			A_Chase;
			user_tele++;
		}
		Loop
	See2://to give the marine some time to spawn away from the player but the player still be able to know where it'll spawn
		PLAY A 0 A_SetUserVar(user_tele, 0)
		TNT1 A 0 A_FadeOut(0.5)
		PLAY ABCDABCDABCDABCD 4 A_Chase("","")
		TNT1 A 0 
		{
			A_ChangeFlag("NOBLOCKMAP", FALSE);
			A_FadeIn(0.5);
			A_SpawnItemEx("TeleportFog");
		}
		Goto See+1
	TeleportCheck:
		PLAY E 0 A_JumpIf(user_tele > 80, "TeleportToPlayer")
		Goto See+1
	TeleportToPlayer:
		TNT1 A 1 
		{
			A_ClearTarget;
			A_Warp(AAPTR_PLAYER1, 0, 0);
			A_ChangeFlag("NOBLOCKMAP", TRUE);
		}
		//TNT1 A 0 A_SpawnItemEx("TeleportFog")
		//TNT1 A 0 A_SpawnItemEx("TeleportDestinationActor", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER)
		Goto See2
Post Reply

Return to “Scripting”