Pickspawn
Moderator: InsideQC Admins
3 posts
• Page 1 of 1
Pickspawn
Hi Everyone:
Need some help with the find statement. I pretty much want to have it walk down the classname list, pick a random spawn entity and return it, but not sure how to complete it?
This can I guess rudementarily work....but lets say I already counted the number of deathmatch spawns in the Quaked part of the QC for those entities, and we have (8) of them. I also assigned them a .cnt to equal their number in sequence of order as they load from the map. COuld I edit this code so a random float is send here, and we use find to pick its .cnt value?
Need some help with the find statement. I pretty much want to have it walk down the classname list, pick a random spawn entity and return it, but not sure how to complete it?
- Code: Select all
entity(string className) Pickspawn =
{
local entity p;
p = find(world, classname, className);
while (p != world)
{
{
if (random () < 0.25)
lastspawn = p;
return (p);
}
p = find(p, classname, className);
}
};
This can I guess rudementarily work....but lets say I already counted the number of deathmatch spawns in the Quaked part of the QC for those entities, and we have (8) of them. I also assigned them a .cnt to equal their number in sequence of order as they load from the map. COuld I edit this code so a random float is send here, and we use find to pick its .cnt value?
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: Pickspawn
- Code: Select all
/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24)
potential spawning position for deathmatch games
*/
void() info_player_deathmatch =
{
self.angles = self.mangle;
self.model = "";
self.origin = self.origin + '0 0 2';
num_dm_spawns += 1; //R00k count spawns for random spawns.
};
- Code: Select all
entity () SelectSpawnPoint =
{
local entity spot;
local entity thing;
local float pcount;
if (deathmatch)
{
spot = lastspawn;
pcount = (random() * num_dm_spawns);
while (pcount)
{
spot = find(spot, classname, "info_player_deathmatch");
pcount -= 1;
}
while (1)
{
if (spot != world)
{
if (spot == lastspawn)
return lastspawn;
pcount = 0;
thing = findradius(spot.origin, 32);
while(thing)
{
if (thing.classname == "player")
pcount = pcount + 1;
thing = thing.chain;
}
if (pcount == 0)
{
lastspawn = spot;
return spot;
}
}
spot = find(spot, classname, "info_player_deathmatch");
}
}
if (serverflags)
{
spot = find (world, classname, "info_player_start2");
if (spot)
{
return (spot);
}
}
spot = find (world, classname, "info_player_start");
if (!spot)
{
error ("PutClientInServer: no info_player_start on level");
}
return (spot);
};
As you can see it's just taking a random number out of the available spawns then looping thru them until it reaches zero. Then scans for anyone nearby, if so then searches once more.
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
Re: Pickspawn
Hey, thats not too bad. I tried it, but it cast a runaway loop, and my compiler dont like -=
I hacked up your code a little, and merged it with some of mine, and seems to be working pretty well.
I am counting the number of each spawn entity class in a global, as well as carryng that incremented value to its self.cnt value.
A new routine I made called : MultiSpawnSelect () will pick the classname randomly, then ask Pickspawn() to look through that list.
I am using it too for the Runes to randomly spawn if not picked up, and so far its looking good. I have seen that findradius used in I think the old
telefragselectspawnpoint() code, but I want to experiment assigning the spawn entity a self.spawn_time equal maybe to time + 5 , and if
we scan the entity and its spawn_time < time, we will figure its safe and clear. I might decide to later use both, not sure yet.
I hacked up your code a little, and merged it with some of mine, and seems to be working pretty well.
I am counting the number of each spawn entity class in a global, as well as carryng that incremented value to its self.cnt value.
A new routine I made called : MultiSpawnSelect () will pick the classname randomly, then ask Pickspawn() to look through that list.
I am using it too for the Runes to randomly spawn if not picked up, and so far its looking good. I have seen that findradius used in I think the old
telefragselectspawnpoint() code, but I want to experiment assigning the spawn entity a self.spawn_time equal maybe to time + 5 , and if
we scan the entity and its spawn_time < time, we will figure its safe and clear. I might decide to later use both, not sure yet.
- Code: Select all
entity(string className) Pickspawn =
{
local entity p;
local float pcount,scount;
if (className == "info_player_deathmatch")
scount = DMSPAWNS;
if (className == "info_player_start")
scount = STARTSPAWNS;
if (className == "info_player_start2")
scount = START2SPAWNS;
if (className == "info_player_coop")
scount = COPPSPAWNS;
if (className == "info_teleport_destination")
scount = TELESPAWNS;
if (className == "info_player_team2")
scount = BLUESPAWNS;
if (className == "info_player_team1")
scount = REDSPAWNS;
dprint (self.classname);
dprint (" Pickspawn");
dprint (className);
dprint ("\n");
pcount = rint (random() * scount);
p = find (world, classname, className);
while ((p != world))
{
if (p.cnt == pcount)
{
lastspawn = p;
return (p);
}
p = find (p, classname, className);
}
};
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest