Page 1 of 1
Elevator LUA (need help with timer again...)
Posted: Sat Apr 04, 2009 4:19 pm
by ryukaji
Ive tried to get this working but for some reason it doesnt play ...Whats wrong with my lua i got the first part to work but then I added the second part and now it doesnt work at all....
Code: Select all
animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "elevatorconsole" then
PlayAnimation("elevator_open")
PauseAnimation("elevator_open")
end
end
)
ActivateRegion("doortrigger2")
testfunction = OnEnterRegion (
function (enter_region, player)
if IsCharacterHuman(player) then
PlayAnimation ("elevator_close")
PauseAnimation ("elevator_close")
RewindAnimation ("elevator_open")
PlayAnimation ("elevator_down")
PauseAnimation ("elevator_down")
PlayAnimation ("elevator_open")
PauseAnimation ("elevator_open")
end
end,
"doortrigger2"
)
The first part worked but then when I added the Pause it stopped working, but without the pause it loops endlessly
Re: Elevator LUA
Posted: Sun Apr 05, 2009 3:27 am
by [RDH]Zerted
All the Animation functions return instantly. That is to say right after you do PlayAnimation(), PauseAnimation() is called too. You need to put everything into timers. When you do PlayAnimation(), start a timer for the length of the animation. When that timer is up, pause the animation and continue with the sequences.
Re: Elevator LUA
Posted: Sun Apr 05, 2009 12:04 pm
by ryukaji
Ohhh ok thanks I thought that was the problem I just didnt know what to do about it. Ill go read about timers then.
EDIT: ok so I set up a timer and this is what I did:
Code: Select all
timer1 = CreateTimer("timer1")
SetTimerValue(timer1, 1.5)
animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "elevatorconsole" then
PlayAnimation("elevator_open")
StartTimer ("timer1")
end
end
)
testfunction = OnTimerElapse(
function(timer, timer1)
PauseAnimation("elevator_open")
end
)
But now it just loops... what did I do wrong?
Re: Elevator LUA
Posted: Sun Apr 05, 2009 5:53 pm
by MasterSaitek009
Try this:
Code: Select all
timer1 = CreateTimer("timer1")
SetTimerValue(timer1, 1.5)
animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "elevatorconsole" then
PlayAnimation("elevator_open")
StartTimer ("timer1")
--You can inline functions like this to keep the continuity of the code
testfunction = OnTimerElapse(
function(timer, timer1)
PauseAnimation("elevator_open")
end,
--Which timer? OnTimerElapse takes two arguments. The function and the timer's name.
"timer1"
)
end
end
)
I haven't tried it but it
should(famous last words) work. I'll leave the cleanup(destroying timers and events) to you.
If any of the above is wrong Zerted, please correct me.
Re: Elevator LUA (need help with timer again)
Posted: Sun Apr 05, 2009 6:50 pm
by ryukaji
Thanks that worked now I think ill manage with the second part making the elevator go down
EDIT: I failed.
Code: Select all
timer1 = CreateTimer("timer1")
SetTimerValue(timer1, 1.5)
timer2 = CreateTimer("timer2")
SetTimerValue(timer2, 2.0)
animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "elevatorconsole" then
PlayAnimation("elevator_open")
StartTimer ("timer1")
testfunction = OnTimerElapse(
function(timer, timer1)
PauseAnimation("elevator_open")
end,
"timer1"
)
end
end
)
ActivateRegion("doortrigger2")
testfunction2 = OnEnterRegion (
function (enter_region, player)
if IsCharacterHuman(player) then
PlayAnimation ("elevator_close")
StartTimer ("timer1")
end
end,
"doortrigger2"
)
testfunction3 = OnTimerElapse (
function (timer, timer1)
PauseAnimation ("elevator_close")
PlayAnimation ("elevator_down")
StartTimer("timer2")
end,
"timer1"
)
testfunction4 = OnTimerElapse (
function (timer, timer2)
PauseAnimation ("elevator_down")
RewindAnimation ("elevator_open")
PlayAnimation ("elevator_open")
StartTimer("timer1")
end,
"timer2"
)
testfunction5 = OnTimerElapse (
function (timer, timer1)
PauseAnimation ("elevator_open")
end,
"timer1"
)
Ok so heres what I did for the second part. What happens is when I destroy the console the elevator opens but then immediately goes down, while the door becomes half transparent and flashy its really weird... What did I do wrong this time??