.lua scripting help (timer related) [Solved]

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
LitFam
Sergeant Major
Sergeant Major
Posts: 234
Joined: Sat Feb 04, 2017 5:52 pm
Games I'm Playing :: SWBF II 2005
xbox live or psn: No gamertag set
Location: Milky Way, Solar System, Earth, Antarctica

.lua scripting help (timer related) [Solved]

Post 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!
Last edited by LitFam on Sun Dec 17, 2017 2:01 am, edited 1 time in total.
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Re: .lua scripting help (timer related)

Post 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: !
LitFam
Sergeant Major
Sergeant Major
Posts: 234
Joined: Sat Feb 04, 2017 5:52 pm
Games I'm Playing :: SWBF II 2005
xbox live or psn: No gamertag set
Location: Milky Way, Solar System, Earth, Antarctica

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

Post by LitFam »

Thank you!
Post Reply