Playing an animation after a timer ends (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
User avatar
ThePanda
Private Second Class
Posts: 74
Joined: Sat Dec 20, 2008 4:22 pm

Playing an animation after a timer ends (Solved)

Post by ThePanda »

I've tried my hand at creating a timer that triggers an animation upon ending. I've taken a look through the scripting system document, and compared it with some shipped scripts, but I've not got anywhere.

Help would be appreciated
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
-- SPAX - Clone Wars Template Assault File
--
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("KY1c_cmn")


---- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")-- This is about capturing CP's
ScriptCB_DoFile("MultiObjectiveContainer")-- I'm not sure what this is for, but it is included in Almost all the Campaign missions
ScriptCB_DoFile("ObjectiveGoto")-- well this speaks for it'selve
ScriptCB_DoFile("ObjectiveAssault")-- something to do with killing units?
ScriptCB_SetGameRules("campaign")


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

myGameMode = "KY1_CW-Assault"

function myScriptInit()
ClearWalkers()
AddWalkerType(3, 1)
SetMemoryPoolSize("CommandFlyer", 2)
SetMemoryPoolSize("CommandWalker", 1)
end


function ScriptPostLoad()
ScriptCB_SetGameRules("campaign")-- Here you can see a script being used; The script to define the gameRules(of wich I don't really know what they do EXACTLY)
SetAIDifficulty(0, 0, "medium")-- I'd say this influences the dumbness of the A.I. to compensate for difficult maps.
DisableAIAutoBalance()--Help requested on explaining this

OnEnterRegion(
function(regIn,character)
MoveEntityToNode(character,"teleportnodes")
end,
"accteleport"
)
ActivateRegion("accteleport")


KillObject("rep-cp4-acc3")
SetProperty("cis-cp2", "Team", "2")
SetProperty("rep-cp2-acc", "Team", "1")
SetProperty("cis-cp2", "Value_ATK_Republic", "1000")
SetProperty("rep-cp1", "AISpawnWeight", "3")
SetProperty("rep-cp4-acc3", "AISpawnWeight", "3")
SetProperty("rep-cp2-acc", "AISpawnWeight", "1000")
SetProperty("rep-cp3-acc2", "AISpawnWeight", "3")


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "rep-cp1"}
cp2 = CommandPost:New{name = "cis-cp1"}
cp3 = CommandPost:New{name = "rep-cp2-acc"}
--cp5 = CommandPost:New{name = "cis-cp2"}
cp4 = CommandPost:New{name = "rep-cp2"}
cp6 = CommandPost:New{name = "rep-cp3-acc2"}
cp7 = CommandPost:New{name = "rep-cp4-acc3"}
--cp5 = CommandPost:New{name = "rep-cp3"}

onfirstspawn = OnCharacterSpawn(
function(character)
if IsCharacterHuman(character) then
ReleaseCharacterSpawn(onfirstspawn)
onfirstspawn = nil
objectives_timer = CreateTimer("objectives_timer")
SetTimerValue(objectives_timer, 2)
StartTimer(objectives_timer)
begin_objectives = OnTimerElapse(
function(timer)
StartObjectives ()
ScriptCB_EnableCommandPostVO(0)
end,
objectives_timer
)
end
end
)

--Go to the Acclamator Hangar
Objective1 = ObjectiveGoto:New{TeamATT = ATT, TeamDEF = DEF,
text = "level.KY1.objectives.campaign.2", popupText = "level.KY1.objectives.popup.2",
regionName = "rep-cp2-acc-con", mapIcon = "hud_objective_icon_circle", AIGoalWeight = 0}

Objective1:AddHint("level.spa2.objectives.popup.2a")
Objective1:AddHint("level.spa2.objectives.popup.2b")
Objective1:AddHint("level.spa2.objectives.popup.2c")


Objective1.OnStart = function(self)
att_obj1_aigoal = AddAIGoal(ATT, "Deathmatch", 100)
def_obj1_aigoal = AddAIGoal(DEF, "Deathmatch", 100)

end

Objective1.OnComplete = function(self)
DeleteAIGoal(att_obj1_aigoal)
DeleteAIGoal(def_obj1_aigoal)
ShowMessageText("game.objectives.complete", ATT)
SetProperty("cis-cp2", "Team", "2")
SetUnitCount(REP, 50)
SetUnitCount(CIS, 32)
RespawnObject("rep-cp4-acc3")

end




--Take the CIS CP
Objective2CP = CommandPost:New{name = "cis-cp2"}
Objective2 = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF, text = "level.KY1.objectives.campaign.3", popupText = "level.KY1.objectives.popup.3", AIGoalWeight = 0}
Objective2:AddCommandPost(Objective2CP)

