SA-MP Forums Archive
[Scripting Help] GetObjectPos - 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: [Scripting Help] GetObjectPos (/showthread.php?tid=520357)



Help - how to create a object when is destroyed - diego200052 - 18.06.2014

Hello, I have a problem. I have several objects and what I want is to detect if the player is close to any of these, so if you want to delete it detects about writing given command. But do not know what function to use.

These are the objects:
pawn Код:
CreateObject(658, -1961.13904, -2321.01660, 35.81062,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1983.18164, -2306.64307, 34.90852,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2016.14282, -2264.51514, 37.59226,   0.00000, 0.00000, 7.86905);
    CreateObject(658, -2048.39502, -2279.55054, 29.44491,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2010.24060, -2343.55347, 29.67017,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2004.06079, -2353.01538, 29.79223,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2018.38208, -2329.69385, 29.27478,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2029.36194, -2291.35181, 31.52319,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2010.10254, -2297.05176, 35.42641,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2030.45569, -2316.16797, 29.67047,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1972.97534, -2354.68018, 30.07845,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1970.45227, -2319.30591, 36.75357,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2000.63892, -2310.16870, 34.11950,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1990.44080, -2348.10059, 28.77349,   0.00000, 0.00000, 355.67593);
    CreateObject(658, -1952.77271, -2400.87695, 29.12618,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1956.66724, -2379.96997, 29.67839,   0.00000, 0.00000, 342.11761);
    CreateObject(658, -1981.88892, -2367.93970, 29.17725,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1977.55750, -2341.85132, 32.61460,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1966.56409, -2341.48047, 33.16028,   0.00000, 0.00000, 359.12994);
    CreateObject(658, -2014.80310, -2273.52222, 36.46095,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2015.66284, -2244.74072, 42.63517,   0.00000, 0.00000, 6.45304);
    CreateObject(658, -2023.14612, -2311.52051, 30.44014,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1962.60889, -2298.47485, 39.00406,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1987.55054, -2321.47803, 33.79900,   0.00000, 0.00000, 296.59744);
    CreateObject(658, -1947.30542, -2354.70630, 31.02817,   0.00000, 0.00000, 353.11136);
    CreateObject(658, -2011.85620, -2317.49365, 30.58669,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2052.63354, -2296.35742, 29.33584,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2001.45227, -2328.94556, 30.92533,   0.00000, 0.00000, 0.27184);
    CreateObject(658, -1951.45557, -2336.34741, 34.34032,   0.00000, 0.00000, 0.93685);
    CreateObject(658, -1947.21790, -2389.20483, 28.84699,   0.00000, 0.00000, 3.86749);
    CreateObject(658, -1986.71814, -2275.15576, 40.01451,   0.00000, 0.00000, 1.38093);
    CreateObject(658, -1942.01318, -2380.26050, 29.53990,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1950.86914, -2307.78613, 39.93758,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1933.43591, -2367.24683, 30.39913,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -2040.30103, -2260.92065, 31.16879,   0.00000, 0.00000, 2.20797);
    CreateObject(658, -1988.83240, -2288.22144, 36.72249,   0.00000, 0.00000, 359.48987);
    CreateObject(658, -1958.64819, -2361.60986, 29.93515,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1951.81140, -2372.82495, 30.10171,   0.00000, 0.00000, 354.98141);
    CreateObject(658, -2013.98291, -2254.87061, 40.94287,   0.00000, 0.00000, 356.74564);
    CreateObject(658, -1978.14734, -2380.29199, 29.60982,   0.00000, 0.00000, 359.27863);
    CreateObject(658, -1936.52637, -2338.55688, 33.01614,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1965.27087, -2327.74609, 34.86839,   0.00000, 0.00000, 0.00000);
    CreateObject(658, -1920.58337, -2266.72681, 59.31048,   0.00000, 0.00000, 0.00000);
This is a idea for this but itґs wrong:

pawn Код:
new Float:x,Float:y,Float:z;
GetObjectPos(objectid,x,y,z);
if(IsPlayerInRangeOfPoint(playerid, 5.0,x,y,z))



Re: [Scripting Help] GetObjectPos - Konstantinos - 18.06.2014

Your way is correct, you only need to know the object IDs so store them to an array and then loop through them and inside the loop get the object's position and check if the player is in range.


Re: [Scripting Help] CreateObject - diego200052 - 18.06.2014

Thank you. But now when I destroy the object I storage the ID in a variable but how i build again?

