Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
spawn point code #425209
06/29/13 03:08
06/29/13 03:08
Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
L
LewyT Offline OP
Newbie
LewyT  Offline OP
Newbie
L

Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
I have a function I wrote to place multiple model entities in a map.
The compiled map has an entity named "humanspawn"
this function finds that entity and uses its location to place multiple copies of the player model.
The problem I'm having is that the models all get spawned in the same location (exactly).
I think I may be using c_scan() incorrectly when trying to detect if another model is already there.
any ideas?

Code:
function spawnhumans( var num )
{
	STRING* s = "";
	STRING* s1 = "humanspawn"; // this is the name of a model already in the compiled level
	var i;
	var found;
	VECTOR* loc = vector(0,0,0);
	ENTITY* spawnpoint;

	spawnpoint = ent_next (NULL);
	if ( spawnpoint == NULL ) spawnpoint = ent_next (NULL);
	str_for_entname ( s, spawnpoint); // get the name of the entity whe just set spawnpoint to
	
	while( !(str_cmpni (s, s1)) ); // if the name of the ent is not "humanspawn" then its the wrong one and keep looking
	{
		spawnpoint = ent_next (spawnpoint);
		if ( spawnpoint == NULL ) spawnpoint = ent_next (NULL);
		str_for_entname ( s, spawnpoint);
		wait(1);
	}

	spawnpoint.group = 1; //
	//c_ignore( 1 );

	loc.x = spawnpoint.x;
	loc.y = spawnpoint.y;
	loc.z = spawnpoint.z;
	
	for( i = 1; i <= num; i++ )
	{
		
		c_ignore( 1 );
		found = c_scan (loc, vector(0,0,1), vector(360,0,500), SCAN_ENTS | IGNORE_WORLD | IGNORE_MAPS ); 

		while ( found > 0 )
		{
			loc.x = loc.x+(-100+random(200));
			loc.y = loc.y+(-100+random(200));
			
			c_ignore( 1 );
			found = c_scan (loc, vector(0,0,1), vector(360,0,500), SCAN_ENTS | IGNORE_WORLD | IGNORE_MAPS ); 

			wait(1);
		}

		if ( i == num )
		{
			player = ent_create("guy5.mdl", vector(loc.x,loc.y,loc.z), updatecharacter); 
		}else{
			ent_create("guy5.mdl", vector(loc.x,loc.y,loc.z), updatecharacter);
		}

		wait(1);
	}
}


Re: spawn point code [Re: LewyT] #425216
06/29/13 08:20
06/29/13 08:20
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Your STRING and VECTOR declarations are incorrect (vector(...) does not create a vector), they should read as follows:
STRING* s1 = str_create("humanspawn"); // you have to write ptr_remove(s1); at the end of your function
VECTOR loc;

Why do you use wait(1)s in your loop? This does not seem useful to me.

Your first loop is pretty strange, why don't you replace it completely with ent_for_name?

Your parameter(s) of c_ignore are wrong, there is a 0 missing (check the manual).

From what I can see you never set found to anything above zero (or initialize it at all).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: spawn point code [Re: Superku] #425269
07/01/13 03:53
07/01/13 03:53
Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
L
LewyT Offline OP
Newbie
LewyT  Offline OP
Newbie
L

Joined: Nov 2011
Posts: 21
MO:US and sometimes Ambato Ecu...
Superku,
thanks for your help!

I used wait(1) and sometimes wait(-1) so I could see what was happening from camera location (before the player character was created.
I also try to use wait(1) in every while loop to keep from freezing the game if I made a mistake and the condition never becomes false.

I use str_cmpni in the first loop so it can match partial words.

I added the 0 to c_ignore but it didn't seem to help.

my intention with "found" is that it be zero whenever c_scan hasn't found any other entity close by.

with most of your suggested changes and a wait(-.5) this is my working code:
The main things seemed to be the VECTOR declaration and the wait which allows my action to set the ENABLE_SCAN emask.

Code:
function spawnhumans( var num )
{
	STRING* s = str_create("");
	STRING* s1 = str_create("humanspawn"); // this is the name of a model already in the compiled level
	var i;
	var found = 0;
	var sp = 0;
	var sp1 = 1;
	var temp;
	VECTOR loc;
	ENTITY* spawnpoint;

	spawnpoint = ent_next (NULL);
	if ( spawnpoint == NULL ) spawnpoint = ent_next (NULL);
	str_for_entname ( s, spawnpoint); // get the name of the entity whe just set spawnpoint to
	while( !(str_cmpni (s, s1)) ); // if the name of the ent is not "humanspawn" then its the wrong one and keep looking
	{
		spawnpoint = ent_next (spawnpoint);
		if ( spawnpoint == NULL ) spawnpoint = ent_next (NULL);
		str_for_entname ( s, spawnpoint);
		wait(1);
	}

	spawnpoint.group = 1; //

	loc.x = spawnpoint.x;
	loc.y = spawnpoint.y;
	loc.z = spawnpoint.z;
	
	for( i = 1; i <= num; i++ )
	{
		c_ignore( 1,0 );
		found = c_scan (loc, vector(0,0,1), vector(360,0,100), SCAN_ENTS | SCAN_LIMIT | IGNORE_WORLD | IGNORE_MAPS ); 

		while ( found > 0 )
		{
			vec_add( loc, vector(-100+random(200),    0,             0) );
			vec_add( loc, vector(0,                -100+random(200), 0) );
			//loc.x = loc.x+(-100+random(200));
			//loc.y = loc.y+(-100+random(200));
			
			c_ignore( 1,0 );
			found = c_scan (loc, vector(0,0,1), vector(360,0,100), SCAN_ENTS | SCAN_LIMIT | IGNORE_WORLD | IGNORE_MAPS ); 

			//wait(1);
		}

		//loc.x = i*100;
		
		if ( i == num )
		{
			player = ent_create("guy5.mdl", vector(loc.x,loc.y,loc.z), updatecharacter); 
		}else{
			ent_create("guy5.mdl", vector(loc.x,loc.y,loc.z), updatecharacter);
		}

		wait(-.5);
	}
	
	ptr_remove(s);
	ptr_remove(s1);
}



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1