Getting the object pos ?
#1

Hello guys, again i'm making a job fs and right now i wanna make a stock fucktion that is gonna be something like this:
pawn Код:
stock IsPlayerNearGarbageContainer(playerid)
If you get my idea from now... i have the garbage containers like that:
pawn Код:
CTSGC[0] = CreateDynamicObject(1332,2407.8999023,-1986.5000000,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (1)
    CTSGC[2] = CreateDynamicObject(1332,2407.8999023,-1984.0000000,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (2)
    CTSGC[3] = CreateDynamicObject(1332,2419.6000977,-1772.6999512,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (3)
    CTSGC[4] = CreateDynamicObject(1332,2419.6000977,-1774.9000244,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (4)
    CTSGC[5] = CreateDynamicObject(1332,2486.0000000,-1926.5000000,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (5)
    CTSGC[6] = CreateDynamicObject(1332,2488.3000488,-1926.5000000,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (6)
    CTSGC[7] = CreateDynamicObject(1332,2720.1000977,-1943.3000488,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (7)
    CTSGC[8] = CreateDynamicObject(1332,2720.1000977,-1945.5000000,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (8)
    CTSGC[9] = CreateDynamicObject(1332,2642.1000977,-2004.8000488,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (9)
    CTSGC[10] = CreateDynamicObject(1332,2642.1000977,-2002.5000000,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (10)
    CTSGC[11] = CreateDynamicObject(1332,2367.1999512,-1742.5000000,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (11)
    CTSGC[12] = CreateDynamicObject(1332,2369.3999023,-1742.5000000,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (12)
    CTSGC[13] = CreateDynamicObject(1332,2242.3000488,-1742.9000244,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (13)
    CTSGC[14] = CreateDynamicObject(1332,2244.3000488,-1742.9000244,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (14)
    CTSGC[15] = CreateDynamicObject(1332,2187.1999512,-1658.3000488,15.1999998,0.0000000,0.0000000,80.0000000); //object(binnt02_la) (15)
    CTSGC[16] = CreateDynamicObject(1332,2187.6000977,-1656.0999756,15.1999998,0.0000000,0.0000000,79.9969482); //object(binnt02_la) (16)
    CTSGC[17] = CreateDynamicObject(1332,2265.8999023,-1653.0999756,15.3999996,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (17)
    CTSGC[18] = CreateDynamicObject(1332,2263.6000977,-1653.0999756,15.3999996,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (18)
    CTSGC[19] = CreateDynamicObject(1332,2373.6999512,-1653.0999756,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (19)
    CTSGC[20] = CreateDynamicObject(1332,2375.8999023,-1653.0999756,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (20)
    CTSGC[21] = CreateDynamicObject(1332,2493.8999023,-1653.4000244,13.5000000,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (21)
    CTSGC[22] = CreateDynamicObject(1332,2491.1000977,-1684.5999756,13.6000004,0.0000000,0.0000000,180.0000000); //object(binnt02_la) (22)
    CTSGC[23] = CreateDynamicObject(1332,2124.1999512,-1612.8000488,13.6000004,0.0000000,0.0000000,340.0000000); //object(binnt02_la) (23)
    CTSGC[24] = CreateDynamicObject(1332,2122.1000977,-1612.0999756,13.6000004,0.0000000,0.0000000,339.9993896); //object(binnt02_la) (24)
    CTSGC[25] = CreateDynamicObject(1332,2075.1000977,-1606.5999756,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (26)
    CTSGC[26] = CreateDynamicObject(1332,2075.8000488,-1644.8000488,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (27)
    CTSGC[27] = CreateDynamicObject(1332,2075.8999023,-1713.1999512,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (28)
    CTSGC[28] = CreateDynamicObject(1332,2007.5999756,-1646.0999756,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (29)
    CTSGC[29] = CreateDynamicObject(1332,1995.5000000,-1679.5000000,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (30)
    CTSGC[30] = CreateDynamicObject(1332,1995.5999756,-1681.6999512,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (31)
    CTSGC[31] = CreateDynamicObject(1332,2007.5999756,-1722.6999512,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (32)
    CTSGC[32] = CreateDynamicObject(1332,2007.5999756,-1724.9000244,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (33)
    CTSGC[33] = CreateDynamicObject(1332,2045.0000000,-1758.0000000,13.6000004,0.0000000,0.0000000,180.0000000); //object(binnt02_la) (34)
    CTSGC[34] = CreateDynamicObject(1332,2047.3000488,-1758.0000000,13.6000004,0.0000000,0.0000000,179.9945068); //object(binnt02_la) (35)
    CTSGC[35] = CreateDynamicObject(1332,2087.5000000,-1805.8000488,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (36)
    CTSGC[36] = CreateDynamicObject(1332,2087.5000000,-1808.0000000,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (37)
    CTSGC[37] = CreateDynamicObject(1332,2075.8000488,-1905.0000000,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (38)
    CTSGC[38] = CreateDynamicObject(1332,2075.8000488,-1902.8000488,13.6000004,0.0000000,0.0000000,90.0000000); //object(binnt02_la) (39)
    CTSGC[39] = CreateDynamicObject(1332,2153.8000488,-1888.6999512,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (40)
    CTSGC[40] = CreateDynamicObject(1332,2156.3000488,-1888.6999512,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (41)
    CTSGC[41] = CreateDynamicObject(1332,2253.6999512,-1888.5999756,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (42)
    CTSGC[42] = CreateDynamicObject(1332,2255.8999023,-1888.5999756,13.6000004,0.0000000,0.0000000,0.0000000); //object(binnt02_la) (43)
    CTSGC[43] = CreateDynamicObject(1332,2319.5000000,-1917.9000244,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (44)
    CTSGC[44] = CreateDynamicObject(1332,2319.5000000,-1920.0999756,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (45)
    CTSGC[45] = CreateDynamicObject(1332,2276.6999512,-1978.0999756,13.6000004,0.0000000,0.0000000,180.0000000); //object(binnt02_la) (46)
    CTSGC[46] = CreateDynamicObject(1332,2274.3999023,-1978.0999756,13.6000004,0.0000000,0.0000000,179.9945068); //object(binnt02_la) (47)
    CTSGC[47] = CreateDynamicObject(1332,2279.1000977,-1978.0999756,13.6000004,0.0000000,0.0000000,179.9945068); //object(binnt02_la) (48)
    CTSGC[48] = CreateDynamicObject(1332,2419.6999512,-2077.3000488,13.6000004,0.0000000,0.0000000,270.0000000); //object(binnt02_la) (49)
    CTSGC[49] = CreateDynamicObject(1332,2419.6999512,-2079.5000000,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (50)
    CTSGC[50] = CreateDynamicObject(1332,2419.6999512,-2075.0000000,13.6000004,0.0000000,0.0000000,269.9945068); //object(binnt02_la) (51)
And i want to check if player is near any of those containers above. How should i do it ?
Reply
#2

Do you mean this https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
Reply
#3

Quote:
Originally Posted by aslan890
Посмотреть сообщение
I know about that... i just don't wanna type it 51 times... for each object... isn't there a shorter way of doing it instead of typing IsPlayerInRangeOfPoint 51 times ?? Cuz in the command im making is /getgarbage... and in that command i wanna put that check... only thing im asking if there is a shorter way of doing it.
Reply
#4

pawn Код:
new CTSGC[51];

new Float:Coords[50][6] = {
{2407.8999023,-1986.5000000,13.6000004,0.0000000,0.0000000,90.0000000},
{2407.8999023,-1986.5000000,13.6000004,0.0000000,0.0000000,90.0000000},
{2407.8999023,-1986.5000000,13.6000004,0.0000000,0.0000000,90.0000000}
};

for(new i; i < sizeof(CTSGC); i++)
{
    if(IsPlayerInRangeOfPoint(playerid, 7.0, Coords[i][0], Coords[i][1], Coords[i][2]))
    {
        SendClientMessage(playerid,0xFFFFFFFF,"You are near the Stadium entrance!"); break;
    }
}
for(new i; i < sizeof(CTSGC); i++)
{
    CTSGC[i] = CreateDynamicObject(1332,Coords[i][0], Coords[i][1], Coords[i][2],Coords[i][3], Coords[i][4], Coords[i][5],-1,-1,-1,150.0);
}
I believe code talks it self
Reply
#5

You can use 'for' loops. This is an example which probably easier to use than the previous one, as this one doesn't ask you to rewrite your whole list of objects.

Код:
for (new o; o != sizeof(CTSGC); o++) // Looping through all the variables inside array CTSGC
{
	if (IsValidDynamicObject(CTSGC[p])) // Checking if the value is actually a valid object..
	{
		new Float: pos[3]; // Acquiring the object's position.
		GetDynamicObjectPos(CTSGC[p], pos[0], pos[1], pos[2]);
		if (IsPlayerInRangeOfPoint(playerid, 5.0, pos[0], pos[1], pos[2])) // Checking if the player is in range..
		{
			// The player is in range of one of the containers! congratz

			break; // This stops the loop from searching for more containers, as it has already found one.
		}
	}
}
The 5.0 is the range in which the player should be, you can change this to the range you think suits best.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)