Elevator LUA (need help with timer again...)

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
ryukaji
Major
Major
Posts: 513
Joined: Mon Sep 17, 2007 7:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Contact:

Elevator LUA (need help with timer again...)

Post 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
Last edited by ryukaji on Sun Apr 05, 2009 8:00 pm, edited 2 times in total.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Elevator LUA

Post 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.
ryukaji
Major
Major
Posts: 513
Joined: Mon Sep 17, 2007 7:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Contact:

Re: Elevator LUA

Post 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?
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: Elevator LUA

Post 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.
ryukaji
Major
Major
Posts: 513
Joined: Mon Sep 17, 2007 7:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Contact:

Re: Elevator LUA (need help with timer again)

Post 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??
Post Reply