get an object near the player + position of it not working...
#1

hey all,

ok so i made this cmd:

pawn Код:
CMD:getobject(playerid, params[])
{
    new Float:px,Float:py,Float:pz,
    Float:ox,Float:oy,Float:oz,
    Float:orx, Float:ory, Float:orz;
    GetPlayerPos(playerid,px,py,pz);
    for(new o = 0; o < 1000; o++) // 1000 is the max object limit
    {
        GetObjectPos(o,ox,oy,oz);
        GetObjectRot(o, orx, ory, orz);
        if(IsPlayerNearObject(playerid, o, 3.0))
        {
            new string[128];
            format(string, sizeof(string), "Object id: %d, X: %f, Y: %f, Z: %f, Rx: %f, Ry: %f, Rz: %f", o, ox, oy, oz, orx, ory, orz);
            SendClientMessage(playerid, COLOR_ORANGE, string);
            print(string);
            SaveIn("ChatLog", string);
            break;
        }
        else SendClientMessage(playerid, COLOR_RED, "You ain't near any object");
    }
    return 1;
}
stock:

pawn Код:
stock IsPlayerNearObject(playerid, objectid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetObjectPos(objectid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
    return false;
}

but it doesn't send ANY message at all...

what am i doing wrong? and no i don't wanna use the streamer for this, because i need to get the NORMAL INTERIOR objects near the player, when he is for example standing on a couch in a random interior, and i do /getobject, it should say which object id it is, the x y z etc, but it doesnt...

anyone knows whats wrong with the above?

Greets
Reply
#2

Are u sure that the cmd is getting called ?
cuz if it dosent show any message at all, then the command is not getting executed, try tracing the code to find whether the cmd is getting called or not
also this code will show "You ain't near any object" 1000 times if u are not near any object, this code is correct
pawn Код:
CMD:getobject(playerid, params[])
{
    new Float:px,Float:py,Float:pz,
    Float:ox,Float:oy,Float:oz,
    Float:orx, Float:ory, Float:orz;
    GetPlayerPos(playerid,px,py,pz);
    new bool:found = false;
    for(new o = 0; o < 1000; o++) // 1000 is the max object limit
    {
        GetObjectPos(o,ox,oy,oz);
        GetObjectRot(o, orx, ory, orz);
        if(IsPlayerNearObject(playerid, o, 3.0))
        {
            new string[128];
            format(string, sizeof(string), "Object id: %d, X: %f, Y: %f, Z: %f, Rx: %f, Ry: %f, Rz: %f", o, ox, oy, oz, orx, ory, orz);
            SendClientMessage(playerid, COLOR_ORANGE, string);
            print(string);
            SaveIn("ChatLog", string);
            found = true;
            break;
        }
    }
    if(!found) SendClientMessage(playerid, COLOR_RED, "You ain't near any object");
    return 1;
}
Also this code wont show the nearest object to the player, it'll simply show the first object in that range (by ID)
Reply
#3

aww, but how to get the object id from it than?
Reply
#4

If u need the nearest object id, then u'll need a variable to store the minimum distance found between all the objects and an ID variable too to store its id
Reply
#5

what do you mean? i didn't really get what you said...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)