Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → TB hostage cog
TB hostage cog
2003-01-18, 12:31 PM #1
Yeah, I have never been able to fix this [http://forums.massassi.net/html/frown.gif]

What happens is you activate the hostage and he follows you (thats good). You activate him again and he stops following you (thats also good). But when you activate him again he just looks at you, and doesnt follow. I am real bad at ai, so I was wondering if someone could give me a hand? Below here is the cog:

Code:
# Actor_hostage.cog
#
# [SM + Dormouse]
#=========================================================#
flags=0x240
symbols
message startup
message pulse
message activated
message killed
message trigger
message touched
message join

template actor_hostage

thing gpos
thing activator local
thing toucher local
thing hostage local
thing posghost local
thing killer local

sector sectorRescue

vector center local
vector lvec local
vector syncpos local
vector curpos local
vector curlvec local
vector synclvec local

flex zdiff local
flex dist local

int isReleased local
int isRescued local
int isMobile local
int count local
int dead local
end
#=========================================================#
code
#------------------------------------------------------------------------------
startup:
// All players run this code.
hostage=CreateThing(actor_hostage, gpos);
CaptureThing(hostage);
AISetMoveSpeed(hostage , 3);
isReleased=0;
isRescued=0;
isMobile=0;
dead=0;
SetPulse(0.1);
SetActorFlags(hostage , 0x40000);
Return;
#------------------------------------------------------------------------------
pulse:
// All players run this line.
if(GetThingSector(hostage) == sectorRescue && !IsRescued && !dead) call rescue;
// Only the host runs this code
if(IsServer()) // Sync the position of the hostage every half a second.
{
count=count+1;
if(count > 5)
{
count=0;
curpos=GetThingPos(hostage);
curlvec=GetThingLVec(hostage);
SendTrigger(-1, 800, VectorX(curpos), VectorY(curpos), VectorZ(curpos), 0);
SendTrigger(-1, 801, VectorX(curlvec), VectorY(curlvec), VectorZ(curlvec), GetThingSector(hostage));
SendTrigger(-1, 803, GetThingHealth(hostage), 0, 0, 0);
}
}
// All players run this code.
if(IsMobile && !IsRescued)
{
dist=VectorDist(GetThingPos(activator), GetThingPos(hostage));
if(dist > 0.2)
{
AISetLookPos(hostage, GetThingPos(activator)); // Move to and look at the activator.
AISetMovePos(hostage, GetThingPos(activator));
}
else
{
AIClearMode(hostage, 0x1);
StopThing(hostage);
}
}
if(dead) SetPulse(0);
Return;
#------------------------------------------------------------------------------
activated:
// Only let this message run on the activating player's machine.
if(jkGetLocalPlayer() != GetSourceRef() || dead) Return;
if(isRescued)
{
SendTrigger(-1, 804, 0, 0, 0, 0);
Return;
}
activator=GetSourceRef();
if(!isMobile) // Player activates the immobilized actor.
{
isMobile=1;
if(isReleased) SendTrigger(-1, 807, 0, 0, 0, 0); // Assume the actor has been paused.
else // Assume the actor was just released.
{
isReleased=1;
ClearActorFlags(hostage , 0x40000);
SendTrigger(-1, 805, activator, 0, 0, 0);
}
}
else // Player activates the moveable actor...
{
isMobile=0;
SendTrigger(-1, 806, activator, 0, 0, 0);
SetActorFlags(hostage , 0x40000);
}
SendTrigger(-1, 802, isMobile, isReleased, activator, 0);
Return;
#------------------------------------------------------------------------------
killed:
// Runs on all computers.
SetPulse(0);
killer=GetThingParent(GetSourceRef());
jkStringClear();
jkStringConcatAsciiString("-=HOSTAGE KILLED BY: ");
jkStringConcatPlayerName(killer);
jkStringConcatAsciiString("!=-");
jkStringOutput();
SendTrigger(-1, 803, GetThingHealth(hostage), killer, 0, 0);
dead=1;
Return;
#------------------------------------------------------------------------------
rescue:
// Runs on all computers
isRescued=1;
zdiff=VectorZ(GetSectorCenter(sectorRescue)) - VectorZ(GetThingPos(hostage));
center=VectorAdd(GetSectorCenter(sectorRescue), VectorSet(-0.2, 0, -zdiff));
AISetMovePos(hostage, center);
AiSetLookPos(hostage, center);
ChangeInv(jkGetLocalPlayer(), 152 , 500);
Print("-=HOSTAGE RESCUED!=-");
Return;
#------------------------------------------------------------------------------
trigger:
// All players but the one who sent the trigger run this code.
if(GetSenderRef() == jkGetLocalPlayer() && GetSourceRef() < 804 || dead) Return;
if(GetSourceRef() == 800) syncpos=VectorSet(GetParam(0), GetParam(1), GetParam(2));
else if(GetSourceRef() == 801)
{
synclvec=VectorSet(GetParam(0), GetParam(1), GetParam(2));
posghost=CreateThingAtPos(LoadTemplate("ghost"), GetParam(3), syncpos, '0 0 0');
SetThingLook(posghost, synclvec);
TeleportThing(hostage, posghost);
DestroyThing(posghost);
}
else if(GetSourceRef() == 802)
{
isMobile=GetParam(0);
isReleased=GetParam(1);
activator=GetParam(2);
}
else if(GetSourceRef() == 803)
{
SetThingHealth(hostage, GetParam(0));
if(GetThingHealth(hostage) < 1 && !dead)
{
PlayKey(hostage, LoadKeyframe("mndie.key"), 5, 0x14);
dead=1;
jkStringClear();
jkStringConcatAsciiString("-=HOSTAGE KILLED BY: ");
jkStringConcatPlayerName(GetParam(1));
jkStringConcatAsciiString("!=-");
jkStringOutput();
}
}
else if(GetSourceRef() == 804)
{
jkStringClear();
jkStringConcatAsciiString("Marty says: 'Thanks a lot, ");
jkStringConcatPlayerName(activator);
jkStringConcatAsciiString("!'");
jkStringOutput();
}
else if(GetSourceRef() == 805)
{
jkStringClear();
jkStringConcatAsciiString("Marty says: 'Ok, ");
jkStringConcatPlayerName(GetParam(0));
jkStringConcatAsciiString(". I'm right behind you!'");
jkStringOutput();
}
else if(GetSourceRef() == 806)
{
jkStringClear();
if(GetParam(0) == jkGetLocalPlayer()) jkStringConcatAsciiString("You say");
else
{
jkStringConcatPlayerName(GetParam(0));
jkStringConcatAsciiString(" says");
}
jkStringConcatAsciiString(": 'Stay there.'"); 
jkStringOutput();
}
else if(GetSourceRef() == 807)
{
jkStringClear();
jkStringConcatAsciiString("Marty says: 'I'm ready to go.'");
jkStringOutput();
}
Return;
#------------------------------------------------------------------------------
touched:
// Runs on all computers. Player pos will not be the same on all comps and the host will most likely foul this up a bit.
toucher=GetSourceRef();
if(GetThingType(toucher) != 10 || !isReleased || IsRescued || dead) Return;
lvec=VectorSub(GetThingPos(toucher), GetThingPos(hostage));
ApplyForce(hostage, VectorScale(VectorNorm(lvec), -2));
Return;
#------------------------------------------------------------------------------
join:
// Only the host runs this code when a player joins. This code syncs the hostage.
if(!IsServer() || dead) Return;
curpos=GetThingPos(hostage);
curlvec=GetThingLVec(hostage);
SendTrigger(-1, 800, VectorX(curpos), VectorY(curpos), VectorZ(curpos), 0);
SendTrigger(-1, 801, VectorX(curlvec), VectorY(curlvec), VectorZ(curlvec), GetThingSector(hostage));
SendTrigger(-1, 802, isMobile, isReleased, activator, 0);
SendTrigger(-1, 803, GetThingHealth(hostage), 0, 0, 0);
Return;
#------------------------------------------------------------------------------
end


Thanks in advance.
Team Battle.
2003-01-18, 6:04 PM #2
I'm assuming it's your IsMobile variable. I guess it's somehow not being set correctly after the 2nd activation.

Stick some print statements in that activated message around what could cause the problem.
-Hell Raiser
2003-01-18, 7:01 PM #3
IsMobile is always correct.
Team Battle.
2003-01-18, 7:01 PM #4
I'm the AI guy, but I really don't like MP.

The problem, maybe GBK will see something I don't but this is what I have to say. The vars IsMobile and IsReleased are only changed on the activator's comp in the Startup and Activated messages. So those aren't teh problem. I dunno.

But I can help make the cog simpler. The syncing of the hostage, why don't you use SetThingPos() instead of createing the ghost and teleporting it. Secondly, add some () around the && arguments in the first IF/then under the trigger message. That might (though I really don't think so) be the problem. Sorry I couldn't have been more help. [http://forums.massassi.net/html/frown.gif] Good luck.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-01-18, 7:06 PM #5
SetThingPos needs a sector doesnt it?

