19.08.2016, 21:45
You gave me a cancer with all those if's.....
Also try renaming one of strings (in cmd or stock) to string1.
PHP код:
CMD:phchange(playerid, params[])
{
new string[128], number, File:file = fopen("cellphones.cfg", io_read), fdeleteline(("cellphones.cfg", idx[]));
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(!PlayerInfo[playerid][pHasCellphone]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a cellphone yet.");
if(!IsPlayerInRangeOfPoint(playerid, 2, 1228.9281,-737.9149,1088.6360)) return SendClientMessage(playerid, COLOR_GREY, "You are not at the cityhall.");
if(sscanf(params, "i", number)) return SendClientMessage(playerid, COLOR_WHITE, "[Usage]: /phchange [desired number]");
if(number < -1 || number > 99999999999) return SendClientMessage(playerid, COLOR_GREY, "Your number can't be low than 100 and more than 99999999999");
if(PlayerInfo[playerid][pNumber] == number) return SendClientMessage(playerid, COLOR_GREY, "You already have this phone number.");
new idx = 1;
while(fread(file, string))
{
if(strval(string) == number) return SendClientMessage(playerid, COLOR_GREY, "This number is already registered.");
if(strval(string) == PlayerInfo[playerid][pNumber])
{
fdeleteline("cellphones.cfg", idx);
}
idx ++;
return 1;
}
fclose(file);
file = fopen("cellphones.cfg", io_append);
format(string, sizeof(string), "%d\r\n", number);
fwrite(file, string);
fclose(file);
if(!PlayerInfo[playerid][pNumber])
{
SendClientMessage(playerid, COLOR_WHITE, " You have changed your Phone Number for free as it's the first time.");
}
else
{
GiveDodMoney(playerid, PlayerInfo[playerid][pLevel] * -1200);
TaxMoney += 500;
format(string, sizeof(string), " You've changed your number and you've been charged $%d.", PlayerInfo[playerid][pLevel] * -1200);
SendClientMessage(playerid, COLOR_WHITE, string);
}
PlayerInfo[playerid][pNumber] = number;
return 1;
}