Load random spawns from ini?
#1

Hello, I would like to know how could I load various spawns from an .ini, without having to specify each X,Y,Z

For example something like this:
Код:
	{1096.9132,2680.9060,12.1853,164.2388},
	{1096.5936,2679.1206,12.1629,169.8319},
	{1096.0532,2676.1050,12.1251,169.8319},
Thanks in advance.
Reply
#2

You could use something like this, however it does not use any file...
pawn Код:
new Float:RandSpawnPoint[][3] =
{
    {1022.7762, -1136.0763, 23.5679},   // W. Vinewood (1)
    {2655.3247, -1671.9651, 10.7122},   // LA Arena (2)
    {1168.6312, -1819.6385, 13.4021},   // Bus station (3)
    {1246.2170,-2036.4877,59.6518}      // Government House (4)
};
and then in OnPlayerSpawn

pawn Код:
OnPlayerSpawn(playerid)
{
    new rand = random(3);
    SetPlayerPos(playerid, RandSpawnPoint[rand][0], RandSpawnPoint[rand][1], RandSpawnPoint[rand][2]);
}
That would spawn them at the random x,y,z specified above.
Reply
#3

Quote:
Originally Posted by Jacksta21
Посмотреть сообщение
You could use something like this, however it does not use any file...
pawn Код:
new Float:RandSpawnPoint[][3] =
{
    {1022.7762, -1136.0763, 23.5679},   // W. Vinewood (1)
    {2655.3247, -1671.9651, 10.7122},   // LA Arena (2)
    {1168.6312, -1819.6385, 13.4021},   // Bus station (3)
    {1246.2170,-2036.4877,59.6518}      // Government House (4)
};
and then in OnPlayerSpawn

pawn Код:
OnPlayerSpawn(playerid)
{
    new rand = random(3);
    SetPlayerPos(playerid, RandSpawnPoint[rand][0], RandSpawnPoint[rand][1], RandSpawnPoint[rand][2]);
}
That would spawn them at the random x,y,z specified above.
I know how to do that, what I want to do is put the positions in an .ini and load them OnPlayerSpawn or just on the gm.
Reply
#4

What I provided does exactly that, and is (probably?) faster than opening and then reading a file into the server.
Why is the .ini file needed when there is a simpler way?
Reply
#5

Quote:
Originally Posted by Jacksta21
Посмотреть сообщение
What I provided does exactly that, and is (probably?) faster than opening and then reading a file into the server.
Why is the .ini file needed when there is a simpler way?
Because I'll have various .ini files, and all of them will have different random spawns.
Reply
#6

Show example files
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Show example files
Why? What I want is like a function or an example to load various floats, someone told me it could be done with sscanf but I don't know how.

This?
Код:
{949.8915,2685.2961,10.8203,255.4671},
{943.4811,2686.7908,10.8203,256.1251},
{938.1342,2687.9041,10.8203,256.1251},
{947.5636,2678.0840,10.8203,262.0472},
{938.7642,2678.1858,10.8203,251.0257},
{944.9770,2667.5320,10.8203,246.7486},
{940.6622,2667.4146,10.8203,246.4196},
{934.8538,2669.0117,11.2036,246.4196}
Reply
#8

there is example in samp folder .... its grandlarc or something it includes vehicles from file and house/biz checkpoints from scriptfiles\properties

gl_common.inc
Reply
#9

Well like this
pawn Код:
#define MAX_POS 20


new Float:sx[MAX_POS],Float:sy[MAX_POS],Float:sz[MAX_POS],Float:sang[MAX_POS],posloaded=0;


public OnGameModeInit()
{
new Float:x,Float:y,Float:z,Float:ang,read[100],i;
i=0;
new File:fi=fopen("SavePos.txt",io_read);
while(fread(fi,read))
{
sscanf(read,"p<,>ffff",x,y,z,ang);
sx[i]=x;
sy[i]=y;
sz[i]=z;
sang[i]=ang;
i++;
posloaded++;//this varaible must be sued in random function at time of spawn
}
fclose(fi);
return 1;
}




CMD:savepos(playerid,params[])//to save position
{
new Float:x,Float:y,Float:z,Float:ang,write[100];
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,ang);
format(write,100,"%1f,%1f,%1f,%1f",x,y,z,ang);
new File:Fi=fopen("SavePos.txt",io_append);//assuming the file to save pos is SavePos.txt
fwrite(Fi,write);
fwrite(Fi,"\n");
fclose(Fi);
return 1;
}
now make use of random() function to take out a random pos and then spawn player
NOTE:CREATE a file named as "SavePos.txt" in scriptfiles folder before loading

I have systems to load and save like this using y_ini but that is very difficult to understand[a little complex] so gave u an easy to understand one
Reply
#10

You all are not getting what I'm talking about, I'll try to explain a little better.

Ok, so I have two teams and a GameMode with map system (Kitten's base GM), that means a new map will load every certain time, now, everything loads as it should, everything is working fine, but for each team there is only one spawn, so all players of the same team spawn on the same spot (which causes bugs sometimes), it looks like this:
Код:
Team1X = -55
Team1Y = -334.89999389648
Team1Z = 7.999998092651
Team2X = -41.299999237061
Team2Y = -224.10000610352
Team2Z = 6.5999999046326
Now, what I want is instead of all those X,Y,Z, is to put random spawns on each .ini and load them. Something like this(could be different, maybe every X on a line, Y on a line, and so on):
Код:
Team1 = 
949.8915,2685.2961,10.8203,255.4671
943.4811,2686.7908,10.8203,256.1251
938.1342,2687.9041,10.8203,256.1251
947.5636,2678.0840,10.8203,262.0472
938.7642,2678.1858,10.8203,251.0257
944.9770,2667.5320,10.8203,246.7486
940.6622,2667.4146,10.8203,246.4196
934.8538,2669.0117,11.2036,246.4196

Team2 = 
947.5636,2678.0840,10.8203,262.0472
938.7642,2678.1858,10.8203,251.0257
944.9770,2667.5320,10.8203,246.7486
940.6622,2667.4146,10.8203,246.4196
934.8538,2669.0117,11.2036,246.4196
I'm currently loading each X,Y,Z like this:
pawn Код:
if(strcmp(name, "Team1X", true) == 0) Map[Team1X] = floatstr(value);
        if(strcmp(name, "Team1Y", true) == 0) Map[Team1Y] = floatstr(value);
        if(strcmp(name, "Team1Z", true) == 0) Map[Team1Z] = floatstr(value);
        if(strcmp(name, "Team2X", true) == 0) Map[Team2X] = floatstr(value);
        if(strcmp(name, "Team2Y", true) == 0) Map[Team2Y] = floatstr(value);
        if(strcmp(name, "Team2Z", true) == 0) Map[Team2Z] = floatstr(value);
And using that on OnPlayerSpawn like this:
pawn Код:
SetPlayerPos(playerid,Map[Team1X],Map[Team1Y],Map[Team1Z]);
But what I want is to load all spawns, and use them random OnPlayerSpawn. Any idea? Thanks to everyone that has helped so far

@Ihateyou: I already took a look into that, but that won't work because its used as an include not a file loaded.
@BroZeus: hmm.. I think that's different
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)