Page 1 of 1
Little problem with the Lua system
Posted: Sun Feb 24, 2008 9:29 am
by Redline
Hi , i have a little problem with the door and the switch, because it don't work for me.
Ok... first look at this Lua order and the picture.´
conquest:Start()
OnObjectKillName(PlayAnimDrop, "Panel");
OnObjectRespawnName(PlayAnimRaise, "Panel");
EnableSPHeroRules()
-- START BRIDGEWORK!
-- OPEN
function PlayAnimRaise()
PauseAnimation("drop");
RewindAnimation("raise");
PlayAnimation("raise");
end
-- CLOSE
function PlayAnimDrop()
PauseAnimation("raise");
RewindAnimation("drop");
PlayAnimation("drop");
end
end
Zeroeditor
And?... what's wrong?

Re: Little problem with the Lua system
Posted: Sun Feb 24, 2008 9:48 am
by Master Fionwë
You tried it out ingame? If so, post the error log. There might be something in there to help us. Also, did you include the animation for the prop, by putting it in the munged folder in the world1 folder? That is really important, as it won't work unless you do so.
Re: Little problem with the Lua system
Posted: Sun Feb 24, 2008 12:06 pm
by Maveritchell
The main problem you have is that "OnObjectKillName" and "OnObjectRespawnName" do not, I believe, exist as predefined functions for SWBF2 .luas. You need to set it up like this:
Doorup = OnObjectKill(
function(object, killer)
if GetEntityPtr(object) == "panel" then
PauseAnimation("raise")
RewindAnimation("drop")
PlayAnimation("drop")
end
end
)
Doordown = OnObjectRepair(
function(object, actor)
if GetEntityPtr(object) == "panel" then
PauseAnimation("drop")
RewindAnimation("raise")
PlayAnimation("raise")
end
end
)
And remember to make sure that your object has destroyed geometry, otherwise it won't be able to have its health modified post-destruction (I believe).
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 9:57 am
by Redline
Thx that you try to help me , but this will don't work , because this old method has always worked. And i can't understand why it no longer work.
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 10:08 am
by Maveritchell
Redline wrote:Thx that you try to help me , but this will don't work , because this old method has always worked. And i can't understand why it no longer work.
I'm not sure what you're trying to say, but I'm fairly certain that as long as your objects have the proper ZE names the code I wrote out should work. Have you tried it and you're saying that it doesn't, or are you supposing that it doesn't because your original code didn't work?
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 10:55 am
by Redline
Yes , i have tried it! and yes the original code didn't work.
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 11:18 am
by Aman/Pinguin
Redline wrote:Yes , i have tried it! and yes the original code did't work.
So the code Maveritchell said works?
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 12:17 pm
by Maveritchell
Whoops, I just realized that OnObjectKillName etc. are actually referenced in stock .luas, so yeah, your original code would work. That being said, if there's an error (and it's unrelated to ZE work) it's probably that you shouldn't nest the new functions you're defining (PlayAnimRaise and PlayAnimDrop) inside the function ScriptPostLoad. Instead of having the "end" after both functions are defined, put it after EnableSPHeroRules().
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 1:53 pm
by [RDH]Zerted
Theres nothing wrong with nesting functions. Its done all the time in these scripts. Your problem is that you are trying to use two functions before they are defined. At OnObjectKillName(), the functions PlayAnimDrop and PlayAnimRaise don't exist yet. They are just nil variables.
You can move your OnObjects after the functions, or move the functions before the OnObjects. Also, moving the functions outside of ScriptPostLoad would work, as the functions would be read when that script file is loaded, but for scoping reasons, its best to do one of the first two options instead of the third.
Re: Little problem with the Lua system
Posted: Mon Feb 25, 2008 1:55 pm
by Aman/Pinguin
Yay, I know this isn't my topic but i think its ok if I post this here.
I had also trouble getting that working and just got it.

*happy*
Okay, for those who have trouble with it, here is my lua:
Code: Select all
--
-- LUA Angruya Droid Invasion
--
-- Gametyp Scripts
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("AIHeroSupport")
-- REP Angreifer (1 = Angreifer)
REP = 1;
CIS = 2;
-- Nicht aendern
ATT = REP;
DEF = CIS;
function ScriptPostLoad()
--CP's
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"}
--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}
--CP Ziele
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:Start()
herosupport = AIHeroSupport:New{AIATTHeroHealth = 2800, AIDEFHeroHealth = 2800, gameMode = "NonConquest",}
herosupport:SetHeroClass(REP, "rep_inf_clone_commando")
herosupport:SetHeroClass(CIS, "cis_inf_ubd")
herosupport:AddSpawnCP("cp1","cp1_spawn")
herosupport:AddSpawnCP("cp2","cp2_spawn")
herosupport:AddSpawnCP("cp3","cp3_spawn")
herosupport:AddSpawnCP("cp4","cp4_spawn")
herosupport:Start()
OnObjectRespawnName(PlayAnimRise, "hdoorpanel");
OnObjectKillName(PlayAnimDrop, "hdoorpanel");
EnableSPHeroRules()
end
--START BRIDGEWORK!
-- CLOSE
function PlayAnimDrop()
PauseAnimation("hdooropen");
RewindAnimation("hdoorclose");
PlayAnimation("hdoorclose");
-- prevent the AI from running across it
BlockPlanningGraphArcs("Connection10");
BlockPlanningGraphArcs("Connection0");
BlockPlanningGraphArcs("Connection9");
EnableBarriers("Barrier92");
end
-- OPEN
function PlayAnimRise()
PauseAnimation("hdoorclose");
RewindAnimation("hdooropen");
PlayAnimation("hdooropen");
-- allow the AI to run across it
UnblockPlanningGraphArcs("Connection10");
UnblockPlanningGraphArcs("Connection0");
UnblockPlanningGraphArcs("Connection9");
DisableBarriers("Barrier92");
end
function ScriptPreInit()
SetWorldExtents(1500)
end
-------------------------
function ScriptInit()
Woah its awesome, now the hangar in my map can be closed.
