Seriously had enough of arrays now.
#1

I'm trying to make arrays for spawnpoints. The data is class > city > random > the 4 cells that contain x y z and angle.

The number of random spawns, however, can vary. I tried using sizeof() but I'm getting errors.

pawn Code:
new Float:cop_spawns[][][4] =
{
    { // Los Santos
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0}
    } // Los Santos
};


new city = 0;
new rand = random(sizeof(cop_spawns[city]));
SetPlayerPos(0, cop_spawns[city][rand][0], cop_spawns[city][rand][1], cop_spawns[city][rand][2]);
How am I meant to store this data without using 15 different fucking arrays? Seriously annoyed.

I have to stress this again: the number of random spawns will vary. Cops will have ~4 per city. Civilians will have 50+. Paramedics will have ~2.
Reply
#2

Why you don't use only two arrays on Float:cop_spawns
pawn Code:
new Float:cop_spawns[][4] =
{
    // Los Santos
    {0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0}
    // Los Santos
};
pawn Code:
new rand = random(sizeof(cop_spawns));
SetPlayerPos(/* playerid or whatever*/, cop_spawns[rand][0], cop_spawns[rand][1], cop_spawns[rand][2]);
And use city with another way. Let me think it.
Reply
#3

Read my post properly. I need it for cities too. I guess I could do

spawns_cop_LS
spawns_cop_LV
spawns_cop_SF
etc.

but I'd rather not :/
Reply
#4

I make something and I hope it works.
pawn Code:
new Float:cop_spawns[ 3 ][ ][ 4 ] =
{
    { // Los Santos
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0}
    }, // Los Santos
    { // San Fiero
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0}
    }, // San Fiero
    { // Las Venturas
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0}
    } // Las Venturas
};
And
pawn Code:
public OnPlayerSpawn( playerid )
{
    new cityrand = random( 3 );
    new rand = random( sizeof( cop_spawns ) );
    if( cityrand == 0 )
    {
        SetPlayerPos( playerid, cop_spawns[ cityrand ][ rand ][ 0 ], cop_spawns[ cityrand ][ rand ][ 1 ], cop_spawns[ cityrand ][ rand ][ 2 ] );
    }
    else if( cityrand == 1 )
    {
        SetPlayerPos( playerid, cop_spawns[ cityrand ][ rand ][ 0 ], cop_spawns[ cityrand ][ rand ][ 1 ], cop_spawns[ cityrand ][ rand ][ 2 ] );
    }
    else
    {
        SetPlayerPos( playerid, cop_spawns[ cityrand ][ rand ][ 0 ], cop_spawns[ cityrand ][ rand ][ 1 ], cop_spawns[ cityrand ][ rand ][ 2 ] );
    }
    return 1;
}
Or
pawn Code:
public OnPlayerSpawn( playerid )
{
    new cityrand = random( 3 );
    new rand = random( sizeof( cop_spawns ) );
    SetPlayerPos( playerid, cop_spawns[ cityrand ][ rand ][ 0 ], cop_spawns[ cityrand ][ rand ][ 1 ], cop_spawns[ cityrand ][ rand ][ 2 ] );
    return 1;
}
Reply
#5

I was contemplating that, but if I add a couple of cop skins, it'll mess the order up and I'll have to edit it. Any easy way around that? It doesn't really sound as simple as I want it, and I believe it'd become complicated.
Reply
#6

Yeah I know about NaN, good idea Y_Less. I could say like, assign 50 indicies per class, and only check up to NaN, so even if I only had 3 spawns in one part, it'd be like

pawn Code:
{x, y, z},
{x, y, z},
{x, y, z},
{NAN, NAN, NAN},
{NAN, NAN, NAN},
{NAN, NAN, NAN},
{NAN, NAN, NAN},
etc.
right?

And to check for NaN

Could you remind me how to check if a value is NaN? I recall it being if(value < 0 && value >= 0) or something. Can't seem to find it.
Reply
#7

Ah, that totally slipped my mind. Thanks. I'll try
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)