stock Float:GetPlayerDistanceFromPlayer(playerid, targetid) { new Float:fDist[3]; GetPlayerPos(playerid, fDist[0], fDist[1], fDist[2]); return GetPlayerDistanceFromPoint(targetid, fDist[0], fDist[1], fDist[2]); }
Here you go with the stock.
Код:
stock Float:GetPlayerDistanceFromPlayer(playerid, targetid) { new Float:fDist[3]; GetPlayerPos(playerid, fDist[0], fDist[1], fDist[2]); return GetPlayerDistanceFromPoint(targetid, fDist[0], fDist[1], fDist[2]); } if(GetPlayerDistanceFromPlayer(playerid, id) < 5.0) { //your code } |
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; }
This is the code to check if the player is near you or not. - ( Explaination is in the code. Which is commented)
Код:
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(GetPlayerDistanceFromPlay(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. |
if(GetPlayerDistanceFromPlay(playerid, id) < 10.0)
Correct that. |
This is the code to check if the player is near you or not. - ( Explaination is in the code. Which is commented)
Код:
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. |
CMD:heal(playerid, params[]) { new healerName[MAX_PLAYER_NAME]; new Float:healedHealth; new id, idName[MAX_PLAYER_NAME], forHealer[128], forHealed[128]; if (playerid == id) { return SendClientMessage(playerid, COLOR_RED, "Error: you cannot heal your self"); } if (GetPlayerDistanceFromPlayer(playerid, id) < 10.0) { if (gTeam[playerid] == gTeam[id]) { GetPlayerHealth(id, healedHealth); if (healedHealth > 99.00) { return SendClientMessage(playerid, 0xF00000, "Player you want to heal hasalready max health"); } else { healedHealth = 100.00; GetPlayerName(playerid, healerName, sizeof(healerName)); format(forHealed, 128, "You are healed by %s",healerName); SendClientMessage(id, 0xF00000, forHealed); GetPlayerName(id, idName, sizeof(idName)); format(forHealer, 128, "You healed", idName); } } } return 1; }
CMD:heal(playerid, params[])
{
new id;
if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_RED, "Error: USAGE: heal id");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "Error: player is not connected");
if(playerid == id) return SendClientMessage(playerid, COLOR_RED, "Error: you cannot heal your self");
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if(!IsPlayerInRangeOfPoint(id, 10, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "Error: player must be near you");
if(gTeam[playerid] != gTeam[id]) return SendClientMessage(playerid, COLOR_RED, "Error: you can't heal enemies");
new Float:healedHealth;
GetPlayerHealth(id, healedHealth);
if(healedHealth > 99.00) return SendClientMessage(playerid, 0xF00000, "Player you want to heal hasalready max health");
SetPlayerHealth(id, 100);
new healerName[MAX_PLAYER_NAME],idName[MAX_PLAYER_NAME],forHealer[128],forHealed[128];
GetPlayerName(playerid, healerName, sizeof(healerName));
format(forHealed, 128, "You are healed by %s",healerName);
SendClientMessage(id, 0xF00000, forHealed);
GetPlayerName(id, idName, sizeof(idName));
format(forHealer, 128, "You healed", idName);
SendClientMessage(playerid, 0xF00000, forHealer);
return 1;
}
I reworked this code for you, it even more readable, without any stock
PHP код:
|