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 → Advanced Cog Problem
Advanced Cog Problem
2001-01-17, 2:40 PM #1
OK. I've spent a lot of time editing Nightmare's MP Ai SYNC cog, and I've run into a hitch (guess I edited it a little TOO much...) Anyways, when the host starts a game the Ai is fine and dandy, but when a client joins the Ai needs to respawn before the client can see him. Here's my code (NOTE: I haven't included the client side of the cog, but since all that does is play a sound and displays a text message I know it's not the problem.)

# Jedi Knight Cog Script
# ai_dflt_srv.cog
#
# RE-WRITE AT END OF BETA PHASE!
#
# This cog was made by sqmagellan. All Rights Reserved.

symbols

message timer
message damaged
message pulse
message activated
message crossed
message startup

thing aipos nolink
thing ai=-1 mask=-1 local

int no_respawn=0
int no_loop=0

surface ai_on_1
surface ai_on_2
surface ai_on_3
surface ai_on_4
surface ai_off_1
surface ai_off_2
surface ai_off_3
surface ai_off_4

thing seeker
int seekframes=2
flex seekspeed=120.0 local

int team=5
int controlflags=0x10

flex sightdist_n=5.0
flex movespeed_n=0.35

flex minfirerate_n=.75
flex maxfirerate_n=4.5
flex maxrange_n=4.5
flex lead_n=0.4

int hitpoints_n=250
int respawn_time_n=10
int killpnts=1
int vision=225
int ok_to_sync=0

flex standoffdist=.75
flex arriveddist=1.5

int death_uni=1000
int self_kill_uni=1000
int taunt_a=1000
int taunt_1_b=1000
int taunt_2_b=1000
int taunt_3_b=1000
int taunt_4_b=1000
int taunt_5_b=1000

template item_drop=+Dstrifle
template aitpl

keyframe FireKey=stfire.key
keyframe HurtKey=sthit.key

sound firesnd=pistol-1.wav
sound HurtSnd=i00s127z.wav
sound BlindSnd=i00ic15z.wav

template weapon=+ais_laser
template die_tpl=+ais_sparks
template respawn_tpl=+telesparks
template sound_tpl=+sound_icon

flex sightdist local
flex movespeed local
flex minfirerate local
flex maxfirerate local
flex maxrange local
flex lead local
int hitpoints local
int respawn_time local

thing target local
thing movetarget local
thing victim local
thing killer local
thing player local
thing shot local

sector sec0 local

flex damage_type local
flex damage_amount local
flex targetswitch local
flex Dot local
flex MaxDot local

int statflags local
int aimodeflags local
int playerflags local

int LOScountdown=0 local
int hp local
int weapon local
int curframe local
int hitcount=0 local
int hastalked local
int aisnd local
int temp_death local
int can_respawn=1 local
int make_us=1 local

sound beep=set_hi2.wav local

vector firepos local
vector firevec local
vector movevec local
vector movepos local
vector interceptvec local
vector dodgevec local
vector gunoffset local
vector randVec local

end

# (/\/\/\/\(()=======================================================-

code

startup:
sightdist = sightdist_n;
movespeed = movespeed_n;
minfirerate = minfirerate_n;
maxfirerate = maxfirerate_n;
maxrange = maxrange_n;
lead = lead_n;
hitpoints = hitpoints_n;
respawn_time = respawn_time_n;

call make_me;

Return;

make_me:
if(!IsMulti() | | IsServer()) ai = CreateThing(aitpl, aipos);
CaptureThing(ai);
SetThingUserData(ai, team);
movetarget = aipos;
statflags = 0x3;
aiflags = 0x2;
hp = hitpoints;
SetPulse(.5);
target = -1;
hitcount = 0;
gunoffset = GetThingFireOffSet(ai);
SetThingVel(ai, '0 -.01 0');
CreateThingAtPos(respawn_tpl, GetThingSector(ai), GetThingPos(ai), '0 0 0');

