Add spawn delay for a team? [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
SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Add spawn delay for a team? [Solved]

Post by SkinnyODST »

Is there a way I can delay the spawn of the Republic team by a couple of seconds? If so, how? I know about making them spawn when the player does as used in the campaign but I need to them to spawn after a couple of seconds have passed in the map.

Thanks
Last edited by SkinnyODST on Tue Mar 06, 2018 2:51 am, edited 1 time in total.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Add spawn delay for a team?

Post by Marth8880 »

SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: Add spawn delay for a team?

Post by SkinnyODST »

Code: Select all

timername= CreateTimer("RepSpawn")
   SetTimerValue(timername, (6)
StartTimer(timername)
   OnTimerElapse(
function AllowAISpawn(REP, canSpawn)
function(timer)
            
      DestroyTimer(timer)
                 end,
              timername
              )
= Errors. What am I doing wrong? I`ve tried quite a few different combinations, all result in the same errors -
Hidden/Spoiler:
[code]C:\BF2_ModTools\data_CCC\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\CCC\CCCc_con.lua:83: `)' expected (to close `(' at line 82) near `StartTimer'
ERROR[scriptmunge scripts\CCC\CCCc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\CCC\CCCc_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

ERROR[levelpack mission\CCCc_con.req]:Expecting bracket, but none was found.
File : munged\pc\cccc_con.script.req(1)...

ucft <--
ERROR[levelpack mission\CCCc_con.req]:Expecting bracket, but none was found.
File : munged\pc\cccc_con.script.req(1)...

ucft <--

2 Errors 0 Warnings[/code]
hunpeter12
Command Sergeant Major
Command Sergeant Major
Posts: 260
Joined: Mon Apr 18, 2011 2:53 pm
Projects :: Underground City The Complex [WIP]
Games I'm Playing :: SWBF2

Re: Add spawn delay for a team?

Post by hunpeter12 »

I think instead of "canSpawn", you have to put 1.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Add spawn delay for a team?

Post by Marth8880 »

Code: Select all

OnTimerElapse(
    function AllowAISpawn(REP, canSpawn)
    function(timer)
        DestroyTimer(timer)
    end,
    timername
)
Having 'function' in 'function AllowAISpawn(REP, canSpawn)' means you're trying to declare 'AllowAISpawn' as a new function, which is what you need to *not* do. What you do need to do is set aside 15 minutes and watch this video from start to finish. If, after watching the video from start to finish, you don't understand how functions work, you need to re-watch the video a second time. If you still don't understand, re-watch it again.



--------------------

Consider the following code:

Image

This code example does the following when executed:
  • 1) Create a timer called "RepSpawn" while assigning that timer's handler to a variable called 'repSpawnTimer'. (line 1)
    2) Give the timer a duration of 6.0 seconds. (line 2)
    3) Start the timer. (line 3)
    4) Register an event callback and store the handler in a variable called 'repSpawnTimerHandler' (line 4) that tells the engine to do the following after (as specified in line 10) the repSpawnTimer timer elapses, all of which is encapsulated in the anonymous function declared in line 5 and closed in line 9:
    • a) Print "Timer 'RepSpawn' has elapsed!" to the debug log (BFront2.log). (line 6)
      b) Destroy the timer so that it cannot be used again. (line 7)
      c) Stop listening to OnTimerElapse events from repSpawnTimer. (line 8 )
What you need to understand is how 'OnTimerElapse' is structured and what it even is. It's simply an event callback that is executed when certain conditions are met - in this case, when the specified timer (repSpawnTimer) elapses. The way that you use this is (typically) with an anonymous function that is used as an argument in OnTimerElapse. What I mean by "anonymous function" is a function that is declared when it's used, and disposed of when it's done being used. The anonymous function in 'OnTimerElapse' is this:

Code: Select all

    function(timer)
        print("Timer 'RepSpawn' has elapsed!")
    end,
--------------------

Code: Select all

AllowAISpawn(REP, canSpawn)
You can't just pass undeclared variables (like canSpawn) as parameters into a function call like you're doing with 'AllowAISpawn(REP, canSpawn)'. In my documentation, I used 'canSpawn' exclusively as context for what the parameter represents (in this case, a boolean (true/false) value), NOT as something that you're supposed to *also* use - unless you were to declare an actual variable named 'canSpawn' with some value, and THEN pass that variable into the call.



---------------------------------------------------------------------------------------

With all of that said, it is extremely important that you understand that you *cannot* just hastily, lazily copy-paste blocks of code into your scripts when adding new scripting functionality to your maps and mods. It is critical that you understand the syntax of the language and take the time to understand what each bit of code is doing so that you can avoid problems like the ones you're currently experiencing.

Further reading:
https://sites.google.com/site/swbf2modt ... chitecture
https://www.lua.org/pil/5.html
https://www.lua.org/pil/6.html

Anyway, let me know how it all goes. :)
SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: Add spawn delay for a team?

Post by SkinnyODST »

Ok I watched the video a couple times and I think I know what functions do? I can set up a function to do something and then it makes it easier to use it again?
Other than that I still have no clue how to delay rep spawn. I put this in,
Hidden/Spoiler:
[code]DisallowAISpawn(REP)

timername = CreateTimer("RepSpawn")
SetTimerValue(timername, 6.0)
StartTimer(timername)
OnTimerElapse(
function(timer)

AllowAISpawn(REP)

DestroyTimer(timer)
end,
timername
)[/code]
I was confident this would work, it makes sense to me by looking at it, however once I started up the game,
1. The Republic didn`t start spawning after 6 seconds passed
and
2. Neither Rep or CIS teams spawn at all

I just can`t see why that doesn`t work. I told the game the Rep can`t spawn with DisallowAISpawn(REP), I set up the timer correctly (I hope) so that after 6 seconds elapses, the Rep team can spawn again because of AllowAISpawn(REP), but the only thing that kinda works is the Rep team can`t spawn...but neither can the CIS?

In case you can`t tell
Hidden/Spoiler:
Image
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Add spawn delay for a team?

Post by AQT »

SkinnyODST wrote:

Code: Select all

DisallowAISpawn(REP)
You can't just make up a lua function like that. This is what you actually meant:

Code: Select all

AllowAISpawn(REP, false)

SkinnyODST wrote:

Code: Select all

AllowAISpawn(REP)
It should be instead:

Code: Select all

AllowAISpawn(REP, true)
SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: Add spawn delay for a team?

Post by SkinnyODST »

AQT wrote:
SkinnyODST wrote:

Code: Select all

DisallowAISpawn(REP)
You can't just make up a lua function like that. This is what you actually meant:

Code: Select all

AllowAISpawn(REP, false)

SkinnyODST wrote:

Code: Select all

AllowAISpawn(REP)
It should be instead:

Code: Select all

AllowAISpawn(REP, true)
Omg it works. After putting DisallowAISpawn in the teams didn`t spawn so I thought it was recognised as a function? Anyway,

T h a n k
Y o u
A l l
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Add spawn delay for a team?

Post by Marth8880 »

SkinnyODST wrote:Omg it works. After putting DisallowAISpawn in the teams didn`t spawn so I thought it was recognised as a function?
The reason why they didn't spawn was because the script execution halted when it tried calling a nonexistent function, which would've been reported as an error with a stack trace in the debug log. With that said, it's a good idea to keep that log open in Tail or Glogg when scripting. ;)
Post Reply