28.11.2011, 16:58
So, I have been trying to make a dynamic /setspawn command. I have done the same with an /addvehicle command where I enter a vehicle and type /addvehicle, and then they get added to the script via a file placed in the scriptfiles. Unfortunately I can not find the problem in my /setspawn command.
It is supposed to work like this: You type /setspawn, it saves the coordinates in a file and when you relog you spawn at the position where the coordinates are. But somehow it don not load the coordinates correctly. This is my code:
The entire command:
Function:
Token_by_delim function:
It is supposed to work like this: You type /setspawn, it saves the coordinates in a file and when you relog you spawn at the position where the coordinates are. But somehow it don not load the coordinates correctly. This is my code:
pawn Код:
public OnPlayerSpawn(playerid)
{
LoadSpawnPosition("EQRP/Server/Spawnpos.ini");
return 1;
}
The entire command:
pawn Код:
if(strcmp(cmd, "/setspawn", true) == 0)
{
if(PlayerInfo[playerid][pLogged] == 1)
{
if(PlayerInfo[playerid][pAdmin] >= 1337)
{
new File:SpawnPos = fopen("EQRP/Server/Spawnpos.ini", io_append);
if(SpawnPos)
{
new Float: X, Float: Y, Float: Z, Float: A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
format(string, sizeof(string), "Player Spawn has been changed to: [%f], [%f], [%f], [%f]", X, Y, Z, A);
SendClientMessage(playerid, COLOR_ADMIN, string);
format(string, sizeof(string), "%f, %f, %f, %f", X, Y, Z, A);
fwrite(SpawnPos, string);
}
fclose(SpawnPos);
}
else SendClientMessage(playerid, COLOR_LIGHTRED, "[Error]: {FFFFFF} You are not allowed to use that command!");
}
else SendClientMessage(playerid, COLOR_LIGHTRED, "[Error]: {FFFFFF} You are not logged in!");
return 1;
Function:
pawn Код:
stock LoadSpawnPosition(const filename[])
{
new File:file_ptr;
new line[256];
new var_from_line[64];
new Float:SpawnX;
new Float:SpawnY;
new Float:SpawnZ;
new Float:SpawnA;
new index;
file_ptr = fopen(filename,filemode:io_read);
if(!file_ptr) return 0;
while(fread(file_ptr,line,256) > 0)
{
index = 0;
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnX = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnY = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnZ = floatstr(var_from_line);
index = token_by_delim(line,var_from_line,',',index+1);
if(index == (-1)) continue;
SpawnA = floatstr(var_from_line);
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerPos(i, SpawnX, SpawnY, SpawnZ);
SetPlayerFacingAngle(i, SpawnA);
}
}
fclose(file_ptr);
return 1;
}
pawn Код:
stock token_by_delim(const string[], return_str[], delim, start_index)
{
new x=0;
while(string[start_index] != EOS && string[start_index] != delim) {
return_str[x] = string[start_index];
x++;
start_index++;
}
return_str[x] = EOS;
if(string[start_index] == EOS) start_index = (-1);
return start_index;
}