Objective2:AddHint("level.geo1.hints.capture_cp")

Objective2.OnStart = function(self)
AICanCaptureCP("cis-cp2", ATT, true)
AICanCaptureCP("cis-cp2", DEF, false)
SetProperty("cis-cp2", "Value_DEF_CIS", "0")
SetProperty("cis-cp2", "Value_ATK_Republic", "1000")
SetProperty("rep-cp1", "SpawnPath", "rep-cp1spawn")
att_obj2_aigoal = AddAIGoal(ATT, "Defend", 50, "cis-cp2")
def_obj2_aigoal = AddAIGoal(DEF, "Defend", 10, "cis-cp2")
att_obj2_aigoal2 = AddAIGoal(ATT, "Deathmatch", 100)
def_obj2_aigoal2 = AddAIGoal(DEF, "Deathmatch", 100)

shipleave = CreateTimer("shipleave")
SetTimerValue(shipleave, 120)
StartTimer(shipleave)
shipretreat = OnTimerElapse(
function(timer)
if GetTimerValue(shipleave) == "0" then
PlayAnimationGroup("shipretreat")
end
end
)

end
Objective2.OnComplete = function(self)
ShowMessageText("game.objectives.complete", ATT)
DeleteAIGoal(att_obj2_aigoal)
DeleteAIGoal(att_obj2_aigoal2)
DeleteAIGoal(def_obj2_aigoal)
DeleteAIGoal(def_obj2_aigoal2)
SetProperty("cis-cp2", "Team", 1)
SetProperty("cis-cp2", "CaptureRegion", "")

end




--Kill 5 fighters
ship_count = 5
objective4Ships = {"cis_fly_droidfighter_sc_auto", "cis_fly_tridroidfighter_auto", "cis_fly_fanblade_auto"}
Objective4= Objective:New{teamATT = ATT, teamDEF = DEF,
text = "level.KY1.objectives.campaign.4", popupText = "level.KY1.objectives.popup.4"}

Objective4.OnStart = function(self)
ScriptCB_SndPlaySound("SPA2_obj_58")

Objective4ShipKillStart(objective4Ships)
end

Objective4.OnComplete = function(self)
DeleteAIGoal(Objective4.Dclass_cpGoal1)
DeleteAIGoal(Objective4.Dclass_cpGoal2)
end




--Land back in the hangar
Objective5 = ObjectiveGoto:New{TeamATT = ATT, TeamDEF = DEF,
text = "level.KY1.objectives.campaign.5", popupText = "level.KY1.objectives.popup.5",
regionName = "rep-cp2-acc-con", mapIcon = "hud_objective_icon_circle", AIGoalWeight = 0}

Objective5:AddHint("level.geo1.hints.movement")
Objective5:AddHint("level.geo1.hints.obj_markers")
Objective5:AddHint("level.geo1.hints.review_objectives")
Objective5:AddHint("level.geo1.hints.sprint")


Objective5.OnStart = function(self)
att_obj5_aigoal = AddAIGoal(ATT, "Deathmatch", 100)
def_obj5_aigoal = AddAIGoal(DEF, "Deathmatch", 100)
MapAddEntityMarker("waz_rep_acc_hangar", "hud_objective_icon_circle", 3.0, 1, "YELLOW", true)

end

Objective5.OnComplete = function(self)
DeleteAIGoal(att_obj5_aigoal)
DeleteAIGoal(def_obj5_aigoal)
ShowMessageText("game.objectives.complete", ATT)
MapRemoveEntityMarker("waz_rep_acc_hangar")

