SA-MP Forums Archive
Detecting if palyer is in range of multiple objects - 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: Detecting if palyer is in range of multiple objects (/showthread.php?tid=481488)



Detecting if palyer is in range of multiple objects - Petricko - 15.12.2013

When I try to detect range of several objects can not I do not know why ... Every time says that I am to far from the object, and when I stand beside object... Can someone help me ...?
Thanks in advance ...
ps. Sorry for bad english...
pawn Код:
new Object[6];
   
    Object[0] = CreateObject(19076, 536.09997558594, -2232.8999023438, 4.6999998092651, 0, 0, 0,900.0);
    Object[1] = CreateObject(694, -2122.1000976563, -1448.5999755859, 201.69999694824, 0, 0, 236.08520507813,900.0);
    Object[2] = CreateObject(3830, 467.70001220703, -2207.6000976563, 9.1000003814697, 0, 0, 218,900.0);
    Object[3] = CreateObject(3886, 524.3994140625, -2159.69921875, -0.10000000149012, 0, 0, 309.99572753906,900.0);
    Object[4] = CreateObject(3886, 527.3994140625, -2157.099609375, -0.10999999940395, 0, 0, 309.99572753906,900.0);
    Object[5] = CreateObject(3599, 490, -2223.2998046875, 7.0999999046326, 0, 0, 151.99584960938,900.0);
   
    if (strcmp("/test", cmdtext, true, 10) == 0)
    {
        for(new i = 0;i<5;i++)
        {
            GetObjectPos(Object[i], ox, oy, oz);
            if(IsPlayerInRangeOfPoint(playerid, 5, ox, oy, oz))
            {
                SendClientMessage(playerid, -1, "You are close to the object.");
                return 1;
            }
            else
            {
                SendClientMessage(playerid, -1, "You are to far from the object.");
                return 1;
            }
        }
        return 1;
    }



Re: Detecting if palyer is in range of multiple objects - dakata994 - 15.12.2013

Try This.
Код:
new Object[6];
    
    Object[0] = CreateObject(19076, 536.09997558594, -2232.8999023438, 4.6999998092651, 0, 0, 0,900.0);
    Object[1] = CreateObject(694, -2122.1000976563, -1448.5999755859, 201.69999694824, 0, 0, 236.08520507813,900.0);
    Object[2] = CreateObject(3830, 467.70001220703, -2207.6000976563, 9.1000003814697, 0, 0, 218,900.0);
    Object[3] = CreateObject(3886, 524.3994140625, -2159.69921875, -0.10000000149012, 0, 0, 309.99572753906,900.0);
    Object[4] = CreateObject(3886, 527.3994140625, -2157.099609375, -0.10999999940395, 0, 0, 309.99572753906,900.0);
    Object[5] = CreateObject(3599, 490, -2223.2998046875, 7.0999999046326, 0, 0, 151.99584960938,900.0);
    
    if (strcmp("/test", cmdtext, true, 10) == 0)
    {
        for(new i = 0;i<5;i++)
        {
            GetObjectPos(Object[i], ox, oy, oz);
            if(IsPlayerInRangeOfPoint(playerid, i, ox, oy, oz))
            {
                SendClientMessage(playerid, -1, "You are close to the object.");
                return 1;
            }
            else
            {
                SendClientMessage(playerid, -1, "You are to far from the object.");
                return 1;
            }
        }
        return 1;
    }



Re: Detecting if palyer is in range of multiple objects - Vince - 15.12.2013

Did you calculate in the size of the object? If your object is 12 meters wide, you can still be standing right beside it but the code won't work.


Re: Detecting if palyer is in range of multiple objects - Petricko - 15.12.2013

This is object, small but it will not detect it. I have 6 object like this...



Re: Detecting if palyer is in range of multiple objects - Mitchy - 15.12.2013

pawn Код:
new Object[6];
   
    Object[0] = CreateObject(19076, 536.09997558594, -2232.8999023438, 4.6999998092651, 0, 0, 0,900.0);
    Object[1] = CreateObject(694, -2122.1000976563, -1448.5999755859, 201.69999694824, 0, 0, 236.08520507813,900.0);
    Object[2] = CreateObject(3830, 467.70001220703, -2207.6000976563, 9.1000003814697, 0, 0, 218,900.0);
    Object[3] = CreateObject(3886, 524.3994140625, -2159.69921875, -0.10000000149012, 0, 0, 309.99572753906,900.0);
    Object[4] = CreateObject(3886, 527.3994140625, -2157.099609375, -0.10999999940395, 0, 0, 309.99572753906,900.0);
    Object[5] = CreateObject(3599, 490, -2223.2998046875, 7.0999999046326, 0, 0, 151.99584960938,900.0);
   
    if (strcmp("/test", cmdtext, true, 10) == 0)
    {
        for(new i = 0;i<5;i++)
        {
            GetObjectPos(Object[i], ox, oy, oz);
            if(IsPlayerInRangeOfPoint(playerid, 2.0, ox, oy, oz))
            {
                SendClientMessage(playerid, -1, "You are close to the object.");
                return 1;
            }
            else if(IsPlayerInRangeofPoint(playerid, 8.0, ox, oy, oz))
            {
                SendClientMessage(playerid, -1, "You are to far from the object.");
                return 1;
            }
        }
        return 1;
    }
Dont know if thats what your looking for but shouldn't something like that work?..

EDIT: changed the ranges, noticed i did them wrong


Re: Detecting if palyer is in range of multiple objects - Jefff - 15.12.2013

pawn Код:
new Object[2];

Object[0] = CreateObject(19076, 536.09997558594, -2232.8999023438, 4.6999998092651, 0, 0, 0,900.0);
CreateObject(694, -2122.1000976563, -1448.5999755859, 201.69999694824, 0, 0, 236.08520507813,900.0);
CreateObject(3830, 467.70001220703, -2207.6000976563, 9.1000003814697, 0, 0, 218,900.0);
CreateObject(3886, 524.3994140625, -2159.69921875, -0.10000000149012, 0, 0, 309.99572753906,900.0);
CreateObject(3886, 527.3994140625, -2157.099609375, -0.10999999940395, 0, 0, 309.99572753906,900.0);
Object[1] = CreateObject(3599, 490, -2223.2998046875, 7.0999999046326, 0, 0, 151.99584960938,900.0);


if(strcmp(cmdtext, "/test", true) == 0)
{
    new bool:IsInRange;

    for(new objectid = Object[0]; objectid < Object[1]+1; objectid++)
    {
        GetObjectPos(objectid, ox, oy, oz);
        if(IsPlayerInRangeOfPoint(playerid, Range_Here, ox, oy, oz))
        {
            IsInRange = true;
            break;
        }
    }

    if(IsInRange)
        SendClientMessage(playerid, -1, "You are close to the object.");
    else
        SendClientMessage(playerid, -1, "You are to far from the object.");

    return 1;
}



Re: Detecting if palyer is in range of multiple objects - cessil - 16.12.2013

the problem is that you're returning 1 no matter what, so it checks the first object in the array and then doesn't check any others

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5, ox, oy, oz))
            {
                SendClientMessage(playerid, -1, "You are close to the object.");
                return 1;//stops script here, doesn't check any other objects
            }
            else
            {
                SendClientMessage(playerid, -1, "You are to far from the object.");
                return 1;//stops script here, doesn't check any other objects
            }