Jump to content

HELP| marker Hit Problem


scolen

Recommended Posts

When one of these markers is hit, another marker is destroyed. After that, even if other markers are hit, none of the markers will be destroyed. What is the reason for it ?

garbages = {
    {-1881.14380, -1707.47888, 21.75000},
    {-1885.83081, -1723.84656, 21.75641},
    {-1896.03723, -1731.46301, 21.75000},
    {-1908.80933, -1733.61536, 21.75000}
}

function pickup(player)
   for i,garbage in pairs(garbages) do 
       marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0)
       function picked(player)
           destroyElement(marker)
       end
       addEventHandler("onMarkerHit", marker, picked)
   end
end

 

Link to comment

I believe that is because you have been destroying variable marker, and not the source of onMarketrHit. So every time you hit any cylinder, the code will destroy the last cylinder in variable marker
 

Try this one to destroy do source of hit

garbages = {
    {-1881.14380, -1707.47888, 21.75000},
    {-1885.83081, -1723.84656, 21.75641},
    {-1896.03723, -1731.46301, 21.75000},
    {-1908.80933, -1733.61536, 21.75000}
}

function pickup(player)
   for i,garbage in pairs(garbages) do 
       marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0)
       function picked(player)
           destroyElement(source) -- here the modification
       end
       addEventHandler("onMarkerHit", marker, picked)
   end
end

If it helped, pls give rep+.

Edited by Rougue90
  • Thanks 1
Link to comment
17 hours ago, Rougue90 said:

I believe that is because you have been destroying variable marker, and not the source of onMarketrHit. So every time you hit any cylinder, the code will destroy the last cylinder in variable marker
 

Try this one to destroy do source of hit

garbages = {
    {-1881.14380, -1707.47888, 21.75000},
    {-1885.83081, -1723.84656, 21.75641},
    {-1896.03723, -1731.46301, 21.75000},
    {-1908.80933, -1733.61536, 21.75000}
}

function pickup(player)
   for i,garbage in pairs(garbages) do 
       marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0)
       function picked(player)
           destroyElement(source) -- here the modification
       end
       addEventHandler("onMarkerHit", marker, picked)
   end
end

If it helped, pls give rep+.

thanks bro ❤️

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...