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 → Adding a feature.
Adding a feature.
2004-09-25, 8:18 PM #1
I need the knight to patrol from one ghost to another, ina function that can be turned on and off, but without disrupting the flames:

Code:
# 03_sneaky.cog
# [Grismath]
# 5.27.04
#
# NEW: 8.29.04: Loop through all surfaces to find ones
#  with a custom flag, then set those to geo4, and
#  scroll them down.
#
#  Thanks go to LKOH_SniperWolf for the rain code.
#
#=====================================================#
symbols
message	entered
thing		player		local
sector		outside
thing		windowcam
thing		knight
thing		torch0
thing		torch1
thing		torch2
thing		light0
thing		light1
thing		light2
template	flame
thing		viewcam
thing		telewindow
material	rainmat
flex     animRate
int      numSurfs    local
int      i           local
int		rainstat=0	local
int		lt0=1	local
int		lt1=1	local
int		lt2=1	local
vector		slidevec
flex		slidespeed
end
#=======================================================#
code
#--------------------------------------------------------
user0:
SetPulse(0.5);
return;
#--------------------------------------------------------
activated:
if(GetSenderRef()==torch0) {
lt0=0;
SetThingLight(light0, 0.0);
}
if(GetSenderRef()==torch1) {
lt1=0;
SetThingLight(light1, 0.0);
}
if(GetSenderRef()==torch2) {
lt2=0;
SetThingLight(light2, 0.0);
}
if(lt0==1 && lt1==1 && lt2==1 && warg==0) {
warg=1;
SetActorFlags(player, 0xa00000);
// Stop patrol
SetCameraFocus(0, viewcam);
Print("SOLDIER: The flames died... that's odd.");
Sleep(2.0);
PlaySoundLocal(thunder, 1, 0, 0x0);
TeleportThing(knight, telewindow);
Sleep(1.0);
SetCameraFocus(0, windowcam);
rainstat=1;

numSurfs = GetSurfaceCount();
for(i = 0; i < numSurfs; i = i + 1){
    if(GetSurfaceMat(i) == rainmat) {
	SetFaceGeoMode(i,0x4);
	slidewall(i, slidevec, slidespeed);
    }
}
Sleep(1.0);
Print("SOLDIER: Ah, that explains it.");
Sleep(2.0);
SetCameraFocus(0, advcam);
ClearActorFlags(player, 0xa00000);
}
return;
#--------------------------------------------------------
pulse:
if(rainstat==1) {
 return;
} else {
if(lt0==1) CreateThing(flame, light0);
if(lt1==1) CreateThing(flame, light1);
if(lt2==1) CreateThing(flame, light2);
// patroller move
}
return;
#--------------------------------------------------------
entered:
if(GetSenderRef()==outside && wraa==0) {
wraa=1;
SetActorFlags(player, 0xa00000);
SetCameraFocus(0, windowcam);
Print("INSIDE: Knave, why durst thou abandon thy post?");
Sleep(2.0);
AISetMovePos(knight, GetThingPos(telewindow));
Sleep(1.0);
Print("SOLDIER: My apologies, sir, it shall not happen again.");
Sleep(2.5);
Print("INSIDE: See to it that is does not.");
Sleep(2.0);
SetCameraFocus(0, advcam);
ClearActorFlags(player, 0xa00000);
// Begin patrol sequence
}
if(GetSenderRef()==path0 && lt0==1) {
if(GetThingSector(knight)==left || GetThingSector(knight)==right) {
// Copy this for the other two path parts
SetActorFlags(player, 0xa00000);
// Stop Patrol
SetCameraFocus(0, windowcam);
Print("SOLDER: Sir!  Someone approaches!");
Sleep(2.0);
SetCameraFocus(0, viewcam);
Sleep(1.0);
ClearActorFlags(player, 0xa00000);
DamageThing(player, 999, 0x1, player);
}
}
if(GetSenderRef()==path1 && lt1==1) {
if(GetThingSector(knight)==left || GetThingSector(knight)==right) {
SetActorFlags(player, 0xa00000);
Print("SOLDER: Sir!  Someone approaches!");
Sleep(2.0);
ClearActorFlags(player, 0xa00000);
DamageThing(player, 999, 0x1, player);
}
}
if(GetSenderRef()==path2 && lt2==1) {
if(GetThingSector(knight)==left || GetThingSector(knight)==right) {
SetActorFlags(player, 0xa00000);
Print("SOLDER: Sir!  Someone approaches!");
Sleep(2.0);
ClearActorFlags(player, 0xa00000);
DamageThing(player, 999, 0x1, player);
}
}
return;
#--------------------------------------------------------
end
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2004-09-26, 11:57 AM #2
Well, this should do it. Once again, untested. But, hopefully right. The # comments should probably be removed, but I wanted to make it easier to tell which each does.

You can add more ghosts as needed, just don't forget to make sure numPositions is set appropriately. It should be the number of actual ghosts used (remembering ghost0 is 1)

moveSpeed determines the AI's movespeed.

willLoop; this is basically a boolean, 0 for false, anything greater than 0 for true.
If willLoop is true, when the AI gets to the last ghost position, he'll move from there to the first ghost. This would be what you'd want if you wanted a circular path.
If false, when the AI gets to the last position, it will go from there to the second to last ghost, on back towards the first. When at the first, it will start back. Basically this will cause it to go back and forth along them, more useful if it's a straightline path.

Code:
thing     knight
thing     ghost0
thing     ghost1
thing     ghost2
thing     ghost3
thing     ghost4

int       on = 0       local

int       numPositions
#set this equal to the number of ghosts used
#IE ghost#, take that # + 1...

int       willLoop
#set this to 1 or greater, if you want it to
#go from the last used ghost 

int       i2            local

flex      moveSpeed

message   knightPatrol



knightPatrol:
if(on == 0){
    on = 1;
}else{
    on = 0;
    AISetMoveThing(knight, ghost0);
    AISetMode(knight, 0x0);
}

while(on){
    AISetMoveSpeed(knight,moveSpeed);
    AISetMode(knight,0x1);
    if(willLoop){
        for(i2 = 0; i2 < numpositions; i2 = i2 + 1){
            AISetMoveThing(knight, ghost0[i2]);
            AISetLookPos(knight, GetThingPos(ghost0[i2]));

            //This makes the code wait till the AI is within a reasonable distance
            //to the ghost position before letting it go to the next one.
            while(VectorDist(GetThingPos(knight),GetThingPos(ghost0[i2])) > .05){
                Sleep(.1);
            }
        }
    }else{
        for(i2 = 0; i2 < numpositions; i2 = i2 + 1){
            AISetMoveThing(knight, ghost0[i2]);
            AISetLookPos(knight, GetThingPos(ghost0[i2]));

            while(VectorDist(GetThingPos(knight),GetThingPos(ghost0[i2])) > .05){
                Sleep(.1);
            }
        }
        for(i2 = numpositions - 1; i2 > -1; i2 = i2 - 1){
            AISetMoveThing(knight, ghost0[i2]);
            AISetLookPos(knight, GetThingPos(ghost0[i2]));

            while(VectorDist(GetThingPos(knight),GetThingPos(ghost0[i2])) > .05){
                Sleep(.1);
            }
        }
    }
}

Return;


Let me know how it turns out.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2004-09-26, 12:01 PM #3
That while statement with the VectorDist should all be on one line. The forum just word-wrapped it.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come

↑ Up to the top!