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 → I've come a LONG way (cog showcase)
I've come a LONG way (cog showcase)
2004-01-02, 8:06 PM #1
I was looking at some of my old cogs to see how i did stuff, and I relized that i went from my 473 line spawning system cog for SM HQ, which was rather lame, to this 93 line long cog that controls the spawning in Attack on Theed. (i admit, alot of the lines are due to my spacing organization habbits)

My AoT spawning system automatically randomly spawns you at one of four points in the "spawning area" that is closet to where you died. This keeps the action where I want the action to be taking place, and keeps it happening. In the future I may add more points in each spawning area, but for now 4 is good. Check it out and tell me what you think.

Code:
# Jedi Knight Cog Script
#
# 1337sp4wn.cog
#
# Controls the player spawning in Attack on Theed: Final Assault.
#
# [SM SIth Lord]
#
# This cog is not made or distributed by LucasArts Entertainment Co.

flags=0x240

symbols

message		newplayer
message		killed

thing		primer_point
thing		spawnarea0
thing		spawnarea1
thing		spawnarea2
thing		spawnarea3

thing		r0sa0
thing		r0sa1
thing		r0sa2
thing		r0sa3

thing		r1sa0
thing		r1sa1
thing		r1sa2
thing		r1sa3

thing		r2sa0
thing		r2sa1
thing		r2sa2
thing		r2sa3

thing		r3sa0
thing		r3sa1
thing		r3sa2
thing		r3sa3

thing		r4sa0
thing		r4sa1
thing		r4sa2
thing		r4sa3

int		numspawns=4
int		primer_spawn=1	local
int		player		local

flex		magicnum	local

end

# ========================================================================================

code

newplayer:
player = GetSourceRef();
CaptureThing(player);
if( primer_spawn ){
  primer_spawn = 0;
  TeleportThing(player,primer_point);
  return;
  }
bestdist = VectorDist(playerpos,GetThingPos(spawnarea0));
bestindex = 0;
for(index=0; index < numspawns; index = index + 1){
   if( VectorDist(playerpos,GetThingPos(spawnarea0[index])) <= bestdist ){
     bestdist = VectorDist(playerpos,GetThingPos(spawnarea0[index]));
     bestindex = index;
     }
   }
magicnum = Rand();
if( magicnum < 0.25 ) JumpToFrame(spawnarea0[bestindex],1,GetThingSector(r1sa0[bestindex]));
else if( magicnum >= 0.25 && magicnum < 0.50 ) JumpToFrame(spawnarea0[bestindex],2,GetThingSector(r2sa0[bestindex]));
else if( magicnum >= 0.50 && magicnum < 0.75 ) JumpToFrame(spawnarea0[bestindex],3,GetThingSector(r3sa0[bestindex]));
else if( magicnum >= 0.75 ) JumpToFrame(spawnarea0[bestindex],4,GetThingSector(r4sa0[bestindex]));
TeleportThing(player,spawnarea0[bestindex]);
JumpToFrame(spawnarea0[bestindex],0,GetThingSector(r0sa0[bestindex]));
return;

killed:
player = GetSourceRef();
playerpos = GetThingPos(player);
return;

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

end


Anothing note: The JK 3do limit was kept in mind when making this cog, very much so. With this cog (modified), you can have unlimited "spawn zones" and unlimited spawn points using only ONE 3do, the ghost "thing" that does all the work. [http://forums.massassi.net/html/smile.gif] It serves its purpose very well.

------------------
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
2004-01-02, 8:11 PM #2
Lol, i guess i forgot to say a couple important details. The long list of "things" are simply 3do's that are in the sector that the frame of the primer_point is going to jump to. So, in an essence, it only takes that one 3do, because the reference 3do's would be there anyways. The naming system goes as follows:
r0sa0 = reference object 0 / spawn area 0

I also forgot that each spawn area uses its own ghost 3do at the moment, but i should be able to use one of the reference objects as the spawn area ghost if i'm not too picky about defining the spawn zones EXACTLY where i want them.

One more thing, why the HELL did I capture the player? lol. anybody? i'll be d4mned if I know.

------------------
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.

[This message has been edited by SM_Sith_Lord (edited January 02, 2004).]
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
2004-01-02, 8:16 PM #3
LMAO, geez, i don't even understand my own cog. Looks like i have the spawnareaX ghosts for each spawn zone jump to the place of spawning. Geez, why didn't I just use one ghost to jump all around the level? i think some reivsion is in order.

------------------
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
One day, after everybody else quits, I'll be the best.
Sith Mercenaries
^My site.
2004-01-03, 4:46 AM #4
A very good idea, indeed.

↑ Up to the top!