I didnt write the cog, SM and dormouse did.

The actor does everything as though he has about to follow you (ie is mobile, and he looks at you), except he seems to be stuck there, he doesnt walk.
Team Battle.
2003-01-18, 7:22 PM #6
Heres a more tidy version of the cog

http://24.45.190.154:81/jkteambattle/images/media/actor_hostage.cog
Team Battle.
2003-01-20, 4:59 AM #7
Well you did use CreateThingAtPos(), that uses a sector. [http://forums.massassi.net/html/tongue.gif] I seriously don't know on this one. [http://forums.massassi.net/html/frown.gif]

Maybe this might help some. Its one of my friendly actor cogs, and isn't converted to MP, but its the general just right? [http://forums.massassi.net/html/wink.gif] (Only Hellcat can use this if he needs to)
Code:
# Jedi Knight COG Script
#
# FRIEND_FOLLOW.COG
#
# A cog for a friendly actor.
# Kinda like Max, just better.
# Follow player version.
#
# [DP]
#

symbols

thing		friend				mask=0x408
thing		player		nolink	local
thing		target				local
int		count=0				local

message	startup
message	killed
message	pulse

end

# ========================================================================================

code

Startup:
	player = GetLocalPlayerThing();
	SetPulse(1);
	AIClearMode(friend, 0x1206);
	Return;

# ........................................................................................

Killed:
	If(GetSenderRef() != friend) Return;
	SetPulse(0);
	AIClearMode(friend, 0x1206);
	AISetMode(friend, 0x1);
	Return;

# ........................................................................................

Pulse:
      count = 0;
	If(AIGetMode(friend) == 0x202) Return;		// So it keeps on the same target
	target = FirstThingInView(friend, 170, 12, 0x4);
	If((target == friend)||(target == player)) target = -1;
	While((target == -1)&&(count < GetThingCount()))
	{
		target = NextThingInView();
		If(count == GetThingCount()) target = -1;
		If((target == friend)||(target == player)) target = -1;
		count = count + 1;		// Incase there isn't anything in view
	}
	If(target != -1)		// If there's a target
	{
		CaptureThing(target);
		AISetFireTarget(friend, target);
		AISetMoveThing(friend, target);
		AISetLookPos(friend, GetThingPos(target));
		AISetMode(friend, 0x202);
		AIClearMode(friend, 0x1000);
	}
	Else		// If not, go to player
	If((VectorDist(GetThingPos(player), GetThingPos(friend))) > .5)
	{
		call followplayer;
		Return;
	}
	Else AIClearMode(friend, 0x1206);
	Return;

# ........................................................................................

FollowPlayer:
	AISetMoveThing(friend, player);
	AISetLookPos(friend, GetThingPos(player));
	AISetMode(friend, 0x1);
	AIClearMode(friend, 0x1206);
	Return;

end


------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

[This message has been edited by Descent_pilot (edited January 20, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-01-20, 12:57 PM #8
AAAAAAAAAH!!!!!

IT'S MARTY'S BRAINS!

I'm going to vomit now. Poor Marty...
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2003-01-21, 8:41 PM #9
I dunno, there is no logic in the way that evil hostage is responding.

/me kicks hostage.

Bad Marty!!
Team Battle.
2003-01-21, 9:15 PM #10
Thanks guys its fixed now. I am not sure what was causing it but I slapped a ClearActorFlags(hostage , 0x40000); under the pulse between these lines:

Code:
if(dist > 0.2){AISetLookPos(hostage, GetThingPos(activator)); // Move to and look at the activator.AISetMovePos(hostage, GetThingPos(activator));}


I figured since he looks at me still it had to be that doing it.

Well I know that solution sucked, but it works. So its cool.
Team Battle.
2003-01-22, 3:08 PM #11
Such a sucky ending to a great story. [http://forums.massassi.net/html/tongue.gif] I have a theory, though I really don't want to check through all the code and see if this works, but maybe it had to do with the value of IsReleased. That was set to 1 and the ClearActorFlags() was never being called. Then again this is just a theory...

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!