Jump to content

HELP destroyelement


Ronis

Recommended Posts

Posted

Hello, need little help with destroy element, someone can help me what's wrong, why function removeboxfromhands not working

function PutBoxOnHand() 
local pizza = createObject ( 1271, 0, 0, 0 ) 
exports.bone_attach:attachElementToBone(pizza,source,12,0.081,0.05,0.01,0,-70,0) 
end 
addEvent("PutBoxOnHand", true) 
addEventHandler("PutBoxOnHand", root, PutBoxOnHand) 
  
 function removeBoxFromHands () 
    if pizza[source] and isElement(pizza[source]) then 
    destroyElement(tank[source]) 
    pizza[source] = nil 
   end 
  end 
addEvent("removeBoxHands", true) 
addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) 

Posted

Use the [/lua] tags next time.

 

pizza = {} 
  
function PutBoxOnHand() 
pizza[source] = createObject ( 1271, 0, 0, 0 ) 
exports.bone_attach:attachElementToBone(pizza[source],source,12,0.081,0.05,0.01,0,-70,0) 
end 
addEvent("PutBoxOnHand", true) 
addEventHandler("PutBoxOnHand", root, PutBoxOnHand) 
  
 function removeBoxFromHands () 
    if pizza[source] and isElement(pizza[source]) then 
    destroyElement(pizza[source]) 
    pizza[source] = nil 
   end 
  end 
addEvent("removeBoxHands", true) 
addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) 

Posted

You first have to define pizza as a table before adding it in like that, that's just how lua works;

local pizza = { } 
pizza [ source ] = createObject ( 1271, 0, 0, 0 ) 

Make sure to put the "local pizza..." at the top of your document to avoid nil values.

Posted
local pizza = {} 
function PutBoxOnHand() 
pizza[source] = createObject ( 1271, 0, 0, 0 ) 
exports.bone_attach:attachElementToBone(pizza[source],source,12,0.081,0.05,0.01,0,-70,0) 
end 
addEvent("PutBoxOnHand", true) 
addEventHandler("PutBoxOnHand", root, PutBoxOnHand) 
  
 function removeBoxFromHands () 
    if pizza[source] and isElement(pizza[source]) then 
    destroyElement(pizza[source]) 
    pizza[source] = nil 
   end 
  end 
addEvent("removeBoxHands", true) 
addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands) 

Posted
local pizza[source] = createObject ( 1271, 0, 0, 0 )  

Here unexpected symbol near '['

Look at the code I posted. It does not have a local index declaration.

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