pawn Код:
Tree[0] = CreateObject(658, -1961.13904, -2321.01660, 35.81062,   0.00000, 0.00000, 0.00000);
    Tree[1] = CreateObject(658, -1983.18164, -2306.64307, 34.90852,   0.00000, 0.00000, 0.00000);
    Tree[2] = CreateObject(658, -2016.14282, -2264.51514, 37.59226,   0.00000, 0.00000, 7.86905);
    Tree[3] = CreateObject(658, -2048.39502, -2279.55054, 29.44491,   0.00000, 0.00000, 0.00000);
    Tree[4] = CreateObject(658, -2010.24060, -2343.55347, 29.67017,   0.00000, 0.00000, 0.00000);
    Tree[5] = CreateObject(658, -2004.06079, -2353.01538, 29.79223,   0.00000, 0.00000, 0.00000);
    Tree[6] = CreateObject(658, -2018.38208, -2329.69385, 29.27478,   0.00000, 0.00000, 0.00000);
    Tree[7] = CreateObject(658, -2029.36194, -2291.35181, 31.52319,   0.00000, 0.00000, 0.00000);
    Tree[8] = CreateObject(658, -2010.10254, -2297.05176, 35.42641,   0.00000, 0.00000, 0.00000);
    Tree[9] = CreateObject(658, -2030.45569, -2316.16797, 29.67047,   0.00000, 0.00000, 0.00000);
    Tree[10] = CreateObject(658, -1972.97534, -2354.68018, 30.07845,   0.00000, 0.00000, 0.00000);
    Tree[11] = CreateObject(658, -1970.45227, -2319.30591, 36.75357,   0.00000, 0.00000, 0.00000);
    Tree[12] = CreateObject(658, -2000.63892, -2310.16870, 34.11950,   0.00000, 0.00000, 0.00000);
    Tree[13] = CreateObject(658, -1990.44080, -2348.10059, 28.77349,   0.00000, 0.00000, 355.67593);
    Tree[14] = CreateObject(658, -1952.77271, -2400.87695, 29.12618,   0.00000, 0.00000, 0.00000);
    Tree[15] = CreateObject(658, -1956.66724, -2379.96997, 29.67839,   0.00000, 0.00000, 342.11761);
    Tree[16] = CreateObject(658, -1981.88892, -2367.93970, 29.17725,   0.00000, 0.00000, 0.00000);
    Tree[17] = CreateObject(658, -1977.55750, -2341.85132, 32.61460,   0.00000, 0.00000, 0.00000);
    Tree[18] = CreateObject(658, -1966.56409, -2341.48047, 33.16028,   0.00000, 0.00000, 359.12994);
    Tree[19] = CreateObject(658, -2014.80310, -2273.52222, 36.46095,   0.00000, 0.00000, 0.00000);
    Tree[20] = CreateObject(658, -2015.66284, -2244.74072, 42.63517,   0.00000, 0.00000, 6.45304);
    Tree[21] = CreateObject(658, -2023.14612, -2311.52051, 30.44014,   0.00000, 0.00000, 0.00000);
    Tree[22] = CreateObject(658, -1962.60889, -2298.47485, 39.00406,   0.00000, 0.00000, 0.00000);
    Tree[23] = CreateObject(658, -1987.55054, -2321.47803, 33.79900,   0.00000, 0.00000, 296.59744);
    Tree[24] = CreateObject(658, -1947.30542, -2354.70630, 31.02817,   0.00000, 0.00000, 353.11136);
    Tree[25] = CreateObject(658, -2011.85620, -2317.49365, 30.58669,   0.00000, 0.00000, 0.00000);
    Tree[26] = CreateObject(658, -2052.63354, -2296.35742, 29.33584,   0.00000, 0.00000, 0.00000);
    Tree[27] = CreateObject(658, -2001.45227, -2328.94556, 30.92533,   0.00000, 0.00000, 0.27184);
    Tree[28] = CreateObject(658, -1951.45557, -2336.34741, 34.34032,   0.00000, 0.00000, 0.93685);
    Tree[29] = CreateObject(658, -1947.21790, -2389.20483, 28.84699,   0.00000, 0.00000, 3.86749);
    Tree[30] = CreateObject(658, -1986.71814, -2275.15576, 40.01451,   0.00000, 0.00000, 1.38093);
    Tree[31] = CreateObject(658, -1942.01318, -2380.26050, 29.53990,   0.00000, 0.00000, 0.00000);
    Tree[32] = CreateObject(658, -1950.86914, -2307.78613, 39.93758,   0.00000, 0.00000, 0.00000);
    Tree[33] = CreateObject(658, -1933.43591, -2367.24683, 30.39913,   0.00000, 0.00000, 0.00000);
    Tree[34] = CreateObject(658, -2040.30103, -2260.92065, 31.16879,   0.00000, 0.00000, 2.20797);
    Tree[35] = CreateObject(658, -1988.83240, -2288.22144, 36.72249,   0.00000, 0.00000, 359.48987);
    Tree[36] = CreateObject(658, -1958.64819, -2361.60986, 29.93515,   0.00000, 0.00000, 0.00000);
    Tree[37] = CreateObject(658, -1951.81140, -2372.82495, 30.10171,   0.00000, 0.00000, 354.98141);
    Tree[38] = CreateObject(658, -2013.98291, -2254.87061, 40.94287,   0.00000, 0.00000, 356.74564);
    Tree[39] = CreateObject(658, -1978.14734, -2380.29199, 29.60982,   0.00000, 0.00000, 359.27863);
    Tree[40] = CreateObject(658, -1936.52637, -2338.55688, 33.01614,   0.00000, 0.00000, 0.00000);
    Tree[41] = CreateObject(658, -1965.27087, -2327.74609, 34.86839,   0.00000, 0.00000, 0.00000);
    Tree[42] = CreateObject(658, -1920.58337, -2266.72681, 59.31048,   0.00000, 0.00000, 0.00000);
pawn Код:
DestroyObject(Tree[object_id]);



Re: [Scripting Help] CreateObject - Konstantinos - 18.06.2014

Quote:
Originally Posted by diego200052
Посмотреть сообщение
Thank you. But now when I destroy the object I storage the ID in a variable but how i build again?
What do you mean? You can create new objects and store their objectid to the array.

PS: When you destroy an object, it's good to set the variable (for that object) to INVALID_OBJECT_ID.
pawn Код:
DestroyObject(Tree[object_id]);
Tree[object_id] = INVALID_OBJECT_ID;



Re: [Scripting Help] CreateObject - diego200052 - 18.06.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
What do you mean? You can create new objects and store their objectid to the array.

PS: When you destroy an object, it's good to set the variable (for that object) to INVALID_OBJECT_ID.
pawn Код:
DestroyObject(Tree[object_id]);
Tree[object_id] = INVALID_OBJECT_ID;
Ok thank you, I resolved the problem. +REP