Ronis Posted January 25, 2016 Posted January 25, 2016 Hello, need little help with this detach elements. function PutBoxOnHand(tank, x, y, z) local x, y, z = getElementPosition ( source ) --Get the players position local tank = createObject ( 1220, x, y, z + 5 ) --Create a tank attachElements ( tank, source, 0, 0, -1 ) --Attach the tank to the player. end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", getRootElement(),PutBoxOnHand) function removeBoxHands (thePlayer) local tank = getAttachedElements( thePlayer ) detachElements ( tank) end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxHands) RemoveBoxHands not working
KariiiM Posted January 25, 2016 Posted January 25, 2016 (edited) Hey, which element do you want to detach? "tank" ? from player's hands? Edited January 25, 2016 by Guest
Ronis Posted January 25, 2016 Author Posted January 25, 2016 Hey, i want detach the box createObject ( 1220, x, y, z + 5 ) --Create a tank
KariiiM Posted January 25, 2016 Posted January 25, 2016 Okay, here you go Test it and tell me the results to let me know local tank = {} function PutBoxOnHand(tank, x, y, z) local x, y, z = getElementPosition ( source ) --Get the players position tank[source] = createObject ( 1220, x, y, z + 5 ) --Create a tank attachElements ( tank[source], source, 0, 0, -1 ) --Attach the tank to the player. end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", getRootElement(),PutBoxOnHand) function removeBoxFromHands (thePlayer) if (isElementAttached(tank[source])) then detachElements(tank[source]) end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands)
Ronis Posted January 25, 2016 Author Posted January 25, 2016 ERROR attempt to index local 'tank' (a nill value) Line 33 = tank[source] = createObject ( 1220, x, y, z + 5 ) --Create a tank
KariiiM Posted January 25, 2016 Posted January 25, 2016 local tank = {} function PutBoxOnHand() local x, y, z = getElementPosition ( source ) --Get the players position tank[source] = createObject ( 1220, x, y, z + 5 ) --Create a tank attachElements ( tank[source], source, 0, 0, -1 ) --Attach the tank to the player. end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", getRootElement(),PutBoxOnHand) function removeBoxFromHands () if (isElementAttached(tank[source])) then detachElements(tank[source]) end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands)
Ronis Posted January 25, 2016 Author Posted January 25, 2016 wow man it's working, but one problem, the box is not removed, it's on the ground
KariiiM Posted January 25, 2016 Posted January 25, 2016 wow man it's working, but one problem, the box is not removed, it's on the ground Yes this function just detach the element, So do you want me to make the box destroyed?
KariiiM Posted January 26, 2016 Posted January 26, 2016 Try that and tell me if there's any error local tank = {} function PutBoxOnHand() local x, y, z = getElementPosition ( source ) --Get the players position tank[source] = createObject ( 1220, x, y, z + 5 ) --Create a tank attachElements ( tank[source], source, 0, 0, -1 ) --Attach the tank to the player. end addEvent("PutBoxOnHand", true) addEventHandler("PutBoxOnHand", getRootElement(),PutBoxOnHand) function removeBoxFromHands () if tank[source] and isElement(tank[source]) then destroyElement(tank[source]) tank[source] = nil end end addEvent("removeBoxHands", true) addEventHandler("removeBoxHands", getRootElement(),removeBoxFromHands)
Ronis Posted January 26, 2016 Author Posted January 26, 2016 You are the best man, the best, it's working, thankyou very much
KariiiM Posted January 26, 2016 Posted January 26, 2016 You are the best man, the best, it's working, thankyou very much You're welcome and anytime
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