Yeah, I have never been able to fix this
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:
Thanks in advance.
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.