SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/04/2020, 04:29 AM   #1
SiaReyes
Gangsta
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 618
Reputation: 57
Default Enum Random Spawn

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

Last edited by SiaReyes; 19/04/2020 at 06:38 AM.
SiaReyes is offline   Reply With Quote
Old 19/04/2020, 08:41 AM   #2
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,227
Reputation: 205
Default Re: Enum Random Spawn

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.
__________________
Calisthenics is offline   Reply With Quote
Old 20/04/2020, 03:02 AM   #3
SiaReyes
Gangsta
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 618
Reputation: 57
Default Re: Enum Random Spawn

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.
SiaReyes is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Objects and random spawn KayJ Scripting Help 11 01/12/2019 03:34 AM
Random spawn Micko123 Scripting Help 13 28/04/2016 06:18 PM
Random Enum? jeffery30162 Server Support 0 16/12/2014 09:39 PM
random enum values ? [mysql] Champ Scripting Help 0 08/08/2014 08:30 AM


All times are GMT. The time now is 06:05 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.