02.02.2012, 08:34
Here you go. Try this.
If you want dynamic, let me know.
pawn Код:
#include <a_samp>
#define FILTERSCRIPT
#define COLOR_DARKGREEN 0x006400FF
#define COLOR_DARKORANGE 0xFF8C00FF
new Text:Title[MAX_PLAYERS];
new Text:Object[MAX_PLAYERS];
new str[64];
public OnFilterScriptInit()
{
print("=====================================");
print(" Nearest Object Initialized! ");
print(" By: TopAz(FeaR) ");
print("=====================================");
return 1;
}
public OnFilterScriptExit()
{
print("=====================================");
print(" Nearest Object Unloaded! ");
print(" By: TopAz(FeaR) ");
print("=====================================");
return 1;
}
public OnPlayerConnect(playerid)
{
//Title
Title[playerid] = TextDrawCreate(511 ,107 , "~g~~h~~h~Nearest Object:");
TextDrawColor(Title[playerid], COLOR_DARKGREEN);
TextDrawLetterSize(Title[playerid], 0.4, 2.8000000000000003);
TextDrawFont(Title[playerid], 1);
TextDrawSetProportional(Title[playerid], true);
TextDrawHideForPlayer(playerid, Title[playerid]);
//Nearest Object
Object[playerid] = TextDrawCreate(510 ,127 , "~r~N/A");
TextDrawColor(Object[playerid], COLOR_DARKORANGE);
TextDrawLetterSize(Object[playerid], 0.4, 2.8000000000000003);
TextDrawFont(Object[playerid], 1);
TextDrawSetProportional(Object[playerid] , true);
TextDrawHideForPlayer(playerid, Object[playerid]);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
TextDrawDestroy(Title[playerid]);
TextDrawDestroy(Object[playerid]);
}
public OnPlayerUpdate(playerid)
{
format(str, sizeof(str), "~y~%f", GetNearestObject(playerid));
TextDrawSetString(Object[playerid], str);
return 1;
}
stock GetNearestObject(playerid)
{
new Float:px, Float:py, Float:pz;
new currentobject = -1, Float:distance = -1;
GetPlayerPos(playerid, px, py, pz);
for(new index = 0; index < MAX_OBJECTS; index++)
{
if(!IsValidObject(index))
continue;
new Float:ox, Float:oy, Float:oz;
GetObjectPos(index, ox, oy, oz);
new Float:odist = floatsqroot
(
floatpower(floatabs(floatsub(ox, px )), 2.0) +
floatpower(floatabs(floatsub(oy, py )), 2.0) +
floatpower(floatabs(floatsub(oz, pz )), 2.0)
);
if(currentobject == -1)
{
currentobject = index;
distance = odist;
}
else if(odist < distance)
{
currentobject = index;
distance = odist;
}
}
return currentobject;
}