Spawns
#1



I'm trying to make a spawning system, where when all players spawn, they're set to the circles as indicated above.

Each of the 9 points are different locations, but I want it where when all players connect, player 1 is set to circle one, the next player set to circle 2, the next player to circle 3 and so and so. How would I go about achieving this?
Reply
#2

How about number 10?

You could (if you only have 9 competitors) create spawning coordinates in an array and then assign the playerid to the coordinate on array[playerid]. Of course, this could go on with more IDs as well
Reply
#3

Create an enum that holds Float values for the spawn coordinates, and a boolean that is set to true when the spawn becomes occupied and false when it's not. Then declare a two-dimensional array with that enum, the first dimension being 9 and the second dimension being the enum.

As for making them spawn points, I'd suggest creating a function with a loop that finds the first available spawn coords from the array, skipping spawn points that have their boolean set to true. Once the first available spawn coordinates are found, set the boolean for those spawn coords to true. Teleport that player to those coordinates. Then call that function under OnPlayerSpawn. You could also try using SetSpawnInfo, which looks a little smoother, but the method above would have to work differently. Don't forget to set the boolean to false at some point (once the player dies, for example).

Here's an example of how you could approach this:
pawn Код:
enum E_SPAWN_DATA
{
    Float:e_spawnX,
    Float:e_spawnY,
    Float:e_spawnZ,
    bool:e_isOccupied
    // note that these values are constants; you can't set default values in enums!
}

new gSpawnCoords[9][E_SPAWN_DATA];

stock SetPlayerSpawn(playerid)
{
    // Loop through array
    for (new i = 0; i < sizeof(gSpawnCoords); i++) {
        // check if gSpawnCoords[i][e_isOccupied] is true
        // if true continue
        // if false, teleport player to spawn coords of index i, set isOccupied to true, and return/break
    }
}

public OnGameModeInit()
{
    // Set default values of isOccupied to false and your spawn coord data here
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerSpawn(playerid);
    return 1;
}
Reply
#4

Thank you, that helped me with a lot of things!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)