17.12.2011, 08:14
Hey guys, i made a script to add a player in a file each time he get /invite and remove it from the file each time get uninvite, but i have a problem: when a new player is added i want it to be added in a new line, but he is added in the first line, so i can't remove it at /uninvite.Now the file look like this: http://s8.postimage.org/wvgcny4ad/Untitled.png but i want look like this: http://s11.postimage.org/effplc2cj/Untitled.png. Please help
tesst = how many lines i have
SaveCate = save the number of the line in a new file
LoadCate = load the number of the file
I made this filescript to show leader how many members he have
The command for leader is:
pawn Код:
new tesst;
enum cMemb
{
cNume[255],
cFactiune
};
new MembInfo[10001][cMemb];
public OnGameModeInit() // Do not add vehicles Above the next lines. - CuervO
{
LoadCate();
LoadMembers();
return 1;
}
forward LoadCate();
public LoadCate()
{
new file[64];
format(file, sizeof(file),"LARP/cate.ini")
if(dini_Exists(file))
{
tesst = dini_Int(file,"cate");
}
printf("[SCRIPT]: Loaded Cate %d", tesst);
return 1;
}
forward SaveCate();
public SaveCate()
{
new string3[64];
format(string3, sizeof(string3), "LARP/cate.ini");
dini_IntSet(string3, "cate",tesst);
return 1;
}
forward RemoveMembers(string[]);
public RemoveMembers(string[])
{
tesst--;
if(tesst <= 0)
{
tesst = 0;
}
for(new i=0;i<=tesst;i++)
{
if(strcmp(MembInfo[i][cNume], string, true) == 0)
{
strmid(MembInfo[i][cNume], MembInfo[tesst][cNume], 0, strlen(string), 255);
strmid(MembInfo[tesst][cNume], "", 0, strlen(string), 255);
MembInfo[i][cFactiune] = MembInfo[tesst][cFactiune];
MembInfo[tesst][cFactiune] = 0;
}
}
SaveCate();
SaveMembers();
return 1;
}
forward AddMembers(faction, string[]);
public AddMembers(faction, string[])
{
strmid(MembInfo[tesst][cNume], string, 0, strlen(string), 255);
MembInfo[tesst][cFactiune] = faction;
tesst++;
SaveCate();
SaveMembers();
return 1;
}
forward SaveMembers();
public SaveMembers()
{
new idx;
new File: file2;
while (idx < tesst)
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%s|%d\n",
MembInfo[idx][cNume],
MembInfo[idx][cFactiune]);
if(idx == 0)
{
file2 = fopen("members.cfg", io_write);
}
else
{
file2 = fopen("members.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
}
forward LoadMembers();
public LoadMembers()
{
print("done");
new arrCoords[20][64];
new strFromFile2[256];
new File: file = fopen("members.cfg", io_read);
print("done2");
if (file)
{
new idx;
while (idx < tesst)
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
strmid(MembInfo[idx][cNume], arrCoords[0], 0, strlen(arrCoords[0]), 255);
MembInfo[idx][cFactiune] = strval(arrCoords[1]);
printf("%s si fac %d",MembInfo[idx][cNume], MembInfo[idx][cFactiune]);
idx++;
}
fclose(file);
}
}
// this i have in /invite: AddMembers(PlayerInfo[playerid][pLeader], giveplayer);
//this i have in /uninvite: RemoveMembers(giveplayer);
SaveCate = save the number of the line in a new file
LoadCate = load the number of the file
I made this filescript to show leader how many members he have
The command for leader is:
pawn Код:
if(strcmp(cmd, "/allmembers", true) == 0)
{
if(PlayerInfo[playerid][pLeader] == 0) { return SendClientMessage(playerid, COLOR_LIGHTRED, "Tu nu esti lider !");}
SendClientMessage(playerid, COLOR_WHITE, "Playeri factiuni:");
for(new i = 0;i<tesst; i++)
{
if(PlayerInfo[playerid][pLeader] == MembInfo[i][cFactiune])
{
format(string, sizeof(string), "%s", MembInfo[i][cNume]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
}
return 1;
}