matrix: 00_generator.cog


[ Follow Ups ] [ Post Followup ] [ Jed Messages ]

Posted by Stealth on January 09, 1998 at 11:45:39:


The examples are from 06bbarons.jkl.

Ok the generator cog..

# 00_GENERATOR.COG
#
# Generic Dark Forces like enemy generator.

# I got this next line from the placed cogs section in the above JKL. These are the params passed to the generator cog

# 17: 00_GENERATOR.COG 283 probedroid 300.000000 30.000000 3 1 0.000000 1000.000000


# this is from the "world things" in the same jkl file.

#num template: name: X: Y: Z: Pitch: Yaw: Roll: Sector:
#283: ghost ghost 75.644798 26.638800 5.075000 0.000000 0.000000 0.000000 589 thingflags=0x400

symbols

thing generator_pos desc=generator_ghost(this is Thing number 283 from world things list it happens to be a "GHOST" this is the first value passed by the placed cog line.)
template enemy_tpl desc=enemy_to_generate(this is the thing template name you want to generate "probedroid" in this case from second value of placed cog line.
flex initial_delay=300.0 desc=initial_delay(you could remove this desc= and replace with "local" as the 300.000000 third value is the same as set inthe cog then you won`t have to type it in jed you can change initial_delay=300.0 to what ever you want it to be either way).
flex generate_delay=30.0 desc=generate_delay(same here 30.000000)
int generate_num=5 desc=generate_number(placed cog passed 3 so only three droids will be generated you can set to loacl and change the 5 to what ever (not too many))
int max_alive=3 desc=max_alive(placed cog passing "1" only one alive at once same here "local")
flex min_dist=0.0 desc=min_dist the last two are the min and max distance from the player it will generate as these are the same values you could set them to local and use your own numbers. LEC left these not local so the cog is more universal and can be reused several times in a level)
flex max_dist=1000.0 desc=max_dist

So you really only need to add a ghost to your level some place ,get the "Thing number" from top of thing editor, and pick an enemy template name to use(you can add another thing to get the name and just delete it later), if you set the rest to loacl and edit the values to what you want that is all you will have to enter in Jed. else you can pass all the values like the placed cog example line.
And it should go.do`nt forget to give your ghost the thing flags 0x400

int enemy local
int cur_num=0 local
int cur_alive=0 local
flex distance=0.0 local

message startup
message user0
message timer
message pulse
message killed mask=0xfff

end

## Code Section

code

//-------------------------------------------------------------------------------------------------

startup:
// if initial_delay == -1 then the generator will be started by SendMessage
// user0 from another COG. Much like the WAKEUP message in DF...
if (generator_pos == -1) return; // if generator doesn't appear on this difficulty, quit

if(initial_delay != -1) SetTimer(initial_delay);

Return;

//-------------------------------------------------------------------------------------------------

user0:

//-------------------------------------------------------------------------------------------------

timer:
SetPulse(generate_delay);

//-------------------------------------------------------------------------------------------------

pulse:
if((cur_alive < max_alive))
{
distance = VectorDist(GetThingPos(generator_pos), GetThingPos(jkGetLocalPlayer()));
if((distance >= min_dist) && (distance <= max_dist))
{
if(!HasLOS(player, generator_pos))
{
enemy = CreateThing(enemy_tpl, generator_pos);
CaptureThing(enemy);

cur_num = cur_num + 1;
cur_alive = cur_alive + 1;

// If we have generated enough enemies, end the pulse
if(cur_num >= generate_num) SetPulse(0);
}
}
}

Return;

//------------------------------------------------------------------------------------------------

killed:
// Note that this script is generic, so generated enemies won't drop powerups.
// If dropped powerups are necessary, one script per enemy must be done...
cur_alive = cur_alive - 1;

Return;

end




Follow Ups:



Post a Followup

Name:
E-Mail:
Subject:
Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ Jed Messages ]