What is covered in this post is bz_getStandardSpawn() and bz_eGetPlayerSpawnPosEvent and the usage of them, which is the primary means of spawn control. (I won't cover how to decide where to do the spawning, as it depends on things like game modes, maps and server settings...etc and it probably is for another post.)
While bz_ePlayerSpawnEvent, bz_getSpawnPointWithin() and bz_killPlayer() are capable of affecting spawns, they aren't covered, as they are more of a subset related to spawn effects vs actual spawn control. (bz_getSpawnPointWithin() is a bit of a particular case, as it requires zones and is more map/game specific and is not directly related to the concept of spawn control itself.)
BZFS spawning may be controlled via the events, as bz_eGetPlayerSpawnPosEvent is the sole method of doing so, however it lacks awareness of the world the tank is spawning in. This may be seen in the *Airspawn* plug-in which can possibly spawn tanks into buildings or objects as stated in the official readme.
For controlling the spawns, I don't recommend strictly hard-code anything. See the code below for getting a spawn position for a player and saving its values.
Code: Select all
float spawningPos[3]={0.0, 0.0, 0.0};
float rotation=0.0;
float *spawningRot;
spawningRot = &rotation;
bz_getStandardSpawn(player, spawningPos, spawningRot);
Code: Select all
spawnPosData->handled = true;
spawnPosData->pos[0]= spawningPos[0];
spawnPosData->pos[1]= spawningPos[1];
spawnPosData->pos[2]= spawningPos[2];
spawnPosData->rot = rotation;
There's a simple trick to have a smarter spawn system. Just a few simple loops and an API function, specifically bz_getStandardSpawn to make it work.
What you really want is to reach spawn conditions, and looping is probably one of the easiest ways of doing it.
You might get something which can look like the following code:
Code: Select all
// spawnMatched isn't strictly needed and may be omitted.
// however it is useful for various utility and debug aspects of a plug-in.
bool spawnMatched = false;
for(;;) {
bz_getStandardSpawn();
if (Spawn matched conditional) {
spawnMatched=true;
break;
}
}
Which is a pretty basic thing to do.
But if you want something a bit more complex, you can try to see if it matches one of many conditionals and you might end up with something like the following:
Code: Select all
bool spawnMatched = false;
for(;;) {
bz_getStandardSpawn();
for (i=0; i<= (spawnOptions-1); i++) {
if (spawn matches conditions) {
spawnMatched=true;
break;
}
}
if (spawnMatched) {
break;
}
}
Just be sure to have some sanity checks for spawning and not to create indefinite loops. (Limiting to a few hundred/thousand loops can help, but note that the loops need to increase the smaller/more specific of a location you want players to spawn in.)
And that's basically it for the most part.
Questions, comments, suggestions?
-Zehra