Timed Spawn ( Spawn at Anim. End )

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
NullCommando
Jedi
Jedi
Posts: 1010
Joined: Sat Dec 01, 2007 12:29 pm
Games I'm Playing :: Destiny
xbox live or psn: NullCommando
Location: Earth

Timed Spawn ( Spawn at Anim. End )

Post by NullCommando »

I have recently created and ZeroEdit animation where a Gunship lands on an Mygeeto platform. What I want is to have AI spawn as soon as the Gunship touches down, is there an .lua code to where you can set when the AI spawn from an specific path?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Timed Spawn ( Spawn at Anim. End )

Post by Maveritchell »

Kill a command post at the start of the level, and respawn it when your animation's over. Check out the scripting_system doc for how to.
NullCommando
Jedi
Jedi
Posts: 1010
Joined: Sat Dec 01, 2007 12:29 pm
Games I'm Playing :: Destiny
xbox live or psn: NullCommando
Location: Earth

Re: Timed Spawn ( Spawn at Anim. End )

Post by NullCommando »

Still learning my way around script functions, is this setup right? I bet I messed up the functions, I thought I should use the Trigger Animation on death of an object.
Hidden/Spoiler:
[code]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("ambush")

-- REP Attacking (attacker is always #1)
REP = 1;
CIS = 2;
-- These variables do not change
ATT = REP;
DEF = CIS;
AmbushTeam = 5
ATM = AmbushTeam

function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp2 = CommandPost:New{name = "cp2"}
cp4 = CommandPost:New{name = "cp4"}

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp4)

conquest:Start()

EnableSPHeroRules()

SetUpAmbushTrigger("ambushregion", ambushpath, 6, 5)

CommandPostKill: KillObject (local_cp3, killer)

animateobja = OnObjectKill
KillObject(local_cp3, killer)
if GetEntityName(cor1_prop_gunship) == "cor1_prop_gunship" then
PlayAnimation("land")
end

CommandPostRespawn: ObjectRespawn (local_cp3)


end


---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptInit()

ReadDataFile("ingame.lvl")


SetMaxFlyHeight(30)
SetMaxPlayerFlyHeight (30)

SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo

ReadDataFile("sound\\yav.lvl;yav1cw")
ReadDataFile("dc:sound\\nas.lvl;nascw")
ReadDataFile("dc:SIDE\\rep.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_medic",
"rep_inf_ep3_mechanic",
"rep_inf_ep3_sniper",
"rep_inf_ep3_support",
"rep_inf_ep3_officer",
"rep_hover_fightertank",
--"rep_hero_anakin",
"rep_hover_barcspeeder")
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_marine",
"cis_inf_rocketeer",
"cis_inf_sniper",
"cis_inf_OOM-9",
"cis_inf_grappledroid",
"cis_inf_grievousguard",
"cis_inf_droideka",
--"cis_hero_darthmaul",
"cis_hover_aat")


ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_laser",
"tur_bldg_tower")

SetupTeams{
rep = {
team = REP,
units = 32,
reinforcements = 450,
soldier = { "rep_inf_ep3_rifleman",9, 25},
assault = { "rep_inf_ep3_rocketeer",1, 4},
engineer = { "rep_inf_ep3_sniper",1, 4},
sniper = { "rep_inf_ep3_medic",1, 4},
officer = {"rep_inf_ep3_mechanic",1, 4},
support = { "rep_inf_ep3_support",1, 4},
special = { "rep_inf_ep3_officer",1, 4},

},
cis = {
team = CIS,
units = 32,
reinforcements = 450,
soldier = { "cis_inf_marine",9, 25},
assault = { "cis_inf_rocketeer",1, 4},
engineer = { "cis_inf_rifleman",1, 4},
sniper = { "cis_inf_sniper",1, 4},
officer = { "cis_inf_OOM-9",1, 4},
support = {"cis_inf_droideka",1, 4},
melee = { "cis_inf_grievousguard",1, 4},
},

atm = {
team = ATM,
units = 6,
reinforcements = -1,
soldier = {"rep_inf_ep3_rifleman", 6, 6},
}

}

SetTeamAsFriend(ATM, REP)
SetTeamAsFriend(REP, ATM)
SetTeamAsEnemy(ATM, CIS)
SetTeamAsEnemy(CIS, ATM)
ClearAIGoals(ATM)
AddAIGoal(ATM, "Deathmatch", 100)

--SetHeroClass(CIS, "cis_hero_darthmaul")
--SetHeroClass(REP, "rep_hero_anakin")

