Save floats to array? [REP] -
TobsenMTA - 17.12.2015
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;
Re: Save floats to array? [REP] -
SickAttack - 17.12.2015
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;
}
Re: Save floats to array? [REP] -
TobsenMTA - 17.12.2015
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
Re: Save floats to array? [REP] -
SickAttack - 17.12.2015
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;
}
Re: Save floats to array? [REP] -
TobsenMTA - 18.12.2015
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!
Re: Save floats to array? [REP] -
SickAttack - 18.12.2015
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.