Hi,
How do i make pumping with lua ? I mean, an element go in a direction, then in reverse, then reverse again, etc.
I found something in a TA unit (a T3 mexe), but i don't understand how to do the same thing in lua.
[LUA] How make pumping ?
- zuzuf
- Administrateur - Site Admin
- Posts: 3281
- Joined: Mon Oct 30, 2006 8:49 pm
- Location: Toulouse, France
- Contact:
Re: [LUA] How make pumping ?
you need to start a script (which will then run in parallel to the function that started it) with a loop containing one cycle of the pumping animation which will be repeated until the loop ends.
Something like:
you could then do "this:start_script(this.PumpingAnimation, this)" in the Create function to have the unit pumping as soon as it's created (you may also want to delay the animation until build is complete). With this code it'll pump until its death but you can replace the "true" condition with a variable or something else to allow stopping/starting the animation with some event.
Something like:
Code: Select all
local ANIM_SPEED = 0.2
__this.PumpingAnimation = function(this)
while true do
this:move( this.piston, y_axis, 0, 1)
this:sleep( ANIM_SPEED )
this:move( this.piston, y_axis, 10, 1)
-- required to avoid the engine being stuck in a script
this:sleep( ANIM_SPEED )
end
end
=>;-D Penguin Powered
Re: [LUA] How make pumping ?
Thank you. I will try that.
Re: [LUA] How make pumping ?
Well, i tried to add that to my unit script, but how do i call the function, particularly by adding the name of the element i want to make "pumping" ?
- zuzuf
- Administrateur - Site Admin
- Posts: 3281
- Joined: Mon Oct 30, 2006 8:49 pm
- Location: Toulouse, France
- Contact:
Re: [LUA] How make pumping ?
Just use the start_script function which accepts as many parameters as you want:
Since you can manipulate only variables in Lua, the model pieces are just variables containing the piece's ID so you can copy it into another variable, change it (not recommended), use it as a return value for a function, etc...
Code: Select all
__this.my_function = function(this, parameter1, parameter2)
end
__this.Create = function(this)
this:start_script(this.my_function, this, this.head, this.lleg)
end
=>;-D Penguin Powered
Re: [LUA] How make pumping ?
Thanks, i will try that.
Who is online
Users browsing this forum: No registered users and 3 guests