Spawn Manipulation Guide

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
User avatar
Zehra
Private First Class
Private First Class
Posts: 914
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

Spawn Manipulation Guide

Post by Zehra »

Alright, here is how to do spawn manipulation/modification.

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);
And we now a have spawn position we can use with the bz_eGetPlayerSpawnPosEvent event, with the following code:

Code: Select all

spawnPosData->handled = true;
spawnPosData->pos[0]= spawningPos[0];
spawnPosData->pos[1]= spawningPos[1];
spawnPosData->pos[2]= spawningPos[2];
spawnPosData->rot   = rotation;
We just got a spawn position and used it, but it's basically the same as doing nothing and having no plug-in loaded.

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;
    }
}
(Note: Above can't be used as is.)

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;
    }
}
(Note: Above can't be used as is.)

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
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Post Reply