Page 1 of 1

.lua scripting help (timer related) [Solved]

Posted: Sat Dec 16, 2017 8:06 pm
by LitFam
I am trying to make a new game mode where the objective is to hold out as long as you can against the enemy. I want a timer to count down till you win the match, also the player only get one life in the game mode.

Now I got the one life thing and the force player on team 1 stuff all figured out, however, I can't figure out how to create a timer that counts down till victory (you win the match after the timer hits 0).

If anyone could help me create this timer counting down until victory funtion I would be grateful!

Re: .lua scripting help (timer related)

Posted: Sat Dec 16, 2017 10:35 pm
by Lorul1
Add this code under function ScriptPostLoad() and above function ScriptInit() in your lua

Code: Select all

Gamestarter = OnCharacterSpawn( 
   function(player)
      if IsCharacterHuman(player) then
	 StartTimer(loser)
	 ShowTimer(loser)
      end
   end
)

loser = CreateTimer("loser")
	SetTimerValue(loser, 60)
	
	OnTimerElapse(
        function(timer)
	    MissionVictory(DEF)
            DestroyTimer(loser)
        end,
        loser
        )
Explanation & tips :
Hidden/Spoiler:
The first part translates to : Whenever a human player spawns, start the "loser" timer and also show/display the "loser" timer.

The second part (the actual "loser" timer) has a value set to 60 seconds. (you can replace this 60 with however many seconds you need)
Its translation is : When the time elapses we will give victory to the "DEF" team (normally either droids or rebels are the DEF team, and clones or stormies are the ATT team , so feel free to swap out DEF with ATT if you have to) and get rid of the timer named "loser"

Every occurrence of the words gamestarter and loser can be replaced with anything you want them to be.
(but if you replace the word loser with something else the other 4 instances will have to be replaced with that same word)

Hopes this helps you and maybe some newer modders too :thumbs: !

Re: .lua scripting help (timer related) [Solved]

Posted: Sun Dec 17, 2017 2:01 am
by LitFam
Thank you!