end




--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamDEF = DEF,
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(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
--conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)

conquest:Start()

SetUberMode(1);

EnableSPHeroRules()

end
function StartObjectives()
objectiveSequence = MultiObjectiveContainer:New{delayVictoryTime = 4.0 }
objectiveSequence:AddObjectiveSet(Objective1)
objectiveSequence:AddObjectiveSet(Objective2)
objectiveSequence:AddObjectiveSet(Objective4)
objectiveSequence:AddObjectiveSet(Objective5)
objectiveSequence:Start()

end

function Objective4ShipKillStart(shipClasses)
Objective4ShipKill = {} --reminder: don't reuse this variable name (it's global!)
for i, ship in ipairs (shipClasses) do
Objective4ShipKill = OnObjectKillClass (
function (object, killer)
if killer and IsCharacterHuman (killer) then
ship_count = ship_count - 1
if ship_count > 0 then
ShowMessageText("level.spa.count." .. ship_count, 1)
elseif ship_count == 0 then
Objective4:Complete (ATT)

--release all the "kill" event responses
for i, func in pairs(Objective4ShipKill) do
ReleaseObjectKill(func)
end
end
end
end,
ship
)
end
end

function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end

local locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
if charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end


Area highlighted in blue. Also, have I added in an extra end in there somewhere? My objectives don't seem to continue after I take the CP anymore.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Playing an animation after a timer ends

Post by Maveritchell »

Use Notepad ++ and check out your .lua script, it should help you determine what your nested structure looks like (and find any extra "end"s if they exist).

And I don't think "PlayAnimationGroup" is a valid callback. Use "PlayAnimation," that already uses the "animation group" name (you always call animations by the group name, and never by the animation name).
User avatar
ThePanda
Private Second Class
Posts: 74
Joined: Sat Dec 20, 2008 4:22 pm

Re: Playing an animation after a timer ends

Post by ThePanda »

I think I'm getting somewhere now.

I've tweaked it a little, and I think I have it working, or kind of. I've specified all the strings and values, and I don't get any more errors in BFront2.log about bad arguments to the function, but the animation still doesn't play. I'm not sure if the timer is even starting, even though I've told it to.

Here's the updated LUA:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
-- SPAX - Clone Wars Template Assault File
--
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("KY1c_cmn")


---- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")-- This is about capturing CP's
ScriptCB_DoFile("MultiObjectiveContainer")-- I'm not sure what this is for, but it is included in Almost all the Campaign missions
ScriptCB_DoFile("ObjectiveGoto")-- well this speaks for it'selve
ScriptCB_DoFile("ObjectiveAssault")-- something to do with killing units?
ScriptCB_SetGameRules("campaign")


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

myGameMode = "KY1_CW-Assault"

function myScriptInit()
ClearWalkers()
AddWalkerType(3, 1)
SetMemoryPoolSize("CommandFlyer", 2)
SetMemoryPoolSize("CommandWalker", 1)
end


function ScriptPostLoad()
ScriptCB_SetGameRules("campaign")-- Here you can see a script being used; The script to define the gameRules(of wich I don't really know what they do EXACTLY)
SetAIDifficulty(0, 0, "medium")-- I'd say this influences the dumbness of the A.I. to compensate for difficult maps.
DisableAIAutoBalance()--Help requested on explaining this

OnEnterRegion(
function(regIn,character)
MoveEntityToNode(character,"teleportnodes")
end,
"accteleport"
)
ActivateRegion("accteleport")


KillObject("rep-cp4-acc3")
SetProperty("cis-cp2", "Team", "2")
SetProperty("rep-cp2-acc", "Team", "1")
SetProperty("cis-cp2", "Value_ATK_Republic", "1000")
SetProperty("rep-cp1", "AISpawnWeight", "3")
SetProperty("rep-cp4-acc3", "AISpawnWeight", "3")
SetProperty("rep-cp2-acc", "AISpawnWeight", "1000")
SetProperty("rep-cp3-acc2", "AISpawnWeight", "3")


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "rep-cp1"}
cp2 = CommandPost:New{name = "cis-cp1"}
cp3 = CommandPost:New{name = "rep-cp2-acc"}
--cp5 = CommandPost:New{name = "cis-cp2"}
cp4 = CommandPost:New{name = "rep-cp2"}
cp6 = CommandPost:New{name = "rep-cp3-acc2"}
cp7 = CommandPost:New{name = "rep-cp4-acc3"}
--cp5 = CommandPost:New{name = "rep-cp3"}

