Save floats to array? [REP]
#1

Hey guys,
i load some spawns with sscanf.
Loading works fine.
I printed and all coordinates are there.
Now i want use this coordinates as random spawns.
But how?
I dont know how to do this now.
Hope for help.

Load code:
Код:
else if(!sscanf(loadstr1, "p<\">'spawnpoint''vehicle='d'posX='f'posY='f'posZ='f'rotX='f'rotY='f'rotZ='f",mapValues1[pMmodelids1], mapValues1[pMXs1], mapValues1[pMYs1], mapValues1[pMZs1], mapValues1[pMRXs1], mapValues1[pMRYs1], mapValues1[pMRZs1])){
CreateRaceSpawn1(mapValues1[pMmodelids1], mapValues1[pMXs1], mapValues1[pMYs1], mapValues1[pMZs1], mapValues1[pMRZs1]);
printf("%f %f %f", mapValues1[pMXs1], mapValues1[pMYs1], mapValues1[pMZs1]);
++count;
Reply
#2

Store the coordinates in the array "aRandomSpawns" and do as followed:

pawn Код:
// ** INCLUDES

#include <a_samp>

// ** DEFINES

// *** GENERAL

#define MAX_POSITIONS 100

// ** ARRAYS AND ENUMERATORS

enum eRandomSpawns
{
    Float:random_spawn_x,
    Float:random_spawn_y,
    Float:random_spawn_z,
    Float:random_spawn_angle
};

new aRandomSpawns[MAX_POSITIONS][eRandomSpawns];

// ** MAIN

main()
{
    print("Loaded \"random_spawns.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new selected = random(sizeof(aRandomSpawns));
    SetPlayerPos(playerid, aRandomSpawns[selected][random_spawn_x], aRandomSpawns[selected][random_spawn_y], aRandomSpawns[selected][random_spawn_z]);
    SetPlayerFacingAngle(playerid, aRandomSpawns[selected][random_spawn_angle]);
    SetCameraBehindPlayer(playerid);
    return 1;
}
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Store the coordinates in the array "aRandomSpawns" and do as followed:

pawn Код:
// ** INCLUDES

#include <a_samp>

// ** ARRAYS AND ENUMERATORS

enum eRandomSpawns
{
    Float:random_spawn_x,
    Float:random_spawn_y,
    Float:random_spawn_z,
    Float:random_spawn_angle
};

new aRandomSpawns[][eRandomSpawns];

// ** MAIN

main()
{
    print("Loaded \"random_spawns.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new selected = random(sizeof(aRandomSpawns));
    SetPlayerPos(playerid, aRandomSpawns[selected][random_spawn_x], aRandomSpawns[selected][random_spawn_y], aRandomSpawns[selected][random_spawn_z]);
    SetPlayerFacingAngle(playerid, aRandomSpawns[selected][random_spawn_angle]);
    SetCameraBehindPlayer(playerid);
    return 1;
}
Ty but i store like this now:
aRandomSpawns[random_spawn_x] = mapValues1[pMXs1];

But i got an error.
array sizes do not match, or destination array is too small
Reply
#4

Quote:
Originally Posted by TobsenMTA
Посмотреть сообщение
Ty but i store like this now:
aRandomSpawns[random_spawn_x] = mapValues1[pMXs1];

But i got an error.
array sizes do not match, or destination array is too small
That's not how you store it in to that array...

Example:
pawn Код:
for(new i = 0; i < MAX_POSITIONS; i ++)
{
    aRandomSpawns[i][random_spawn_x] = x;
}
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
That's not how you store it in to that array...

Example:
pawn Код:
for(new i = 0; i < MAX_POSITIONS; i ++)
{
    aRandomSpawns[i][random_spawn_x] = x;
}
Thank you.
I used a other way than this because this is not optimized enought.

btw: i needed to make it like this: new aRandomSpawns[MAX_RANDOMSPAWNS][eRandomSpawns];

Thank you anyways!
Reply
#6

Quote:
Originally Posted by TobsenMTA
Посмотреть сообщение
Thank you.
I used a other way than this because this is not optimized enought.

btw: i needed to make it like this: new aRandomSpawns[MAX_RANDOMSPAWNS][eRandomSpawns];

Thank you anyways!
Ha! Yeah right. I doubt your "method" is more optimized. The answer is simple, it can't be more optimized (in general terms).

P.S. I edited the thread by adding "MAX_POSITIONS" to the script before your last reply.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)