if (BitTest(controlflags, 0x1))
{
curframe = 0;
movetarget = seeker;
aiflags = BitSet(aiflags, 0x80);
TeleportThing(seeker, aipos);
SkipToFrame(seeker, 0, seekspeed);
}
SyncThingPos(ai);

Return;

pulse:
if (BitTest(aiflags, 0x1)) return;
if ((IsServer()) && (ok_to_sync)) SyncThingPos(ai);

if(BitTest(aiflags, 0x2))
{
victim = -1;
maxDot = sightdist + 1;
victim = FirstThingInView(ai, 225, 5.5, 0x404);
while (victim != -1)
{
if ((HasLOS(ai, victim)) && ((GetThingType(victim) == 10 && GetPlayerTeam(victim) != team) | | (GetThingType(victim) == 2 && GetThingUserData(victim) != team)) && (VectorDist(GetThingPos(ai), GetThingPos(victim)) <= sightdist) && (victim != ai))
{
dot = VectorDist(GetThingPos(ai), GetThingPos(victim));
if (dot < maxDot)
{
target = victim;
maxDot = dot;
}
}
victim = NextThingInView();
}
if(target != -1)
{
playerflags = GetActorFlags(target);
if (!BitTest(playerflags, 0x80))
{
if (BitTest(controlflags, 0x1)) StopThing(seeker);
movetarget = target;
aiflags = BitClear(aiflags, 0x2);
aiflags = BitSet(aiflags, 0x8);
aiflags = BitSet(aiflags, 0x20);
if (BitTest(aiflags, 0x80)) aiflags = BitClear(aiflags, 0x80);
statflags = BitSet(statflags, 0x4);
SetTimerEx(minfirerate + (rand() * (maxfirerate - minfirerate)), 4, 0.0, 0.0);
}
}
}
if (BitTest(aiflags, 0x20) && !BitTest(controlflags, 0x2))
{
interceptvec = VectorNorm(VectorSub(VectorAdd(GetThingPos(movetarget), VectorScale(GetThingVel(movetarget), lead)), GetThingPos(ai)));
movevec = VectorSet(VectorX(interceptvec), VectorY(interceptvec), 0.0);
SetThingLook(ai, movevec);
if (VectorDist(GetThingPos(ai), GetThingPos(movetarget)) < standoffdist) SetThingVel(ai, VectorScale(VectorNorm(GetThingLVec(ai)), -movespeed));
if (VectorDist(GetThingPos(ai), GetThingPos(movetarget)) > (arriveddist)) SetThingVel(ai, VectorScale(VectorNorm(GetThingLVec(ai)), movespeed));
}
if (BitTest(aiflags, 0x80))
{
if (GetThingType(movetarget) != 10 && BitTest(controlflags, 0x1))
{
if (!IsthingMoving(seeker) && VectorDist(GetThingPos(ai), GetThingPos(movetarget)) < .25)
{
curframe = curframe + 1;
if (curframe > seekframes)
{
if (no_loop) aiflags = BitClear(aiflags, 0x80);
else curframe = 0;
}
SkipToFrame(seeker, curframe, seekspeed);
}
}
if (GetThingType(movetarget) == 10 && !HasLOS(ai, movetarget))
{
movetarget = -1;
aiflags = BitClear(aiflags, 0x80);
}
if ((HasLOS(ai, movetarget)) | | movetarget == seeker )
{
interceptvec = VectorNorm(VectorSub(VectorAdd(GetThingPos(movetarget), VectorScale(GetThingVel(movetarget), lead)), GetThingPos(ai)));
movevec = VectorSet(VectorX(interceptvec), VectorY(interceptvec), 0.0);
SetThingLook(ai, movevec);
if (VectorDist(GetThingPos(ai), GetThingPos(movetarget)) > .25) SetThingVel(ai, VectorScale(VectorNorm(GetThingLVec(ai)), movespeed));
}
}
if (BitTest(aiflags, 0x8))
{
if (HasLOS(ai, target)) LOScountdown = 0;
if (!HasLOS(ai, target) | | VectorDist(GetThingPos(ai), GetThingPos(target)) < sightdist) LOScountdown = LOScountdown + 1;
if (LOScountdown >= 8 | | (GetThingFlags(target) & 0x200))
{
target = -1;
movetarget = -1;
aiflags = BitSet(aiflags, 0x2);
aiflags = BitClear(aiflags, 0x8);
aiflags = BitClear(aiflags, 0x20);
statflags = BitClear(statflags, 0x4);
if (BitTest(controlflags, 0x1))
{
movetarget = seeker;
aiflags = BitSet(aiflags, 0x80);
SkipToFrame(seeker, curframe, seekspeed);
}
}
}
sec0 = GetThingSector(ai);
if ((ai == -1) | | (GetThingTemplate(ai) != aitpl) | | (GetSectorFlags(sec0) & 0x40))
{
target = -1;
if (ai > -1)
{
temp_death = 1;
call time_to_go;
jkPrintUNIString(-3, self_kill_uni);
}
}

