GetPlayerDistanceFromPlayer?
#1

I want to know how to GetPlayerDistanceFromPlayer.
Or how to use GetPlayerDistanceFromPoint to get the playerid of the player who is in RangeOfPlayer;
Reply
#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]);
}
Use this. Like,

if(GetPlayerDistanceFromPlayer(playerid, id) < 5.0)
{
//your code
}
Reply
#3

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
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]);
}
Use this. Like,

if(GetPlayerDistanceFromPlayer(playerid, id) < 5.0)
{
//your code
}
How to get playerid of player who is in that range.
Reply
#4

You who enter playerid whom check
Reply
#5

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;
}
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.
Reply
#6

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
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;
}
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.
if(GetPlayerDistanceFromPlay(playerid, id) < 10.0)

Correct that.
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
if(GetPlayerDistanceFromPlay(playerid, id) < 10.0)

Correct that.
Thanks for telling.
Reply
#8

Quote:
Originally Posted by DeeadPool
Посмотреть сообщение
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;
}
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: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;
}
The code has still a problem. Please help.
Reply
#9

I reworked this code for you, it even more readable, without any stock
PHP код:
CMD:heal(playeridparams[])
{
    new 
id;
    if(
sscanf(params"u"id)) return SendClientMessage(playeridCOLOR_RED"Error: USAGE: heal id");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playeridCOLOR_RED"Error: player is not connected");
    if(
playerid == id) return SendClientMessage(playeridCOLOR_RED"Error: you cannot heal your self");
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
    if(!
IsPlayerInRangeOfPoint(id10xyz)) return SendClientMessage(playeridCOLOR_RED"Error: player must be near you");
    if(
gTeam[playerid] != gTeam[id]) return SendClientMessage(playeridCOLOR_RED"Error: you can't heal enemies");
    new 
Float:healedHealth;
    
GetPlayerHealth(idhealedHealth);
    if(
healedHealth 99.00) return SendClientMessage(playerid0xF00000"Player you want to heal hasalready max health");
    
SetPlayerHealth(id100);
    new 
healerName[MAX_PLAYER_NAME],idName[MAX_PLAYER_NAME],forHealer[128],forHealed[128];
    
GetPlayerName(playeridhealerNamesizeof(healerName));
    
format(forHealed128"You are healed by %s",healerName);
    
SendClientMessage(id0xF00000forHealed);
    
GetPlayerName(ididNamesizeof(idName));
    
format(forHealer128"You healed"idName);
    
SendClientMessage(playerid0xF00000forHealer);
    return 
1;

Reply
#10

Quote:
Originally Posted by Shinja
Посмотреть сообщение
I reworked this code for you, it even more readable, without any stock
PHP код:
CMD:heal(playeridparams[])
{
    new 
id;
    if(
sscanf(params"u"id)) return SendClientMessage(playeridCOLOR_RED"Error: USAGE: heal id");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playeridCOLOR_RED"Error: player is not connected");
    if(
playerid == id) return SendClientMessage(playeridCOLOR_RED"Error: you cannot heal your self");
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
    if(!
IsPlayerInRangeOfPoint(id10xyz)) return SendClientMessage(playeridCOLOR_RED"Error: player must be near you");
    if(
gTeam[playerid] != gTeam[id]) return SendClientMessage(playeridCOLOR_RED"Error: you can't heal enemies");
    new 
Float:healedHealth;
    
GetPlayerHealth(idhealedHealth);
    if(
healedHealth 99.00) return SendClientMessage(playerid0xF00000"Player you want to heal hasalready max health");
    
SetPlayerHealth(id100);
    new 
healerName[MAX_PLAYER_NAME],idName[MAX_PLAYER_NAME],forHealer[128],forHealed[128];
    
GetPlayerName(playeridhealerNamesizeof(healerName));
    
format(forHealed128"You are healed by %s",healerName);
    
SendClientMessage(id0xF00000forHealed);
    
GetPlayerName(ididNamesizeof(idName));
    
format(forHealer128"You healed"idName);
    
SendClientMessage(playerid0xF00000forHealer);
    return 
1;

Thanks very much
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)