Hero192 Posted February 25, 2016 Share Posted February 25, 2016 Hello guys, I made a robsystem everything is fine but the rob system has a marker to rob it inside the store, when I aim on the ped, all of them being created in once and when I finish rob only one marker be deleted. local marker local robmarkers = { {379.07, -68.18, 1001.51, 0, 10}, {379.07, -68.18, 1001.51, 1, 10}, {379.07, -68.18, 1001.51, 2, 10}, {379.07, -68.18, 1001.51, 3, 10}, {379.07, -68.18, 1001.51, 4, 10}, {379.07, -68.18, 1001.51, 5, 10}, {379.07, -68.18, 1001.51, 6, 10}, {367.35, -6.57, 1001.85, 5, 9}, {367.35, -6.57, 1001.85, 6, 9}, {367.35, -6.57, 1001.85, 7, 9}, {367.35, -6.57, 1001.85, 8, 9}, {367.35, -6.57, 1001.85, 9, 9}, {367.35, -6.57, 1001.85, 10, 9}, {367.35, -6.57, 1001.85, 11, 9}, {372.34, -119.30, 1001.49, 1, 5}, {372.34, -119.30, 1001.49, 8, 5}, {372.34, -119.30, 1001.49, 9, 5}, {372.34, -119.30, 1001.49, 10, 5}, {372.34, -119.30, 1001.49, 11, 5} } addEvent("onCreateMarker",true) addEventHandler("onCreateMarker", root, function() setElementFrozen(client, false) showCursor(false) removeEventHandler("onClientRender", root, renderDistanceCheck) if isElement(marker) then destroyElement(marker) end for index, v in pairs(robmarkers) do marker = createMarker(v[1], v[2], v[3]-1, "cylinder", 1.5, 255, 0, 0, 210) if marker then setElementDimension(marker, v[4]) setElementInterior(marker, v[5]) addEventHandler("onClientMarkerHit", marker, onRobMarkerHit) end end end) Much thanks to who can help me Link to comment
Tox Posted February 26, 2016 Share Posted February 26, 2016 (edited) because you define the marker variable every loop, i solved a similiar problem with storing markers in another table and create a loop to destroy local marker = {} for i = 1, #marker do if isElement (marker[i]) then destroyElement (marker[i]) end end for index, v in ipairs (robmarkers) do marker[index] = crea... Edited February 26, 2016 by Guest Link to comment
Noki Posted February 26, 2016 Share Posted February 26, 2016 The code you provided only shows the markers being created. When you created the ped and marker, include a something like this. -- Keep this up the top of your script markers = {} peds = {} -- Replace the line you have createMarker/createPed with this (but include your arguments) markers[index] = createMarker(...) peds[index] = createPed(...) Give the ped the same index as the marker. When they aim at the ped, set a global variable to the index of the ped within the table. for i, ped in ipairs(peds) do if (aimElement == ped) then ind = i break end end When the robbery finishes, you get the marker from the index previously got with the ped and destroy it. if (markers[ind] and isElement(markers[ind])) then destroyElement(markers[ind]) ind = nil end Probably not the most elegant solution, but it's what I would do. Link to comment
Bonus Posted February 26, 2016 Share Posted February 26, 2016 I think there are no peds for the markers. Just use a table and loop it. In your code I can't see what you are exactly doing. But notice: If you create the markers clientsided, only the client will see and use it. Link to comment
Hero192 Posted February 26, 2016 Author Share Posted February 26, 2016 Yes they're client sided, when I Aim on the ped all markers who are in the table getting created, not only one and when the marker getting robbed , I do if isElement(marker) then destroyElement(marker) end only one marker who be destroyed, others keep visible to the localPlayer and that's annoying. Any good solution @Bonus Link to comment
Bonus Posted February 26, 2016 Share Posted February 26, 2016 Save it in a table like in Nokis first code. local markers = {} ... for i=1, #robmarkers do markers[i] = createMarker ... end -- to destroy all -- for i=1, #markers do if isElement ( markers[i] ) then destroyElement ( markers[i] ) end end markers = {} Link to comment
Hero192 Posted February 26, 2016 Author Share Posted February 26, 2016 Worked Thanks alot Bonus and Noki!!, Btw, is there anyway to create only one marker for each ped's position instead of all these markers in once I mean, When you aim on the ped and the ped is on dimension 2 & interior 5 then the marker will be created in 2 & 5, like that I'll avoid fps drop Link to comment
Bonus Posted February 26, 2016 Share Posted February 26, 2016 Create the robmarkers with ped as index: robMarkers = { [ped1] = { { 123, 312, 51 ... }, ... } } } for i=1, #robMarkers[robped] do ... end 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