SA-MP Forums Archive
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: Spawn (/showthread.php?tid=642327)



Spawn - JaKe Elite - 28.09.2017

PHP Code:
enum ENUM_GAME
{
    
gameID,
    
gameName[20],
    
gameType
};
enum ENUM_SPAWN
{
    
spawn_gameID,
    
spawn_gameTeam,
    
Float:spawn_X,
    
Float:spawn_Y,
    
Float:spawn_Z,
    
Float:spawn_A,
}
////////////////////////////////////////////////////////////////////////////////
new GameInfo[][ENUM_GAME] = {
    {
0"de_dust"GAME_BOMBING}
};
new 
SpawnInfo[][ENUM_SPAWN] =
{
    
// De_Dust
    
{0TEAM_TERRORIST7748.2246, -2561.867218.4057254.3921},
    {
0TEAM_TERRORIST7745.2607, -2572.027818.4135308.5993},
    {
0TEAM_TERRORIST7741.2280, -2566.790318.4135268.4923},
    {
0TEAM_TERRORIST7741.3320, -2558.592818.4081245.6188},
    {
0TEAM_COUNTER7692.6514, -2643.591118.4302270.4191},
    {
0TEAM_COUNTER7692.4092, -2656.409218.3768269.4791},
    {
0TEAM_COUNTER7701.4702, -2659.552018.3846311.1528},
    {
0TEAM_COUNTER7706.7485, -2653.481718.3768287.0259}
};
new 
game_id 0// de_dust
// OnGameModeInit
game_id random(sizeof(GameInfo)); 
So I have an array here, I would like to determine and set the players position according on the array. Like for EG, The map is de_dust and the only positions that will be randomized are those arrays/records which is set for that game only.

How can I do that?


Re: Spawn - jlalt - 28.09.2017

You can use a way where you define the kinds and add a parameter called kind in your ENUM_SPAWN,

example:
PHP Code:
#define TEAM_DUST 1
#define TEAM_... 2
... 
then
PHP Code:
enum ENUM_SPAWN 

    
spawn_KInD,
    
spawn_gameID
    
spawn_gameTeam
    
Float:spawn_X
    
Float:spawn_Y
    
Float:spawn_Z
    
Float:spawn_A

and later
PHP Code:
new SpawnInfo[][ENUM_SPAWN] = 

    
// De_Dust 
    
{TEAM_DUST0TEAM_TERRORIST7748.2246, -2561.867218.4057254.3921},
    ....
    {
TEAM_..., 0TEAM_TERRORIST7748.2246, -2561.867218.4057254.3921},
    ....
}; 
and later will be able to get spawn area kind by an if statement, ex:
PHP Code:
if(SpawnInfo[x][spawn_KInD] == TEAM_DUST// this spawn area belongs to dust!
{




Re: Spawn - JaKe Elite - 28.09.2017

Yeah, but the problem is how can I randomize a spawn point for a specific game depending it on the game_id variable?


Re: Spawn - Misiur - 28.09.2017

Something like
pawn Code:
new onlyCurrentGameSpawns[sizeof(SpawnInfo)], count;
for (new i = 0; i != sizeof SpawnInfo; ++i) {
  if (SpawnInfo[i][spawn_gameID] == gameid) {
    onlyCurrentGameSpawns[count++] = i;
  }
}

new index = onlyCurrentGameSpawns[random(count)];



Re: Spawn - JaKe Elite - 28.09.2017

Will try this out, thanks!


Re: Spawn - JaKe Elite - 28.09.2017

PHP Code:
stock Initiate_Spawn(playerid)
{
    new 
countindexonlyCurrentGameSpawns[sizeof(SpawnInfo)];
    
    for(new 
i!= sizeof(SpawnInfo); ++i)
    {
        if (
SpawnInfo[i][spawn_gameID] == game_id) {
            
onlyCurrentGameSpawns[count++] = i;
        }
    }
    
    
index onlyCurrentGameSpawns[random(count)];
    
    if(
gTeam[playerid] == TEAM_TERRORIST)
    {
        
SetPlayerPos(playeridSpawnInfo[index][spawn_X], SpawnInfo[index][spawn_Y], SpawnInfo[index][spawn_Z]);
        
SetPlayerFacingAngle(playeridSpawnInfo[index][spawn_A]);

        
/*foreach(new x : g_Terrorist)
        {
            SetPlayerMarkerForPlayer(playerid, x, 0xFF6347FF);
        }
        if(server_bomber == INVALID_PLAYER_ID && !IsPlayerConnected(server_bomber))
        {
            server_bomber = Iter_Random(g_Terrorist);
            ShowPlayerObjective(playerid, 0x33AA33FF, "You are chosen to handle the C4 Bomb.", 5000);
            printf("%s has been chosen to handle the C4 bomb.", GetName(server_bomber));
        }
        Server_AssignBomber();*/
    
}
    else
    {
        
SetPlayerPos(playeridSpawnInfo[index][spawn_X], SpawnInfo[index][spawn_Y], SpawnInfo[index][spawn_Z]);
        
SetPlayerFacingAngle(playeridSpawnInfo[index][spawn_A]);

        foreach(new 
g_Counter)
        {
            
SetPlayerMarkerForPlayer(playeridx0x00CCFFFF);
        }
    }
    return 
1;

Will this work?