Spawn delay

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
ZoomV
Rebel Warrant Officer
Rebel Warrant Officer
Posts: 308
Joined: Thu Aug 15, 2013 11:27 am
Projects :: Old Republic Map pack
Games I'm Playing :: BF2 SWTOR and GW2
xbox live or psn: No gamertag set
Location: Belsavis, Maximum Security Ward

Spawn delay

Post by ZoomV »

So I have this map I'm working on, but at the beginning of the map I need to spawn a significant number of AI from a rather cramped command post, which leads to a ton of crowding. I am wondering if its possible to string out the spawn so its not spawning so many AI all at once at the beginning of the map.

I noticed the setspawndelay property in the LUA but for the life of me, I can't seem to figure out what it's parameters are and do.
jedimoose32
Field Commander
Field Commander
Posts: 938
Joined: Thu Jan 24, 2008 12:41 am
Projects :: Engineering Degree
Location: The Flatlands of Canada

Re: Spawn delay

Post by jedimoose32 »

This isn't 100% for sure, but... http://www.gametoast.com/viewtopic.php?p=511805#p511805

It makes sense given how a lot of other callbacks are set up in this game. Maybe try tweaking the values to (20.0, 0.2) or something like that and see what happens.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Spawn delay

Post by razac920 »

I don't know about that function in particular, but there is an easy enough workaround if that doesn't work:
Simply move part of each teams' characters onto local teams (which cannot spawn), and after a timer goes off move them back (so they can spawn).
ZoomV
Rebel Warrant Officer
Rebel Warrant Officer
Posts: 308
Joined: Thu Aug 15, 2013 11:27 am
Projects :: Old Republic Map pack
Games I'm Playing :: BF2 SWTOR and GW2
xbox live or psn: No gamertag set
Location: Belsavis, Maximum Security Ward

Re: Spawn delay

Post by ZoomV »

razac920 wrote:I don't know about that function in particular, but there is an easy enough workaround if that doesn't work:
Simply move part of each teams' characters onto local teams (which cannot spawn), and after a timer goes off move them back (so they can spawn).
Can you elaborate?
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Spawn delay

Post by razac920 »

Sure, start with some code like this:

Code: Select all

    local temp = GetTeamSize(1)
    for i=1,temp do -- moving all team 1 bots to team 3
      local unit = GetTeamMember(1,temp-i)
      if unit and not IsCharacterHuman(unit) then
        SelectCharacterTeam(unit, 3)
      end
    end
    local temp = GetTeamSize(2)
    for i=1,temp do -- moving all team 2 bots to team 4
      local unit = GetTeamMember(2,temp-i)
      if unit and not IsCharacterHuman(unit) then
        SelectCharacterTeam(unit, 4)
      end
    end
(Assuming teams 3 and 4 have no CPs and cannot spawn). Now just set a timer that moves some bots back, something like this (which moves back 1 bot to each original team each second):

Code: Select all

  teamsize = GetTeamSize(3) -- or 4, if they are the same
  botspawn = CreateTimer("botspawn")
  SetTimerValue(botspawn,1) -- 1 second timer
  timercheck = OnTimerElapse(function(timer)
    local unit = GetTeamMember(3,0)
    if unit then
      SelectCharacterTeam(unit,1)
    end
    unit = GetTeamMember(4,0)
    if unit then
      SelectCharacterTeam(unit,2)
    end
    teamsize = teamsize - 1
    if teamsize == 0 then
      ReleaseTimerElapse(timercheck)
      timercheck = nil
      DestroyTimer(botspawn)
      botspawn = nil
    else
     SetTimerValue(botspawn,1)
     StartTimer(botspawn) 
    end
  end,
  botspawn)
  StartTimer(botspawn)
Post Reply