Jump to content

Remove and Objet with CommandHandler


Elmatus

Recommended Posts

Posted

Help, i created a scrit that when i write /hi the door opens and a smoke object appears, but i want tha when 5 seconds are passed, the smoke objet disappears, i have understand that is:

 removeObjet = ( myGate ) 

But it doesnt work, Please help

Posted
function rObject() 
    setTimer( function() destroyElement(myEffect) end, 3000, 0 ); 
end 
addCommandHandler("effectoff",rObject); 

Posted

Or then just do this.

addCommandHandler("effectoff", 
    function(player, cmd) 
        setTimer(destroyElement, 3000, 0, myeffect) 
    end 
) 

Doesn't really matter how.

Posted

The final code was this:

function createTheGate () 
   myGate = createObject ( 18483, -783.20001220703, 2597.1999511719, 104.09999847412, 0, 0, 83.984985351563 )  
end 
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createTheGate ) 
  
function openMyGate () 
   moveObject ( myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0 )        
   myEffect = createObject ( 2780, -783.90002441406, 2660.5, 104.09999847412, 0, 0, 0 ) 
   setTimer ( function() destroyElement (myEffect) end, 3000, 0 ); 
end 
addCommandHandler("opengate",openMyGate)   
  
function movingMyGateBack () 
   moveObject ( myGate, 500, -783.20001220703, 2597.1999511719, 104.09999847412, 0, 0, 0 )   
end 
addCommandHandler("closegate",movingMyGateBack)  

The door opens,the somoke appears, the smoke disappears, BUT, in the consolo say this repeatedly:

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

help me please D:

Posted

It doesnt help me that links D:

I need to solve this in console:

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

WARNIG: beta\testsmoke.lua:9: Bad Argument @ 'destroyElement' [Expected element at argument 1]

I dont know why appears, the scrip works perfect, bug that appears in console many times

Posted
[Expected element at argument 1]

Try:

function createTheGate () 
   myGate = createObject ( 18483, -783.20001220703, 2597.1999511719, 104.09999847412, 0, 0, 83.984985351563 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createTheGate ) 
  
function openMyGate () 
   moveObject ( myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0 )       
   myEffect = createObject ( 2780, -783.90002441406, 2660.5, 104.09999847412, 0, 0, 0 ) 
   setTimer ( function() end, 3000, 0 )  
   destroyElement (myEffect) 
end 
addCommandHandler("opengate",openMyGate)   
  
function movingMyGateBack () 
   moveObject ( myGate, 500, -783.20001220703, 2597.1999511719, 104.09999847412, 0, 0, 0 )   
end 
addCommandHandler("closegate",movingMyGateBack) 

You're missing an argument at line 7, check it out.

Posted (edited)
local originalX = -783.20001220703 
local originalY = 2597.1999511719 
local originalZ = 104.09999847412 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        myGate = createObject(18483, originalX, originalY, originalZ, 0, 0, 83.984985351563) 
    end 
) 
  
addCommandHandler("opengate", 
    function () 
        moveObject(myGate, 500, -781.20001220703, 2624.8000488281, 104.09999847412, 0, 0, 0)       
        myEffect = createObject(2780, -783.90002441406, 2660.5, 104.09999847412, 0, 0, 0) 
        setTimer(destroyElement, 3000, 1, myEffect) 
    end 
) 
  
addCommandHandler("closegate", 
    function() 
        moveObject(myGate, 500, originalX, originalY, originalZ, 0, 0, 0)   
    end 
) 

Edited by Guest
Posted

Why do you set a timer with infinite number of executes? This is the reason why you get them all messages, first time the object gets deleted and then each destroyElement call will fail because myEffect is not a valid object any more. Check the setTimer parameters again.

Posted
Why do you set a timer with infinite number of executes? This is the reason why you get them all messages, first time the object gets deleted and then each destroyElement call will fail because myEffect is not a valid object any more. Check the setTimer parameters again.

Right, didn't pay attention to that.

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