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 → Generator2 cog help
Generator2 cog help
2004-11-17, 11:43 AM #1
i need help witgh my AI generator cog. I am using the one off massassi, but there is one problem, When playing with 2 or more people, 2 AIs spawn when the first one is killed, even though the max alive thing is set to 1. I don't even know where to start to fix it. If anyone can help, it'd be awesome. Here's the cog I am using, so you can just edit this one to save time.. thanks.

#This is a mod made by FantomJedi -- e-mail Fantom117A@aol.com
#
#The thing is the number of the ghost object where the enemy is spawned
#
#The template is the enemy you want to use
#
#The gen_num is how many total enemies you want before the cog stops respawning them
#
#The max_alive is how many enemies are alive at once
#
#Jedi Knight Cog Script
#
# 06_generator.cog
#
# Cribbed from generic generator, for use in last tower room
#
# [RD]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ========================================================================================

symbols

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

thing generator_pos desc=generator_ghost

template enemy_tpl desc=enemy_to_generate

int initial_delay=1.0 local desc=initial_delay
int generate_delay=5.0 local desc=generate_delay
int min_dist=0.0 local desc=min_distance
int max_dist=1000.0 local desc=max_distance

float distance=1.0 local

cog squadmaker local

int enemy local
int cur_num=0 local
int cur_alive=0 local
int generate_num
int max_alive desc=max_alive

end

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

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(initial_delay != -1) SetTimer(initial_delay);
Return;

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

user0:
// FIXME!! remove next line when parsing bug is corrected
enemy = enemy;
// fall through on purpose

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

timer:
SetPulse(generate_delay);
// fall through on purpose

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

pulse:
if((cur_alive < max_alive))
{
distance = VectorDist(GetThingPos(generator_pos), GetThingPos(GetLocalPlayerThing()));
if((distance >= min_dist) && (distance <= max_dist))
{
if(IsThingVisible(generator_pos)==0)
{
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:
cur_alive = cur_alive - 1;
SendMessage(squadmaker, user0);
return;

end
||||||||||||||||||||
2004-11-17, 12:41 PM #2
Aren't there some resawning AI COGs here at Massassi?

And please tell me this isn't for generating waves of enemies. Respawning enemies are a poor design choice almost all of the time.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2004-11-17, 2:34 PM #3
Emon, don't worry i know what I'm doing...unless it comes to writing cog.. for that, I only sometimes know what I am doing.. ;)
||||||||||||||||||||
2004-11-17, 2:42 PM #4
Also, if no one can figure out the first cog... I could use a variation of THIS cog instead.. (but I'd rather have the first cog)...

I need this cog to spawn another AI after so many seconds (maybe 20 mins)

# Jedi Knight Cog Script
#
# 00_GENERATOR2.COG
#
# Simplified single-enemy generator triggered by entering a sector
# Useful to prevent early enemy wakeup, slow framerates at long distances, etc.
# [RKD]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

symbols
message entered

sector trigger

thing generator_pos nolink desc=generator_ghost

template enemy_tpl desc=enemy_to_generate

int itsalive=0 local
end

## Code Section

code

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

entered:
if (itsalive) return;

CreateThing(enemy_tpl, generator_pos);
itsalive = 1;
DestroyThing(generator_pos);
return;
end
||||||||||||||||||||
2004-11-17, 3:10 PM #5
Maybe it needs the proper flags. Try this:

Code:

#This is a mod made by FantomJedi -- e-mail Fantom117A@aol.com
#
#The thing is the number of the ghost object where the enemy is spawned
#
#The template is the enemy you want to use
#
#The gen_num is how many total enemies you want before the cog stops respawning them
#
#The max_alive is how many enemies are alive at once
#
#Jedi Knight Cog Script
#
# 06_generator.cog
#
# Cribbed from generic generator, for use in last tower room
#
# [RD]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ==========================

flags=0x80

symbols

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

thing generator_pos desc=generator_ghost

template enemy_tpl desc=enemy_to_generate

int initial_delay=1.0 local desc=initial_delay
int generate_delay=5.0 local desc=generate_delay
int min_dist=0.0 local desc=min_distance
int max_dist=1000.0 local desc=max_distance

float distance=1.0 local

cog squadmaker local

int enemy local
int cur_num=0 local
int cur_alive=0 local
int generate_num
int max_alive desc=max_alive

end

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

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(initial_delay != -1) SetTimer(initial_delay);
Return;

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

user0:
// FIXME!! remove next line when parsing bug is corrected
enemy = enemy;
// fall through on purpose

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

timer:
SetPulse(generate_delay);
// fall through on purpose

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

pulse:
if((cur_alive < max_alive))
{
distance = VectorDist(GetThingPos(generator_pos), GetThingPos(GetLocalPlayerThing()));
if((distance >= min_dist) && (distance <= max_dist))
{
if(IsThingVisible(generator_pos)==0)
{
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:
cur_alive = cur_alive - 1;
SendMessage(squadmaker, user0);
return;

end
KOP_blujay
Just dancin'...and singin'...in the Force.
2004-11-17, 9:16 PM #6
hey blujay, i tried it, and it's doing the same thing.. it generates 1 at the beginning of the level, but once you kill it, it generates 2.. (if there is more than one person in the game.. if it's only me, it works fine)
||||||||||||||||||||
2004-11-18, 2:00 PM #7
Try this (already sent it to you, posting here for posterity):

Code:
#This is a mod made by FantomJedi -- e-mail Fantom117A@aol.com
#
# Rewritten Nov/18/2004 by blujay
#
#The thing is the number of the ghost object where the enemy is spawned
#
#The template is the enemy you want to use
#
#The gen_num is how many total enemies you want before the cog stops respawning them
#
#The max_alive is how many enemies are alive at once
#
#Jedi Knight Cog Script
#
# 06_generator.cog
#
# Cribbed from generic generator, for use in last tower room
#
# [RD]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ==========================

flags=0x80

symbols

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

thing generator_pos desc=generator_ghost

template enemy_tpl desc=enemy_to_generate

int initial_delay=1.0 local desc=initial_delay
int generate_delay=5.0 local desc=generate_delay
int min_dist=0.0 local desc=min_distance
int max_dist=1000.0 local desc=max_distance

float distance=1.0 local

cog squadmaker local

int enemy local
int cur_alive=0 local
int max_alive desc=max_alive

end

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

code

startup:
	SetTimer(initial_delay);
	
	Return;

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

timer:
	SetPulse(generate_delay);
	
	return;

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

pulse:
	if((cur_alive < max_alive)) {
		distance = VectorDist(GetThingPos(generator_pos), GetThingPos(GetLocalPlayerThing()));
		if((distance >= min_dist) && (distance <= max_dist)) {
			if(IsThingVisible(generator_pos)==0) {
				enemy = CreateThing(enemy_tpl, generator_pos);
				CaptureThing(enemy);

				cur_alive = cur_alive + 1;

			}
		}
	}
	
	return;

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

killed:
	cur_alive = cur_alive - 1;

	return;

end
KOP_blujay
Just dancin'...and singin'...in the Force.

↑ Up to the top!