Enum Random Spawn
#1

I want to make random spawns using enum with ids.

Example
Code:
enum dsinfo
{
   id,
   Float:X,
   Float:Y,
   Float:Z,
};

new ds[][dsinfo] =
{
    {1, x, y, z},
    {1, x, y, z},
    {1, x, y, z},

    {2, x, y, z},
    {2, x, y, z},
};
Each id has a specific number of spawn coordinates.

If a player join ds ID 1 , the player should be spawned in any of those 3 coordinates. If Id 2, player should be spawned any of those 2 coordinates
Reply
#2

If you never modify `ds` during run-time, you can choose randomly from 0-2 (exclusive) for ds ID 1 or from 3-4 (exclusive) for ds ID 2.

Having them separated them will let you use random with `sizeof` operator.
Reply
#3

Code:
GetSpawnPosFromID(id){
    new dsid[],count;
    for(new i,j=sizeof(ds); i < j; i++)
    {
        if(ds[i][0]==id){
            dsid[count++]=i;
        }
    }
    return dsid[random(count)];
}
new rand=GetSpawnPosFromID(1);
SetPlayerPos(playerid, ds[rand][X], ds[rand][Y], ds[rand][Z]);
Will this work? I got this somewhere around this forum.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)