Page 1 of 1

Lua Troubles [Solved thanks to AQT]

Posted: Sun Feb 12, 2012 5:39 pm
by ARCTroopaNate
I'm trying to do a couple cool lua things for my map. I have destructable buildings in the map and I'm trying to make certain things happen when the buildings are destroyed.

Building A) Automatic win for the attacking team.
Building B) Subtract 10 reinforcments from the defending team.

I have attempted the reinforcements thing but it didn't work.

LUA
Hidden/Spoiler:
OnEntityDestruction(entity, cis_prop_hq)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)

OnEntityDestruction(entity, cis_prop_hq1)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)
I'm also wondering if you have to do that for every building of its type, or just the one.

Help please.

Re: Lua Troubles

Posted: Sun Feb 12, 2012 9:19 pm
by AQT
The functions you have set up don't say what will happen when some event before it occurs, so of course, they won't work. The following is good for understanding the structure of similar functions, and the If statement is exactly what you want, too: the destruction of an object.
But your supposed Then statements are correct. Also, your first scenario would follow the same format but just with a different outcome. The outcome would be an instant victory for a particular team, so use the function:

Code: Select all

MissionVictory("[insert-team-name]")
And just to be safe, you can also include an automatic defeat for the opposing team.

Re: Lua Troubles

Posted: Sun Feb 12, 2012 9:41 pm
by ARCTroopaNate
I've read through the thread multiple times, and I admit I'm still confused. I get the then part but not the if statements. Could you possibly walk me through creating an if statement for the Entity destruction thing?

Re: Lua Troubles

Posted: Sun Feb 12, 2012 10:06 pm
by AQT
Maveritchell wrote:animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "objectBnameinZeroEditor" then
PlayAnimation("whateveranimationgroup")
end
end
)
The bolded is the If statement, and you don't even need to change it to serve your purpose here, aside from putting the actual name of the object. OnObjectKill is the event that happens to object, which also doesn't change, because that's what you want to happen; you want this object to be destroyed in order for something, the Then statement(s), to occur. For more events see the shipped document entitled Battlefront2_scripting_system.doc. Animateobja is just a variable and can be anything you want, but it should be unique per function. And then the following is what happens once the specified object is destroyed in the above example:

Code: Select all

PlayAnimation("whateveranimationgroup")
But you seem to know what to replace that with for your purposes, so I will stop here.

Re: Lua Troubles

Posted: Sun Feb 12, 2012 10:50 pm
by ARCTroopaNate
New lua. Is this correct? It says I have an unexpected symbol.
Hidden/Spoiler:
objkill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_barracks" then
OnEntityDestruction(entity, cis_prop_barracks)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)
end
)

objkill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_barracks1" then
OnEntityDestruction(entity, cis_prop_barracks1)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)
end
)

objkill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_hq" then
MissionVictory("[REP]")
end
)

Re: Lua Troubles

Posted: Sun Feb 12, 2012 11:37 pm
by AQT
There should be two end lines per function. You only have one at the moment. You used objkill as a variable for all of the functions when they should each be unique, as in different from each other.
AQT wrote:...but it should be unique per function.
And you don't need those brackets around REP. The brackets were just part of the placeholder I used, not part of the function itself.

Re: Lua Troubles

Posted: Mon Feb 13, 2012 6:33 pm
by ARCTroopaNate
I tried the above and still, nothing happens.

The whole top part of my script.
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

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

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


function ScriptPostLoad()
EnableAIAutoBalance()

SetClassProperty("rep_fixer", "WeaponName2", "cis_weap_inf_shotgun")
SetClassProperty("cis_inf_droid", "WeaponName3", "rep_weap_inf_punch")
SetClassProperty("cis_inf_droideka", "PointsToUnlock", "8")

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

--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(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)


objectkill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_barracks" then
OnEntityDestruction(entity, cis_prop_barracks)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)
end
end
)

objckill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_barracks1" then
OnEntityDestruction(entity, cis_prop_barracks1)
DEFReinforcementCount = GetReinforcementCount(DEF)
SetReinforcementCount(DEF, DEFReinforcementCount - 10)
end
end
)

objkill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "cis_prop_hq" then
MissionVictory("REP")
end
end
)


conquest:Start()

EnableSPHeroRules()

end

Re: Lua Troubles

Posted: Mon Feb 13, 2012 6:48 pm
by AQT
Trying changing "REP" to ATT in the last function, and get rid of the entire OnEntityDestruction line from the other two. You don't even need that. Also, make sure the names of the objects you referenced are correct, that they match up in ZE and in the lua.

Re: Lua Troubles

Posted: Mon Feb 13, 2012 8:30 pm
by ARCTroopaNate
YES! :D It worked, thanks AQT! :jango: This is now solved. I did your changes, manually cleaned and now it's working!