Data is not OverWriting -
rockhopper - 02.03.2015
PHP код:
CMD:oban(playerid,params[])
{
new targetname[24];
new Name[MAX_PLAYER_NAME];
new Msg[128];
new file[100], File:PFile, str1[100] , str2[100];
if (APlayerData[playerid][LoggedIn] == true)
{
// Check if the player's admin-level is at least 3
if (APlayerData[playerid][PlayerLevel] >= 3)
{
if(sscanf(params, "s[24]", targetname)) return SendClientMessage(playerid, -1, "Correct Usage: /oban [Player's Name]");
else
{
// Get the name of the admin
GetPlayerName(playerid, Name, sizeof(Name));
// Construct the complete filename for this player's account
format(file, sizeof(file), PlayerFile, targetname);
// Check if the file exists
if (fexist(file))
{
PFile = fopen(file, io_append); // Open the playerfile for appending (this command only appends a new line to overwrite the bantime)
format(str1, 100, "BanTime 2147483640\r\n");// Construct the line: "BanTime <0>"
format(str2,100,"Bans 5\r\n");
fwrite(PFile, str2);
fwrite(PFile, str1); // And save it to the file
fclose(PFile); // Close the file
format(Msg, 128, "%s %s has offline-banned %s", AdminLevelName[APlayerData[playerid][PlayerLevel]], Name, targetname);
SendClientMessageToAll(0x808080FF, Msg);
}
else
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}There is no account with that playername");
}
}
}
return 1;
}
This is the CMD I made . It doesn't give me erros but when I try it Instead of replacing the Variables in the player files it makes one more for example :-
PHP код:
Data1
Data2
Ban
BanTime
Data5
Data6
Ban//This gets created again instead of overwriting the above vars
Bantime//
How do I fix this ?
Re: Data is not OverWriting -
-=Dar[K]Lord=- - 02.03.2015
https://sampwiki.blast.hk/wiki/File_Functions
What you have to do is first delete the line and re append the data you need.
Check out the wiki.
AW: Data is not OverWriting -
Nero_3D - 02.03.2015
You used io_append, that will only append the data and not overwrite it
You need to copy the complete file into memory or a tmp file, see
ftemp() (it is opened in io_readwrite)
After you copied everything into the tmp file, you read line for line and copy the data back into the main file
If it hits "Ban" or "BanTime" than you add your new lines instead of the old
Edit: you can also do it like darklord said than you don't need a tmp file
Re: Data is not OverWriting -
rockhopper - 02.03.2015
Please Give me Example can't really understand Plus How do I delete the 2 lines of Ban / Bantime ?
Re: Data is not OverWriting -
rockhopper - 02.03.2015
Anyone please ? I need it urgently ?
Re: Data is not OverWriting -
Vince - 02.03.2015
If you don't understand it then don't try to write your own user system. There are a number of good file function includes, the most famous one probably being Y_Ini.
Re: Data is not OverWriting -
rockhopper - 02.03.2015
IK I used Y_INI Before I just want this .. cuz the script that I am using uses its own system so please can you tell it to me ?
Re : Data is not OverWriting -
Nero_3D - 02.03.2015
We could provide something like that but you could also use ******
http://lmgtfy.com/?q=freplaceline+si...orum.sa-mp.com
Re: Data is not OverWriting -
rockhopper - 02.03.2015
Okay After Googling I found a stock by FireCat And I am using it Stock is
PHP код:
fRemoveLine(file[],line[])//By: Firecat
{
new string[256],
File:Temp = fopen("Temp.ini",io_append),
File:Main = fopen(file,io_read);
while(fread(Main,string))
{
if(strcmp(string,line) != 0)
{
fwrite(Temp,string);
}
}
fclose(Main);
fclose(Temp);
fremove(file);
Main = fopen(file, io_append);
Temp = fopen("Temp.ini",io_read);
while(fread(Temp,string))
{
fwrite(Main,string);
}
fclose(Main);
fclose(Temp);
fremove("Temp.ini");
return 1;
}
But when I use it in the following way
PHP код:
fRemoveLine(PFile,"Bans");
fRemoveLine(PFile,"BanTime");
I get the following error
PHP код:
error 035: argument type mismatch (argument 1)
error 035: argument type mismatch (argument 1)
AW: Data is not OverWriting -
Nero_3D - 02.03.2015
The first parameter is the filename not the handle
Also I am not sure if strcmp will find only the part of the string, if it doesn't work edit it to that
pawn Код:
fRemoveLine(file[],line[])//By: Firecat
{
new string[256],
len = strlen(line), // added
File:Temp = fopen("Temp.ini",io_append),
File:Main = fopen(file,io_read);
while(fread(Main,string))
{
if(strcmp(string,line,false,len) != 0) // changed
{
fwrite(Temp,string);
}
}
// rest stays the same