[Include] Get Nearest
#1

Introduction
Get Nearest is a small library which get's the nearest object, player, vehicle and dynamic object.







Features

  • Object
  • Player
  • Vehicle
  • Dynamic Object









Installation

  • Download the file.
  • Copy it on your includes directory.
  • Include it on your script using this.
    pawn Code:
    #include <getnearest>











How to use

You can use it like this.

pawn Code:
#include <a_samp>
#include <others/streamer>
#include <others/getnearest>

new Text:SomeTd;
new str[64];

public OnFilterScriptInit()
{
    InitTextDraw();
    return 1;
}

stock InitTextDraw()
{
    SomeTd = TextDrawCreate(44 ,286 , "Object: N/A");
    TextDrawFont(SomeTd , 1);
    TextDrawLetterSize(SomeTd , 0.8, 5.6000000000000005);
    TextDrawColor(SomeTd , 0xa84343FF);
    TextDrawSetOutline(SomeTd , false);
    TextDrawSetProportional(SomeTd , true);
    TextDrawSetShadow(SomeTd , 1);
}

public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid, SomeTd);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    new nearobj = GetNearest(playerid, OBJECT, 1000.0);
    if(nearobj)
    {
        format(str, sizeof(str), "Object: %d", nearobj);
        TextDrawSetString(SomeTd, str);
    }
    return 1;
}








Documentation

pawn Code:
GetNearest(playerid, type, distance);

/*
playerid: The id of the playerid whom you want to get the nearest of.
type: OBJECT | PLAYER | VEHICLE | DYNAMIC_OBJECT.
distance: The highest distance to check.

Returns: Returns the thing's id and if not exist on the distance, returns -1.
*/









Change Log
Code:
v1.1
++
Optimized Script(Thanks to wups and Lorenc for some tips).
Added Distance as parameter(argument).
Fixed Static Object Bug(Forgot to get the correct object coordinates).

v1.0
++
Initial Release







Download

v1.1 Pastebin.
v1.0 Pastebin.
Reply


Messages In This Thread
Get Nearest - by T0pAz - 27.02.2012, 16:44
Re: Get Nearest - by tyler12 - 27.02.2012, 16:45
Re: Get Nearest - by Konstantinos - 27.02.2012, 16:46
Re: Get Nearest - by T0pAz - 27.02.2012, 16:48
Re: Get Nearest - by rati555 - 27.02.2012, 17:03
Re: Get Nearest - by TheArcher - 27.02.2012, 17:08
Re: Get Nearest - by T0pAz - 27.02.2012, 17:11
Re: Get Nearest - by asteroid - 27.02.2012, 17:13
AW: Get Nearest - by kvn - 27.02.2012, 17:16
Re: Get Nearest - by wups - 27.02.2012, 17:55
Re: Get Nearest - by ang12123 - 27.02.2012, 17:56
Re: Get Nearest - by Lorenc_ - 27.02.2012, 19:18
Re: Get Nearest - by T0pAz - 28.02.2012, 07:35
Re: Get Nearest - by Niko_boy - 28.02.2012, 07:38
Respuesta: Get Nearest - by [Nikk] - 28.02.2012, 07:42
Re: Get Nearest - by Not Applicable - 28.02.2012, 07:56
Re: Get Nearest - by [HK]Ryder[AN] - 28.02.2012, 13:09
Re: Get Nearest - by wups - 28.02.2012, 14:40
Re: Get Nearest - by T0pAz - 28.02.2012, 14:53
Re: Get Nearest - by RyDeR` - 28.02.2012, 15:03
Re: Get Nearest - by T0pAz - 28.02.2012, 15:25
Re: Get Nearest - by wups - 28.02.2012, 16:40
Re: Get Nearest - by T0pAz - 28.02.2012, 16:54

Forum Jump:


Users browsing this thread: 1 Guest(s)