Jump to content

deleting marker if exist (return false)


Hero192

Recommended Posts

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

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 by Guest
Link to comment

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...