Timed Spawn ( Spawn at Anim. End )
Moderator: Moderators
-
NullCommando
- Jedi

- Posts: 1010
- Joined: Sat Dec 01, 2007 12:29 pm
- xbox live or psn: NullCommando
- Location: Earth
Timed Spawn ( Spawn at Anim. End )
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?
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Timed Spawn ( Spawn at Anim. End )
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

- Posts: 1010
- Joined: Sat Dec 01, 2007 12:29 pm
- xbox live or psn: NullCommando
- Location: Earth
Re: Timed Spawn ( Spawn at Anim. End )
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:
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Timed Spawn ( Spawn at Anim. End )
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.
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 )
I'm assuming you're wanting something like this:
Put it together in a hurry, may or may not be right.
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
)