Jump to content

little help DetachElements


Ronis

Recommended Posts

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 :(

Link to comment

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) 

Link to comment
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) 

Link to comment

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) 

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