Return;

damaged:
if (GetSenderRef() != ai) Return;
if (!BitTest(statflags, 0x1)) return;
killer = GetThingParent(GetSourceRef());
if ((killer == -1) | | ((GetThingType(killer) == 10 && GetPlayerTeam(killer) == team) | | (GetThingType(killer) == 2 && GetThingUserData(killer) == team))) return;

if ((GetThingType(killer) == 10) && (!ok_to_sync)) ok_to_sync = 1;
damage_type = GetParam(1);
damage_amount = GetParam(0);
if (BitTest(damage_type, 0x15)) damage_amout = damage_amount * 2000;
hp = hp - damage_amount;

if (hp > 0)
{
targetswitch = damage_amount + (rand() * 80);
if ((targetswitch > 100) | | (!BitTest(statflags, 0x4)) && ((GetThingType(killer) == 10 && GetPlayerTeam(killer) != team) | | (GetThingType(killer) == 2 && GetThingUserData(killer) != team)))
{
if (BitTest(controlflags, 0x1)) StopThing(seeker);
target = killer;
movetarget = killer;
LOScountdown = 8;

if (BitTest(aiflags, 0x2)) aiflags = BitClear(aiflags, 0x2);
if (!BitTest(aiflags, 0x8)) aiflags = BitSet(aiflags, 0x8);
if (!BitTest(aiflags, 0x20)) aiflags = BitSet(aiflags, 0x20);
if (BitTest(aiflags, 0x80)) aiflags = BitClear(aiflags, 0x80);
if (!BitTest(statflags, 0x4)) statflags = BitSet(statflags, 0x4);

KillTimerEx(4);
SetTimerEx(0.1, 4, 0, 0);
}
if ((Rand() >= 0.6) && (!hastalked))
{
jkStringClear();
jkStringConcatUniString(taunt_a);
jkStringConcatPlayerName(killer);
randtalk = rand();
if (randtalk <= 0.2) jkStringConcatUniString(taunt_1_b);
else if (randtalk <= 0.4) jkStringConcatUniString(taunt_2_b);
else if (randtalk <= 0.6) jkStringConcatUniString(taunt_3_b);
else if (randtalk <= 0.8) jkStringConcatUniString(taunt_4_b);
else jkStringConcatUniString(taunt_5_b);
jkStringOutput(-3, -1);
PlaySoundGlobal(beep, 1, 0, 0);
hastalked = 1;
SetTimerEx(7, 3, 0, 0);
}
hitcount = hitcount + 1;
PlayKey(ai, HurtKey, 2, 32);
PlaySoundThing(HurtSnd, ai, 1, -1, -1, 0);
Return;
}
if (hp <= 0) call time_to_go;

Return;

time_to_go:
if (BitTest(controlflags, 0x1)) StopThing(seeker);
can_respawn = 0;
target = -1;
SetPulse(0);
KillTimerEx(4);
StopThing(ai);
movetarget = aipos;
statflags = 0x0;
aiflags = 0x1;

