23.12.2014, 03:45
I need to make the command to detect the closest player when the params aren't used, I tried this but it doesn't work.
Thanks,
NeTSk8.
Код:
CMD:rob(playerid, params[]) { if(sscanf(params, "U", params[0])) return SendClientMessage(playerid, ERROR, "Usage: /rob [player/id]"); if(params[0] == INVALID_PLAYER_ID) params[0] = GetClosestPlayerToPlayer(playerid); if(GetDistanceBetweenPlayers(playerid, params[0]) >= 9) return SendClientMessage(playerid, ERROR, "No player is close to you."); else { if(IsPlayerSpawned(playerid)) { if(gTeam[playerid] == CIVILIAN) { if(params[0] != playerid) { if(!IsPlayerInAnyVehicle(playerid)) { if(!IsPlayerInAnyVehicle(params[0])) { if(IsPlayerConnected(params[0])) { if(GetPlayerMoney(params[0] > 0)) { if(GetDistanceBetweenPlayers(playerid, params[0]) <= 8) { if(RecentlyRobbed[params[0]] == 0) { if(GetPlayerMoney(params[0]) >= 4999) { new string[250], string2[250], string3[250], robbedcash; robbedcash = random(GetPlayerMoney(params[0])/2); format(string, sizeof(string), "You have robbed $%d from %s[ID:%d]", robbedcash, PlayerName(params[0]), params[0]); SendClientMessage(playerid, ERROR, string); format(string2, sizeof(string2), "%s[ID:%d] has robbed $%d from you!", PlayerName(playerid), playerid, robbedcash); SendClientMessage(params[0], ERROR, string2); format(string3, sizeof(string3), "[HQ] %s has robbed $%d from %s.", PlayerName(playerid), PlayerName(params[0]), robbedcash); SendRadioMessageToCops(string3); GivePlayerMoney(playerid, robbedcash); GivePlayerMoney(params[0], -robbedcash); RecentlyRobbed[params[0]] = 60; GivePlayerScore(playerid, 1); if(gTeam[params[0]] == CIVILIAN) { SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 2); } if(gTeam[params[0]] == COP || gTeam[params[0]] == SWAT || gTeam[params[0]] == FBI || gTeam[params[0]] == ARMY || gTeam[params[0]] == Medic) { SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5); } SetPlayerRobbingSkill(playerid, GetPlayerRobbingSkill(playerid)+1); return true; } else if(GetPlayerMoney(params[0]) < 4999) { new string[250]; format(string, sizeof(string), "%s[ID:%d] doesn't have enough money.", PlayerName(params[0]), params[0]); return SendClientMessage(playerid, ERROR, string); } } else if(RecentlyRobbed[params[0]] > 0) { new string[250]; format(string, sizeof(string), "%s[ID:%d] has been robbed recently. Try again later.", PlayerName(params[0]), params[0]); return SendClientMessage(playerid, ERROR, string); } else { new string[250]; format(string, sizeof(string), "%s[ID:%d] is too far away.", PlayerName(params[0]), params[0]); return SendClientMessage(playerid, ERROR, string); } } else if(GetPlayerMoney(params[0]) == 0) { new string[250]; format(string, sizeof(string), "%s[ID:%d] does not have any money.", PlayerName(params[0]), params[0]); return SendClientMessage(playerid, ERROR, string); } } } else if(!IsPlayerConnected(params[0])) { new string[250]; format(string, sizeof(string), "ID %d is not connected.", params[0]); return SendClientMessage(playerid, ERROR, string); } } else if(IsPlayerInAnyVehicle(params[0])) { new string[250]; format(string, sizeof(string), "%s[ID:%d] is in a vehicle. You cannot rob him.", PlayerName(params[0]), params[0]); return SendClientMessage(playerid, ERROR, string); } } else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "You cannot rob anyone from inside a vehicle."); } else return SendClientMessage(playerid, ERROR, "You cannot rob yourself."); } else return SendClientMessage(playerid, ERROR, "Only CIVILIANS can use this command!"); } } return 1; }
NeTSk8.