IsPlayerNear...
#1

Hi,

i want to find out whether a player is near a specific object.
I searched and found this code:

Код:
#define IsPlayerNear(%1,%2,%3,%4) \
{ \
 new Float:Pos[6], i; \
 GetPlayerPos(%2, Pos[0], Pos[1], Pos[2]); \
 %4(%3, Pos[3], Pos[4], Pos[5]); \
 for(i = 0; i < 3; i++) Pos[i] = floatsub(Pos[i + 3], Pos[i]); \
 if (%1 > Pos[0] > -%1) && \
 (%1 > Pos[1] > -%1) && \
 (%1 > Pos[2] > -%1) ) return 1; \
 return 0; \
}
stock IsPlayerNearPlayer(Float:radi, playerid, otherplayerid) IsPlayerNear(radi, playerid, otherplayerid, GetPlayerPos)
stock IsPlayerNearObject(Float:radi, playerid, objectid) IsPlayerNear(radi, playerid, objectid, GetObjectPos)
stock IsPlayerNearVehicle(Float:radi, playerid, vehicleid) IsPlayerNear(radi, playerid, vehicleid, GetVehiclePos)
This is the code under OnPlayerUpdate:

Код:
if(IsPlayerNearObject(5,playerid,carramp))
{
    	SendClientMessage(playerid,0xC30000FF,"Test");
}
But there are some problems:

(17535) : error 029: invalid expression, assumed zero
(17535) : warning 215: expression has no effect
(17535) : error 001: expected token: ";", but found ")"
(17535) : error 029: invalid expression, assumed zero
(17535) : fatal error 107: too many error messages on one line

17353 is this line: stock IsPlayerNearObject(Float:radi, playerid, objectid) IsPlayerNear(radi, playerid, objectid, GetObjectPos)

Hope you can help me
Reply
#2

Try this
pawn Код:
stock IsPlayerNearObject(Float:radi, playerid, objectid)
{
    new Float:Pos[3];
    GetObjectPos(objectid,Pos[0],Pos[1],Pos[2]);
    if(GetPlayerDistanceFromPoint(playerid,Pos[0],Pos[1],Pos[2]) <= radi)
        return 1;
    return 0;
}
stock IsPlayerNearPlayer(Float:radi, playerid, playerid2)
{
    new Float:Pos[3];
    GetPlayerPos(playerid2,Pos[0],Pos[1],Pos[2]);
    if(GetPlayerDistanceFromPoint(playerid,Pos[0],Pos[1],Pos[2]) <= radi)
        return 1;
    return 0;
}
stock IsPlayerNearVehicle(Float:radi, playerid,vehicleid)
{
    new Float:Pos[3];
    GetVehiclePos(vehicleid,Pos[0],Pos[1],Pos[2]);
    if(GetPlayerDistanceFromPoint(playerid,Pos[0],Pos[1],Pos[2]) <= radi)
        return 1;
    return 0;
}
Reply
#3

Work, thank you
Reply
#4

Is there also a public like

public IsObjectNearPlayer(objectid,playerid)
{

}

or how i can create it?
Reply
#5

Use GetObjectPos and IsPlayerInRangeOfPoint

pawn Код:
stock IsPlayerNearVehicle(Float:radi, playerid,vehicleid)
{
    new Float:Pos[3];
    GetObjectPos(vehicleid,Pos[0],Pos[1],Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid,radi, Pos[0],Pos[1],Pos[2])) return 1;
    return 0;
}
Reply
#6

But how to create a public wich is called every 500 milliseconds or something.
Like OnPlayerUpdate or OnObjectMoved.

This publice should check whether an object is near a player.
Not the player should check if the object is near him.

Tim
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)