SetTeamName (3, "marines")
AddUnitClass (3, "rep_inf_ep3_rifleman", 10,15)
SetUnitCount (3, 32)
AddAIGoal(3, "Deathmatch", 100)
SetTeamAsFriend(ATT,3)
SetTeamAsFriend(3,ATT)
SetTeamAsEnemy(DEF,3)
SetTeamAsEnemy(3,DEF)

SetTeamName (4, "droids")
AddUnitClass (4, "cis_inf_marine", 10,15)
SetUnitCount (4, 32)
AddAIGoal(4, "Deathmatch", 100)
SetTeamAsFriend(DEF,4)
SetTeamAsFriend(4,DEF)
SetTeamAsEnemy(ATT,4)
SetTeamAsEnemy(4,ATT)


-- Level Stats
-- ClearWalkers()
AddWalkerType(0, 4) -- special -> droidekas
AddWalkerType(1, 0) -- 1x2 (1 pair of legs)
AddWalkerType(2, 0) -- 2x2 (2 pairs of legs)
AddWalkerType(3, 0) -- 3x2 (3 pairs of legs)
local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("CommandHover", 32)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 4)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)

SetSpawnDelay(10.0, 0.25)
--ReadDataFile("dc:MYG\\MYG.lvl", "MYG_conquest")
ReadDataFile("dc:MYG\\MYG.lvl", "MYG_conquest")
SetDenseEnvironment("false")




-- Sound

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
OpenAudioStream("sound\\yav.lvl", "yav1")
OpenAudioStream("sound\\yav.lvl", "yav1")
OpenAudioStream("sound\\yav.lvl", "yav1_emt")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 1)

SetOutOfBoundsVoiceOver(2, "cisleaving")
SetOutOfBoundsVoiceOver(1, "repleaving")

SetAmbientMusic(REP, 1.0, "rep_yav_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_yav_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2, "rep_yav_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_yav_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_yav_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2, "cis_yav_amb_end", 2,1)

SetVictoryMusic(REP, "rep_yav_amb_victory")
SetDefeatMusic (REP, "rep_yav_amb_defeat")
SetVictoryMusic(CIS, "cis_yav_amb_victory")
SetDefeatMusic (CIS, "cis_yav_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("BirdScatter", "birdsFlySeq1")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")


--OpeningSateliteShot
AddCameraShot(0.947363, 0.066942, 0.312307, -0.022068, -43.237518, 5.390805, 107.599274);
end

[/code]
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Timed Spawn ( Spawn at Anim. End )

Post by [RDH]Zerted »

Close, but wrong. First, the "CommandPostKill: " and "CommandPostRespawn: " text shouldn't be there. I'll assume you tossed those in for the GT post... If so, theres no need. We tend to know how to read lua code. If you really want to highlight it, put everything in a hide tag instead of code and set the important sections to different colors.

Second, There is no reason to use an event callback for killing the CP. You know when the CP is killed, because you are the one killing it and you only do it once. Remove the event callback and just play the animation after you kill the CP.

Third, SWBF2 uses event based programming. When the game starts to load a map, the lua script is read top to bottom, then the game calls ScriptInit() and ScriptPostLoad(). Event based actions/functions/callbacks don't block, meaning when you do PlayAnimation() the code won't sit there until the animation finished. Instead, it will continue on to the next line while the game starts playing the animation. The code you wrote (if it worked) would play the animation then imminently respawn the CP before the animation finished. You wanted to wait for the animation to finished before spawning a CP, and the way to wait is to use timers. Create a timer for the same length of the animation. When you play the animation, start the timer too. When the timer finishes, it should respawn the CP.

Fourth, you need to kill the CP before conquest:Start(). When Start() is called, the Conquest game mode starts and the AI start spawning. There is a small chance that a few bots could spawn from the CP before you can kill it. If you kill it before Conquest starts, the CP wil be gone before the AI start spawning.
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: Timed Spawn ( Spawn at Anim. End )

Post by MasterSaitek009 »

I'm assuming you're wanting something like this:

Code: Select all

KillObject (local_cp3)

conquest:Start()

OnObjectKill (
    function(object, killer)
            if GetEntityName(object) == "cor1_prop_gunship" then
                  PlayAnimation("land")
				  --You may want to wait a few seconds here depending on how long the anim is
				  ObjectRespawn (local_cp3)
			end
      end
)
Put it together in a hurry, may or may not be right.
Post Reply