Detecting if palyer is in range of multiple objects
#1

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;
    }
Reply
#2

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;
    }
Reply
#3

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.
Reply
#4

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

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
Reply
#6

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;
}
Reply
#7

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
            }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)