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 → problems with cog controlled AI.
problems with cog controlled AI.
2001-02-24, 1:46 PM #1
I'm currently learning the ropes of cog so I decided to make a simple AI character. He's supposed to follow me around and when I get damaged, run after the ph00l who shot me. The problem is that he pays no attention to me getting hurt. here's the code:

Code:
symbols

model		newmodel=kyg7.3do		local
model           weaponMesh=cong.3do             local

sound		activsound=i09ky01z.wav 	local

template	base=walkplayer 		local
template        shot=+concbullet		local

flex 		timactive=1			local
flex		isdamaged=1			local

message 	activated
message 	pulse
message		damaged

end

code

activated:
if (timactive == 2) {
DestroyThing(littletim);
SetPulse(0);
timactive = 1;
return;
}
if (timactive == 1) {
player = GetSourceRef();
littletim = FireProjectile(player, base, activsound, 18, '0.07 0.07 0.00', '0 0 0', 1.0, 0x20, 0, 0);
SetThingFlags(littletim, 0x300);
SetThingModel(littletim, newmodel);
jkSetWeaponMesh(littletim, weaponMesh);
SetPulse(.01);
SyncThingPos(littletim);
timactive = 2;
return;
}

pulse:
if (isdamaged == 1) {
playerface = VectorSub(GetThingPos(player), GetThingPos(littletim));
SetThingLook(littletim, playerface);
playerdir = VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(littletim))), 5);
ApplyForce(littletim, playerdir);
return;
}
if (isdamaged == 2) {
if (damageguy == -1){
isdamaged = 1;
return;
}
face = VectorSub(GetThingPos(damageguy), GetThingPos(littletim));
SetThingLook(littletim, face);
dir = VectorScale(VectorNorm(VectorSub(GetThingPos(damageguy), GetThingPos(littletim))), 5);
ApplyForce(littletim, dir);
return;
}
return;

damaged:
damageguy = GetSourceRef();
isdamaged = 2;
return;

end

How the hecktic henry odule can I fix this?

------------------
Those who stare in the eyes of death and laugh will be the first to go.
Those who stare in the eyes of death and laugh will be the first to go.
2001-02-25, 3:18 AM #2
Here's the way I would do it (and yes, I am working on a set of AI something like this right now), however, since I'm not at home, I don't have any reference material (my cogs), so this may not work:

[just saw that you wanted him to follow the enemy too]

code:
Quote:
<font face="Verdana, Arial" size="2">
message startup
message pulse
message damaged

thing Joe //it's Joe!
thing player local
thing attacker local

int attacked=0 local

startup:
player=GetLocalPlayerThing();
SetPulse(0.1);
return;

pulse:
if (attacked==0){
AISetLookThing(Joe, player);
AISetMoveThing(Joe, player);
}
else
if (attacked==1){
if (GetThingHealth(attacker)>0.0){
AISetLookThing(Joe, attacker);
AISetMoveThing(Joe, attacker);
AISetFireTarget(Joe, attacker);
AISetMode(0x29);//Just in case...
}
else
{
attacked=0;
}
return;

damaged:
if (GetSenderRef()==player){
attacked=1;
attacker=GetSourceRef();
}

return;

end;
</font>


------------------
Black. His gloves of finest wool.
Black. His codpiece made of metal.
His horse is blacker than a hole.
His pot is blacker than his kettle.

Visit Virus Productions!

[This message has been edited by LordVirus (edited February 25, 2001).]
"And lo, let us open up into the holy book of Proxy2..." -genk
His pot is blacker than his kettle!
2001-02-25, 5:20 AM #3
hmm, will that kind of stuff work in a multi player game? I've never tried it. Anyway, GuNbOy pointed out a small problem that I fixed, but it still doesn't work. Here's what I have now (I cleaned it up)

Code:
# Jedi Knight Cog Script
#
# FORCE_BLINDING.COG
#
# Little Tim -- misc. force power script.
#
# This creates a kyle character that follows the player until the player is damaged.
# Upon damage, Little Tim will begin to follow the assailant, annoying the crap out of him.
#
# May be used in both Single and Multi player games.
#
# Hoard
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

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

symbols

model	newmodel=kyg7.3do	local
model   weaponMesh=cong.3do     local

sound	activsound=i09ky01z.wav local

template base=walkplayer 	local
template shot=+concbullet	local

flex 	timactive=1		local
flex	isdamaged=1		local

message activated
message pulse
message	damaged

end

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

code

#------------------------------

activated:

if (timactive == 2) {
   DestroyThing(littletim);
   SetPulse(0);
   timactive = 1;
   return;
}
if (timactive == 1) {
   player = GetSourceRef();
   littletim = FireProjectile(player, base, activsound, 18, '0.07 0.07 0.00', '0 0 0', 1.0, 0x20, 0, 0);
   SetThingFlags(littletim, 0x300);
   SetThingModel(littletim, newmodel);
   jkSetWeaponMesh(littletim, weaponMesh);
   SetPulse(.01);
   SyncThingPos(littletim);
   timactive = 2;
   return;
}

#------------------------------

pulse:

if (isdamaged == 1) {
   playerface = VectorSub(GetThingPos(player), GetThingPos(littletim));
   SetThingLook(littletim, playerface);
   playerdir = VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(littletim))), 5);
   ApplyForce(littletim, playerdir);
   return;
}

else if (isdamaged == 2) {
      if (damageguy == -1) {
      isdamaged = 1;
      return;
}
   face = VectorSub(GetThingPos(damageguy), GetThingPos(littletim));
   SetThingLook(littletim, face);
   dir = VectorScale(VectorNorm(VectorSub(GetThingPos(damageguy), GetThingPos(littletim))), 5);
   ApplyForce(littletim, dir);
   return;
}
return;

#------------------------------

damaged:

damageguy = GetSourceRef();
isdamaged = 2;
return;

end


------------------
Those who stare in the eyes of death and laugh will be the first to go.
Those who stare in the eyes of death and laugh will be the first to go.
2001-02-26, 2:25 PM #4
The cog doen't know what the "damaged" section is.

Since this cog is an individual one from other cogs, you have to either "CaptureThing(thing)" or mask the "thing" in the symbols or put this cog in "kyle.cog", so it returns the "damaged" message to the appropriate thing, player.

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited February 26, 2001).]
2001-02-27, 3:11 AM #5
so how would I go about doing that Hideki? I'm sort of new to cogging and I havn't gotten everything down. Good thing is I only need to hear it once.

------------------
Those who stare in the eyes of death and laugh will be the first to go.
Those who stare in the eyes of death and laugh will be the first to go.
2001-02-27, 5:47 PM #6
Surest way is to put the whole thing in the kyle.cog, but I'm not sure what you mean by the "activated" message.

What you basically do is get the damaged section get called by kyle.cog which is attached to the player.

Then start a pulse message to constantly get your AI guy to attack the "GetThingParent(GetSenderRef())" in the damaged message. Not just GetSenderRef() in the damaged section, it only gets the projectile that hit you.

------------------
http://millennium.massassi.net/ - Millennium
2001-02-28, 3:52 AM #7
Well, the activated message, er, activates the AI. The cog name is force_blinding.cog for now, just to replace it so I can test it out, so putting the whole thing in the kyle.cog wouldn't allow me to turn him on/off.

------------------
Those who stare in the eyes of death and laugh will be the first to go.
Those who stare in the eyes of death and laugh will be the first to go.
2001-02-28, 8:07 AM #8
You could put it all in the kyle.cog and just make the force blinding cog send a message to the kyle.cog that tells it to activate.

------------------
Together we stand.
Divided we fall.

↑ Up to the top!