onfirstspawn = OnCharacterSpawn(
function(character)
if IsCharacterHuman(character) then
ReleaseCharacterSpawn(onfirstspawn)
onfirstspawn = nil
objectives_timer = CreateTimer("objectives_timer")
SetTimerValue(objectives_timer, 2)
StartTimer(objectives_timer)
begin_objectives = OnTimerElapse(
function(timer)
StartObjectives ()
ScriptCB_EnableCommandPostVO(0)
end,
objectives_timer
)
end
end
)


--Go to the Acclamator Hangar
Objective1 = ObjectiveGoto:New{TeamATT = ATT, TeamDEF = DEF,
text = "level.KY1.objectives.campaign.2", popupText = "level.KY1.objectives.popup.2",
regionName = "rep-cp2-acc-con", mapIcon = "hud_objective_icon_circle", AIGoalWeight = 0}

Objective1:AddHint("level.spa2.objectives.popup.2a")
Objective1:AddHint("level.spa2.objectives.popup.2b")
Objective1:AddHint("level.spa2.objectives.popup.2c")


Objective1.OnStart = function(self)
att_obj1_aigoal = AddAIGoal(ATT, "Deathmatch", 100)
def_obj1_aigoal = AddAIGoal(DEF, "Deathmatch", 100)

end

Objective1.OnComplete = function(self)
DeleteAIGoal(att_obj1_aigoal)
DeleteAIGoal(def_obj1_aigoal)
ShowMessageText("game.objectives.complete", ATT)
SetProperty("cis-cp2", "Team", "2")
SetUnitCount(REP, 50)
SetUnitCount(CIS, 32)
RespawnObject("rep-cp4-acc3")

end




--Take the CIS CP
Objective2CP = CommandPost:New{name = "cis-cp2"}
Objective2 = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF, text = "level.KY1.objectives.campaign.3", popupText = "level.KY1.objectives.popup.3", AIGoalWeight = 0}
Objective2:AddCommandPost(Objective2CP)

Objective2:AddHint("level.geo1.hints.capture_cp")

Objective2.OnStart = function(self)
AICanCaptureCP("cis-cp2", ATT, true)
AICanCaptureCP("cis-cp2", DEF, false)
SetProperty("cis-cp2", "Value_DEF_CIS", "0")
SetProperty("cis-cp2", "Value_ATK_Republic", "1000")
SetProperty("rep-cp1", "SpawnPath", "rep-cp1spawn")
att_obj2_aigoal = AddAIGoal(ATT, "Defend", 50, "cis-cp2")
def_obj2_aigoal = AddAIGoal(DEF, "Defend", 10, "cis-cp2")
att_obj2_aigoal2 = AddAIGoal(ATT, "Deathmatch", 100)
def_obj2_aigoal2 = AddAIGoal(DEF, "Deathmatch", 100)

--Create animation timer and play the animation
Objective2.shipleave = CreateTimer("shipleave")
SetTimerValue(Objective2.shipleave, 120.0) --default 120.0
StartTimer(Objective2.shipleave)
Objective2.shipretreat = OnTimerElapse(
function(timer)
if GetTimerValue("shipleave") == "0" then
PlayAnimation("shipretreat")
DestroyTimer("shipleave")
--end,
--Objective2.shipleave
end
end,
"Objective2.shipleave"
)

end

Objective2.OnComplete = function(self)
ShowMessageText("game.objectives.complete", ATT)
DeleteAIGoal(att_obj2_aigoal)
DeleteAIGoal(att_obj2_aigoal2)
DeleteAIGoal(def_obj2_aigoal)
DeleteAIGoal(def_obj2_aigoal2)
SetProperty("cis-cp2", "Team", 1)
SetProperty("cis-cp2", "CaptureRegion", "")
end



