Read from file -
[XST]O_x - 15.05.2010
Hello.
Listen guys i tried to make two commands that allows you to save your position by using /s and then load it by using /l.
Here is what I've done:
pawn Код:
if(strcmp(cmdtext, "/s", true) == 0)
{
new File:Pos=fopen("Pos.txt",io_write);
new Float:x, Float:y, Float:z;
new string[256];
GetPlayerPos(playerid,x,y,z);
format(string,256,"%f,%f,%f",x,y,z);
fwrite(Pos, string);
fclose(Pos);
return 1;
}
And the /l :
pawn Код:
if(strcmp(cmdtext, "/l", true) == 0)
{
new File:Pos=fopen("Pos.txt",io_read);
new string[256];
SetPlayerPos(playerid,x,y,z);
fread(Pos,string);
fclose(Pos);
return 1;
}
I know the /l is totally messed up and it's not working >:
But the /s is working,it creates a file with the positions in it, i just don't know how to read it.
Anyone help please?
Thanks in advance.
Re: Read from file -
Backwardsman97 - 15.05.2010
This will work if you have only written one line to the file.
pawn Код:
if(!strcmp(cmdtext,"/l",true))
{
new
File:Pos=fopen("Pos.txt",io_read),pos[2],
string[256],holder[128],Float:x,Float:y,Float:z;
fread(Pos,string);
pos[0] = strfind(string,",");
pos[1] = strfind(string,",",true,pos[0]+1);
strmid(holder,string,0,pos[0]);
x = floatstr(holder);
strmid(holder,string,pos[0]+1,pos[1]);
y = floatstr(holder);
strmid(holder,string,pos[1]+1,strlen(string));
z = floatstr(holder);
SetPlayerPos(playerid,x,y,z);
fclose(Pos);
return 1;
}
It's a bit more complicated then the one you posted. :P
Re: Read from file -
[XST]O_x - 15.05.2010
Quote:
|
Originally Posted by Baked-Banana
This will work if you have only written one line to the file.
pawn Код:
if(!strcmp(cmdtext,"/l",true)) { new File:Pos=fopen("Pos.txt",io_read),pos[2], string[256],holder[128],Float:x,Float:y,Float:z;
fread(Pos,string);
pos[0] = strfind(string,","); pos[1] = strfind(string,",",true,pos[0]+1);
strmid(holder,string,0,pos[0]); x = floatstr(holder);
strmid(holder,string,pos[0]+1,pos[1]); y = floatstr(holder);
strmid(holder,string,pos[1]+1,strlen(string)); z = floatstr(holder);
SetPlayerPos(playerid,x,y,z); fclose(Pos); return 1; }
It's a bit more complicated then the one you posted. :P
|
HOLY MAMA,back to the wiki

anyway thx

Oh and btw,i have another question.
Is there any way to make /l work only if /s was already typed?
I mean like if you type /l before /s it will send a message "Save a position first." or smth?
thx
Re: Read from file -
Backwardsman97 - 15.05.2010
pawn Код:
if(!strcmp(cmdtext,"/l",true))
{
new
File:Pos=fopen("Pos.txt",io_read),pos[2],
string[256],holder[128],Float:x,Float:y,Float:z;
fread(Pos,string);
if(!strlen(string))
{
//There's nothing in the file
return 1;
}
pos[0] = strfind(string,",");
pos[1] = strfind(string,",",true,pos[0]+1);
strmid(holder,string,0,pos[0]);
x = floatstr(holder);
strmid(holder,string,pos[0]+1,pos[1]);
y = floatstr(holder);
strmid(holder,string,pos[1]+1,strlen(string));
z = floatstr(holder);
SetPlayerPos(playerid,x,y,z);
fclose(Pos);
return 1;
}
Re: Read from file -
[XST]O_x - 15.05.2010
Thanks a lot dude,it's working

just a question,was it easy for you to make? :P
Re: Read from file -
Backwardsman97 - 15.05.2010
Quote:
|
Originally Posted by O_x
Thanks a lot dude,it's working 
just a question,was it easy for you to make? :P
|
Sort of. It's just a trial and error sort of thing. I made a file with some coordinates in it and kept editing and running this script until it showed the right thing.
Re: Read from file -
playbox12 - 15.05.2010
Easier way
Warning: untested
pawn Код:
new Float:PlayerPos[MAX_PLAYERS][6];
new Float:TeleportDest[MAX_PLAYERS][3];
new Float:TelePos[MAX_PLAYERS][6];
if(strcmp(cmd, "/s", true) == 0)
{
if(IsPlayerConnected(playerid))
{
GetPlayerPos(playerid, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]);
SendClientMessage(playerid, COLOR_GRAD1, "Position set use /l to load it");
return 1;
}
if(strcmp(cmd, "/l", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if (GetPlayerState(playerid) == 2)
{
new tmpcar = GetPlayerVehicleID(playerid);
SetVehiclePos(tmpcar, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]);
TelePos[playerid][0] = 0.0;TelePos[playerid][1] = 0.0;
}
else
{
SetPlayerPos(playerid, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]);
}
SetPlayerInterior(playerid,0);
SetPlayerVirtualWorld(playerid,0);
return 1;
}
Re: Read from file -
[XST]O_x - 15.05.2010
Quote:
|
Originally Posted by playbox12
Easier way Warning: untested
pawn Код:
new Float:PlayerPos[MAX_PLAYERS][6]; new Float:TeleportDest[MAX_PLAYERS][3]; new Float:TelePos[MAX_PLAYERS][6];
if(strcmp(cmd, "/s", true) == 0) { if(IsPlayerConnected(playerid)) { GetPlayerPos(playerid, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]); SendClientMessage(playerid, COLOR_GRAD1, "Position set use /l to load it"); return 1; }
if(strcmp(cmd, "/l", true) == 0) { if(IsPlayerConnected(playerid)) { if (GetPlayerState(playerid) == 2) { new tmpcar = GetPlayerVehicleID(playerid); SetVehiclePos(tmpcar, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]); TelePos[playerid][0] = 0.0;TelePos[playerid][1] = 0.0; } else { SetPlayerPos(playerid, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]); } SetPlayerInterior(playerid,0); SetPlayerVirtualWorld(playerid,0); return 1; }
|
thank you too