SA-MP Forums Archive
Object Models - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Object Models (/showthread.php?tid=315203)



Object Models - Chris White - 02.02.2012

While I was playing on my server, I found that there was an object that I didn't expect to find it in that place. So I've tried to edit my GM, but didn't find the code that generates that object. So can someone tell me how to get an object's model ID while in game? here's a screen shot for that object:




Re: Object Models - Chris White - 02.02.2012

bump. you can meet me IG to help me.


Re: Object Models - T0pAz - 02.02.2012

You can use TextDraw and use GetClosestObject stock to update the text of the closest object id. If anyone really needs it, I can create a filterscript.


Re: Object Models - Chris White - 02.02.2012

uh, I think you should. Thanks by the way.


Re: Object Models - T0pAz - 02.02.2012

Here you go. Try this.

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;
}
If you want dynamic, let me know.


Re: Object Models - Chris White - 02.02.2012

lol man. very nice. +rep for you for that work.


Re: Object Models - T0pAz - 02.02.2012

Here is the dynamic object version. Please don't pm me. Ask in the thread.

pawn Код:
#include <a_samp>
#include <streamer>

#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);
    TextDrawShowForPlayer(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);
    TextDrawShowForPlayer(playerid, Object[playerid]);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    TextDrawDestroy(Title[playerid]);
    TextDrawDestroy(Object[playerid]);
}

public OnPlayerUpdate(playerid)
{
    format(str, sizeof(str), "~y~%f", GetNearestDynamicObject(playerid));
    TextDrawSetString(Object[playerid], str);
    return 1;
}

stock GetNearestDynamicObject(playerid)
{
    new Float:px, Float:py, Float:pz;
    new currentobject = -1, Float:distance = -1;
    GetPlayerPos(playerid, px, py, pz);
    for(new index = 0; index < CountDynamicObjects(); index++)
    {
        if(!IsValidDynamicObject(index))
            continue;
        new Float:ox, Float:oy, Float:oz;
        GetDynamicObjectPos(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;
}



Re: Object Models - Chris White - 02.02.2012

still, it doesn't work.