17.08.2016, 15:35
This is the code to check if the player is near you or not. - ( Explaination is in the code. Which is commented)
So how GetPlayerDistanceFromPlayer works is -
GetPlayerDistanceFromPlayer(playerid, targetid) < (Tiles distance)
The target id in the above case was id or else it can be anything you want. ed- issuerid, damagedid, etc. Tiles distance can be anything you want. 5.0, 10.0, 20.0 etc.
Код:
CMD:near(playerid, parmas[]) { new id, idName[MAX_PLAYER_NAME], String[128], String2[128]; GetPlayerName(id, idName, sizeof(idName)); //Getting the name of the id you are going to input. if(sscanf(parmas, "u", id)) return SendClientMessage(playerid, -1, "Usage - /near [id]"); // if id is missing, it will show player message to type in the id. if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "Player not connected!"); if(id == playerid) return SendClientMessage(playerid, -1, "You can not enter your own id!"); if(GetPlayerDistanceFromPlayer(playerid, id) < 10.0) // If the player is in reach of the player in 10 tiles then it will show the message below. { format(String, sizeof(String), "%s is near you!", idName); SendClientMessage(playerid, -1, String); } else // else it will show this. { format(String2, sizeof(String2), "%s is not near you!", idName); SendClientMessage(playerid, -1, String2); } return 1; }
GetPlayerDistanceFromPlayer(playerid, targetid) < (Tiles distance)
The target id in the above case was id or else it can be anything you want. ed- issuerid, damagedid, etc. Tiles distance can be anything you want. 5.0, 10.0, 20.0 etc.