Add spawn delay for a team? [Solved]
Moderator: Moderators
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Add spawn delay for a team? [Solved]
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
Thanks
Last edited by SkinnyODST on Tue Mar 06, 2018 2:51 am, edited 1 time in total.
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: Add spawn delay for a team?
Code: Select all
timername= CreateTimer("RepSpawn")
SetTimerValue(timername, (6)
StartTimer(timername)
OnTimerElapse(
function AllowAISpawn(REP, canSpawn)
function(timer)
DestroyTimer(timer)
end,
timername
)
Hidden/Spoiler:
-
- Command Sergeant Major
- Posts: 260
- Joined: Mon Apr 18, 2011 2:53 pm
- Projects :: Underground City The Complex [WIP]
Re: Add spawn delay for a team?
I think instead of "canSpawn", you have to put 1.
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: Add spawn delay for a team?
Code: Select all
OnTimerElapse(
function AllowAISpawn(REP, canSpawn)
function(timer)
DestroyTimer(timer)
end,
timername
)
--------------------
Consider the following code:
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 )
- a) Print "Timer 'RepSpawn' has elapsed!" to the debug log (BFront2.log). (line 6)
Code: Select all
function(timer)
print("Timer 'RepSpawn' has elapsed!")
end,
Code: Select all
AllowAISpawn(REP, canSpawn)
---------------------------------------------------------------------------------------
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.
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: Add spawn delay for a team?
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, 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
Other than that I still have no clue how to delay rep spawn. I put this in,
Hidden/Spoiler:
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:
-
- Gametoast Staff
- Posts: 4910
- Joined: Sat Nov 03, 2007 4:55 pm
- Location: SoCal, USA
Re: Add spawn delay for a team?
You can't just make up a lua function like that. This is what you actually meant:SkinnyODST wrote:Code: Select all
DisallowAISpawn(REP)
Code: Select all
AllowAISpawn(REP, false)
It should be instead:SkinnyODST wrote:Code: Select all
AllowAISpawn(REP)
Code: Select all
AllowAISpawn(REP, true)
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: Add spawn delay for a team?
Omg it works. After putting DisallowAISpawn in the teams didn`t spawn so I thought it was recognised as a function? Anyway,AQT wrote:You can't just make up a lua function like that. This is what you actually meant:SkinnyODST wrote:Code: Select all
DisallowAISpawn(REP)
Code: Select all
AllowAISpawn(REP, false)
It should be instead:SkinnyODST wrote:Code: Select all
AllowAISpawn(REP)
Code: Select all
AllowAISpawn(REP, true)
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: Add spawn delay for a team?
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.SkinnyODST wrote:Omg it works. After putting DisallowAISpawn in the teams didn`t spawn so I thought it was recognised as a function?