--Kill 5 fighters
ship_count = 5
objective4Ships = {"cis_fly_droidfighter_sc_auto", "cis_fly_tridroidfighter_auto", "cis_fly_fanblade_auto"}
Objective4= Objective:New{teamATT = ATT, teamDEF = DEF,
text = "level.KY1.objectives.campaign.4", popupText = "level.KY1.objectives.popup.4"}

Objective4.OnStart = function(self)
ScriptCB_SndPlaySound("SPA2_obj_58")

Objective4ShipKillStart(objective4Ships)
end

Objective4.OnComplete = function(self)
DeleteAIGoal(Objective4.Dclass_cpGoal1)
DeleteAIGoal(Objective4.Dclass_cpGoal2)
end




--Land back in the hangar
Objective5 = ObjectiveGoto:New{TeamATT = ATT, TeamDEF = DEF,
text = "level.KY1.objectives.campaign.5", popupText = "level.KY1.objectives.popup.5",
regionName = "rep-cp2-acc-con", mapIcon = "hud_objective_icon_circle", AIGoalWeight = 0}

Objective5:AddHint("level.geo1.hints.movement")
Objective5:AddHint("level.geo1.hints.obj_markers")
Objective5:AddHint("level.geo1.hints.review_objectives")
Objective5:AddHint("level.geo1.hints.sprint")


Objective5.OnStart = function(self)
att_obj5_aigoal = AddAIGoal(ATT, "Deathmatch", 100)
def_obj5_aigoal = AddAIGoal(DEF, "Deathmatch", 100)
MapAddEntityMarker("waz_rep_acc_hangar", "hud_objective_icon_circle", 3.0, 1, "YELLOW", true)

end

Objective5.OnComplete = function(self)
DeleteAIGoal(att_obj5_aigoal)
DeleteAIGoal(def_obj5_aigoal)
ShowMessageText("game.objectives.complete", ATT)
MapRemoveEntityMarker("waz_rep_acc_hangar")

end




--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamDEF = DEF,
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(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
--conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)

conquest:Start()

SetUberMode(1);

EnableSPHeroRules()

end
function StartObjectives()
objectiveSequence = MultiObjectiveContainer:New{delayVictoryTime = 4.0 }
objectiveSequence:AddObjectiveSet(Objective1)
objectiveSequence:AddObjectiveSet(Objective2)
objectiveSequence:AddObjectiveSet(Objective4)
objectiveSequence:AddObjectiveSet(Objective5)
objectiveSequence:Start()

end

function Objective4ShipKillStart(shipClasses)
Objective4ShipKill = {} --reminder: don't reuse this variable name (it's global!)
for i, ship in ipairs (shipClasses) do
Objective4ShipKill = OnObjectKillClass (
function (object, killer)
if killer and IsCharacterHuman (killer) then
ship_count = ship_count - 1
if ship_count > 0 then
ShowMessageText("level.spa.count." .. ship_count, 1)
elseif ship_count == 0 then
Objective4:Complete (ATT)

--release all the "kill" event responses
for i, func in pairs(Objective4ShipKill) do
ReleaseObjectKill(func)
end
end
end
end,
ship
)
end
end

function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end

local locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
if charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end
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: Playing an animation after a timer ends

Post by [RDH]Zerted »

2 Things:
1) Your 'if timer value = 0' check is pointless. When the timer elapse code is run, the timer has ended. There is no need to check its value. Remove that if statement (don't forget to remove it's end too).
2) Your OnTimerElapse matches the wrong timer. Your timer has a name of shipleave (CreateTimer("shipleave")). The end of your OnTimerElapse should be "shipleave" or Objective2.shipleave but not "Objective2.shipleave".
User avatar
ThePanda
Private Second Class
Posts: 74
Joined: Sat Dec 20, 2008 4:22 pm

Re: Playing an animation after a timer ends

Post by ThePanda »

I was close, but not close enough.

It works now, thanks guys :).
Post Reply