Jump to content

get objects in a colsphere


Recommended Posts

Hey, again a problem from my side (._.).

This time I have a problem with checking if there is an object in the colshape. When I move the object to the marker (where the colshape is as well) nothing happends.

Here is the code of checking if there is an object:

  
setTimer(function() 
    local shape1 = getElementsWithinColShape(moneyShape1) 
    for index, p in ipairs(shape1) do 
        if getElementModel(p) == 2935 or 2934 then 
            destroyElement(p) 
        end 
    end 
end,50,0) 

Link to comment
  • Moderators

as far I know this script would remove every object within the colshape

setTimer(function()

  • local shape1 = getElementsWithinColShape(moneyShape1)
    • for index, p in ipairs(shape1) do
      • if getElementModel(p) == 2935 or 2934 then
        destroyElement(p)

end

end

end,50,0)

remains always true, so if colshape did exist, then all elements would be destroyed.

You also would have an error/warning for trying to destroy player elements.

This can be written like this:

local model = getElementModel(p) 
 if  model == 2935 or model == 2934 then 

But I will recommend this:

local trueModels = {[2935]=true,[2934]=true} 
  
setTimer(function() 
    local shape1 = getElementsWithinColShape(moneyShape1) 
    for index, p in pairs(shape1) do 
        if trueModels[getElementModel(p)] then 
            destroyElement(p) 
        end 
    end 
end,50,0) 

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