11.02.2008, 22:20
[color=red]Ok, i made this code.
What i want it to do is when i person types / commands [/saveh] Thier Name, coords(X, Y, Z), and Interior ID will be saved in a line in Playerh.txt
And then i want it to read the file everytime a player spawns and get that certain player to spawn to the coords and Interior that were saved under the players name in the file. When i tried to add this to my main script i got countless errors and warnings, i tried my best to solve as much as i can but i failed horribly.
Can anyone please look at this and tell me how i can get this working properly, i REALLY need someones help on this.
Here is is.
What i hae on top.
The functions
What i want it to do is when i person types / commands [/saveh] Thier Name, coords(X, Y, Z), and Interior ID will be saved in a line in Playerh.txt
And then i want it to read the file everytime a player spawns and get that certain player to spawn to the coords and Interior that were saved under the players name in the file. When i tried to add this to my main script i got countless errors and warnings, i tried my best to solve as much as i can but i failed horribly.
Can anyone please look at this and tell me how i can get this working properly, i REALLY need someones help on this.
Here is is.
What i hae on top.
Код:
new Xsave; new Ysave; new Zsave; new IntIDsave; #define FILE_NAME "Playerh.txt" // The name of the file new File:ghouse; // The file new string[256]; new pname[24]; new str[256]; public fcreate(filename[]) { if (fexist(filename)){return false;} new File:fhandle = fopen(filename,io_write); fclose(fhandle); return true; } public fdeleteline(filename[], line[]){ if(fexist(filename)){ new temp[256]; new File:fhandle = fopen(filename,io_read); fread(fhandle,temp,sizeof(temp),false); if(strfind(temp,line,true)==-1){return 0;} else{ fclose(fhandle); fremove(filename); for(new i=0;i<strlen(temp);i++){ new templine[256]; strmid(templine,temp,i,i+strlen(line)); if(equal(templine,line,true)){ strdel(temp,i,i+strlen(line)); fcreate(filename); fhandle = fopen(filename,io_write); fwrite(fhandle,temp); fclose(fhandle); return 1; } } } } return 0; }
Код:
SaveHouse(playerid, X, Y, Z) { new string[256]; new Float: pname, Float:X, Float:Z, Float:Y, Float:IntID; gstats=fopen(FILE_NAME, io_append); GetPlayerName(playerid, pname, 24); GetPlayerPos(playerid, X, Y, Z); GetPlayerInterior(playerid); format(str, 256, "Name: %s X:%d Y:%d Z:%d IntID:%d\n\r",pname, X, Y, Z, GetPlayerInterior(playerid)); if(!ghouse)// Our check { fcreate(FILE_NAME); } while(fread(ghouse, string)) { if(strcmp(string, pname, false, strlen(pname))==0) { // To check if the players name is in the file fdeleteline(FILE_NAME, string); // delete the line fwrite(ghouse, str); // write the string } else if(strcmp(string, pname, false, strlen(pname))!=0) { // Its NOT true fwrite(ghouse, str); } } fclose(ghouse); } ReadStats(playerid) { ghouse=fopen(FILE_NAME, io_read); GetPlayerName(playerid, pname, 24); while(fread(ghouse, string)) { if(strcmp(str, pname, false, strlen(pname))==0) { Xsave[playerid]=GetVal(1, str); Ysave[playerid]=GetVal(2, str); Zsave[playerid]=GetVal(3, str); IntIDsave[playerid]=GetVal(4, str); } } fclose(ghouse); } SetPlayerPos(playerid, Xsave[playerid], Ysave[playerid], Zsave[playerid]); SetPlayerInterior(playerid, IntIDsave[playerid]);