if (!temp_death)
{
if (GetThingType(killer) == 10)
{
SetPlayerScore(killer, GetPlayerScore(killer) + killpnts);
SetPlayerKills(killer, GetPlayerKills(killer) + killpnts);
SyncScores();
}
aisnd = CreateThing(sound_tpl, ai);
CreateThing(item_drop, ai);
SendTrigger(-1, 6, aisnd, 0, killer, death_uni);
CreateThingAtPos(die_tpl, GetThingSector(ai), GetThingPos(ai), '0 0 0');
if (!no_respawn) SetTimerEx(respawn_time, 2, 0, 0);
}
else temp_death = 0;

DestroyThing(ai);
ReleaseThing(ai);
ai = -1;

Return;

timer:
// Taunt re-cycle.
if (GetSenderID() == 3)
{
hastalked = 0;
Return;
}
// AI Weapon Use.
else if (GetSenderID() == 4)
{
if (BitTest(aiflags, 0x8))
{
if ((VectorDist(GetThingPos(ai), GetThingPos(target)) < maxrange) && (HasLOS(ai, target)))
{
StopThing(ai);
if(GetActorFlags(ai) & 0x800)
{
if (Rand() <= 0.25) PlaySoundThing(BlindSnd, ai, 1, -1, -1, 0);
randVec = VectorSet((Rand()-0.5)*15, (Rand()-0.5)*35, 0.0);
}
else randVec = VectorSet(0, 0, 0);
firepos = VectorAdd(GetThingPos(target), VectorScale(GetThingVel(target), lead));
firevec = VectorNorm(VectorSub(firepos, GetThingPos(ai)));
SetThingLook(ai, firevec);
// SetThingLook(ai, VectorSub(GetThingPos(target), GetThingPos(ai)));
shot = FireProjectile(ai, weapon, firesnd, 8, gunoffset, randVec, 1.0, 0x20, 25, .75);
PlayKey(ai, FireKey, 2, 32);
}
if (GetActorFlags(ai) & 0x800) SetTimerEx(minfirerate + (rand() * (maxfirerate - minfirerate)) * 2, 4, 0, 0);
else SetTimerEx(minfirerate + (rand() * (maxfirerate - minfirerate)), 4, 0, 0);
}
Return;
}
// Respawn AI Timer
else if(GetSenderID() == 2)
{
call make_me;
Return;
}

activated:
if (GetSenderRef() == ai)
{
player = GetSourceRef();
if ((GetPlayerTeam(player) == team) && (BitTest(aiflags, 0x2)))
{
if (!BitTest(aiflags, 0x80))
{
movetarget = player;
aiflags = BitSet(aiflags, 0x80);
Return;
}
if (BitTest(aiflags, 0x80))
{
movetarget = -1;
aiflags = BitClear(aiflags, 0x80);
Return;
}
}
}

crossed:
if (((GetSenderRef() == ai_on_1) | | (GetSenderRef() == ai_on_2) | | (GetSenderRef() == ai_on_3) | | (GetSenderRef() == ai_on_4)) && (!ok_to_sync))
{
ok_to_sync = 1;
}
else if (((GetSenderRef() == ai_off_1) | | (GetSenderRef() == ai_off_2) | | (GetSenderRef() == ai_off_3) | | (GetSenderRef() == ai_on_4)) && (ok_to_sync))
{
ok_to_sync = 0;

}

Return;

end

Thanks.

- sqmagellan
2001-01-18, 11:10 AM #2
It gets created at startup, maybe you should make it get recreated at 'newplayer:' (Just replace the old one with a new one)

Maybe this'd work:

Add these symbols:

thing aiold local
message newplayer

And add this code:

newplayer:
aiold=ai;
ai = CreateThing(aitpl,aiold);
DestroyThing(aiold);
Return;

That should work, but I haven't tested it.

Thanks
JK [Meteor]
"Maybe you like rainbows"
I can't remember what to say!!!!
Click here for my homepage.

↑ Up to the top!