SA-MP Forums Archive
Enum Random Spawn - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Enum Random Spawn (/showthread.php?tid=674415)



Enum Random Spawn - SiaReyes - 19.04.2020

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


Re: Enum Random Spawn - Calisthenics - 19.04.2020

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.


Re: Enum Random Spawn - SiaReyes - 20.04.2020

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.