FlorinSzasz Posted July 3, 2022 Share Posted July 3, 2022 local test_locations = {} function test_someting() test_locations[1]=createMarker(-106.93572235107,-1150.2275390625,1.0437397956848-1,"cylinder",4.0,53,151,255,45) test_locations[2]=createMarker(-129.19007873535,-1202.5013427734,2.1060457229614,"cylinder",4.0,53,151,255,45) test_locations[3]=createMarker(-142.54978942871,-1272.1796875,2.1073033809662,"cylinder",4.0,53,151,255,45) end addCommandHandler("test2",test_someting,false,false) local function test(hitPlayer,matchingDimension) for i = 1,3 do if source == test_locations[i] then outputChatBox(""..i.."") destroyElement(test_locations[i]) end end end addEventHandler("onClientMarkerHit",getRootElement(),test) Hi guys, i try to spawn for a job more markers at once and when i hit one i want to check which one i hit. I tried to do this first time 1. i made a table and wrote the markers coords 2. i wrote a function with a ipairs loop in it to make the markers 3. i wrote the function for onClientMarkerHit event but the thing is only the first marker reacts to it and 2nd or 3rd or any other marker from table wont but they are created/spawned Is there another way to check which marker i hit from all created from a table than the method from above. Link to comment
Tekken Posted July 3, 2022 Share Posted July 3, 2022 Hi, will you try this local markers = {}; addCommandHandler("test", function() mark = createMarker(-106.93572235107, -1150.2275390625, 1.0437397956848-1, "cylinder", 4.0, 53, 151, 255, 45); markers[mark] = #markers + 1; mark = createMarker(-129.19007873535, -1202.5013427734, 2.1060457229614, "cylinder", 4.0, 53, 151, 255, 45); markers[mark] = #markers + 1; mark = createMarker(-142.54978942871, -1272.1796875, 2.1073033809662, "cylinder", 4.0, 53, 151, 255, 45); markers[mark] = #markers + 1; end); addEventHandler("onClientMarkerHit", root, function() if markers[source] then outputChatBox(markers[source]); destroyElement(source); markers[source] = nil; end end); Should be working, been a while since I edited MTA Lua 1 1 Link to comment
FlorinSzasz Posted July 3, 2022 Author Share Posted July 3, 2022 Well this works too thx . But i wonder how the game gets that markers[source] is markers[mark] i hope u can give me an ideea or someone. Link to comment
FlorinSzasz Posted February 22, 2023 Author Share Posted February 22, 2023 local test_locations = {} function test_someting() test_locations[1]=createMarker(2199.92871,-1671.48145,14.41751 - 1,"checkpoint",4.0,53,151,255,45) test_locations[2]=createMarker(2181.92944,-1713.81812,12.74913 ,"checkpoint",4.0,53,151,255,45) test_locations[3]=createMarker(2209.10229,-1658.24084,14.79899 - 1,"checkpoint",4.0,53,151,255,45) test_locations[4]=createMarker(2219.04077,-1687.14417,13.334671,"checkpoint",4.0,53,151,255,45) end addCommandHandler("test2",test_someting,false,false) local function test(hitPlayer,matchingDimension) for k,v in ipairs(test_locations) do if source == test_locations[k] then outputChatBox(""..k.."") destroyElement(test_locations[k]) end end end addEventHandler("onClientMarkerHit",getRootElement(),test) Solved, i got back to scripting after months! So in this way from all the markers i destroy only the one i hit. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now