21.06.2011, 18:12
Hello, im using Incognito Streamer and I wanted to know of a way to get the closest dynamicobject to a player, is this possible? Thanks.
for(new i=0;i<MAX_DYNAMIC_OBJECTS;i++)
{
new Float:oX, Float:oY, Float:oZ;
GetDynamicObjectPos(oX, oY, oZ);
if(IsPlayerInRangeOfPoint(playerid, oX, oY, oZ))
{
//Do the things
break;
}
continue;
}
native Streamer_VisibleItems(type, items);
stock GetClosestDynamicObject(playerid)
{
new Float:px,Float:py,Float:pz,
Float:ox,Float:oy,Float:oz,Float:dist,result = 12345;
GetPlayerPos(playerid,px,py,pz);
for(new o; o < CountDynamicObjects(); o++)
{
GetDynamicObjectPos(o,ox,oy,oz);
dist = floatsqroot(floatpower(floatabs(floatsub(px,ox)),2)+floatpower(floatabs(floatsub(py,oy)),2)+floatpower(floatabs(floatsub(pz,oz)),2));
if(dist < result)
{
result = dist;
return o;
}
}
return 1;
}
Try this.
pawn Code:
|
Is there a way to add the object id? So like GetClosestDynamicObject(playerid, objectid); or something? So that way I can find out which object is the closest.
|
new objectid = GetClosestDynamicObject(playerid);