Little problem with the Lua system

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
Redline
2nd Lieutenant
2nd Lieutenant
Posts: 396
Joined: Tue Jan 16, 2007 4:22 pm
Projects :: Space to Ground [reworking]
Games I'm Playing :: Different Games
xbox live or psn: No gamertag set
Location: The left side of the moon
Contact:

Little problem with the Lua system

Post 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
Image

And?... what's wrong? :?
Master Fionwë
Rebel Colonel
Rebel Colonel
Posts: 598
Joined: Wed May 30, 2007 3:33 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: At RCTC
Contact:

Re: Little problem with the Lua system

Post 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.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Little problem with the Lua system

Post 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).
Redline
2nd Lieutenant
2nd Lieutenant
Posts: 396
Joined: Tue Jan 16, 2007 4:22 pm
Projects :: Space to Ground [reworking]
Games I'm Playing :: Different Games
xbox live or psn: No gamertag set
Location: The left side of the moon
Contact:

Re: Little problem with the Lua system

Post 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.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Little problem with the Lua system

Post 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?
Redline
2nd Lieutenant
2nd Lieutenant
Posts: 396
Joined: Tue Jan 16, 2007 4:22 pm
Projects :: Space to Ground [reworking]
Games I'm Playing :: Different Games
xbox live or psn: No gamertag set
Location: The left side of the moon
Contact:

Re: Little problem with the Lua system

Post by Redline »

Yes , i have tried it! and yes the original code didn't work.
Last edited by Redline on Mon Feb 25, 2008 11:20 am, edited 1 time in total.
Aman/Pinguin
Jedi
Jedi
Posts: 1104
Joined: Tue Jan 30, 2007 6:04 am
Projects :: Inactive
Location: Germany

Re: Little problem with the Lua system

Post by Aman/Pinguin »

Redline wrote:Yes , i have tried it! and yes the original code did't work.
So the code Maveritchell said works?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Little problem with the Lua system

Post 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().
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: Little problem with the Lua system

Post 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.
Aman/Pinguin
Jedi
Jedi
Posts: 1104
Joined: Tue Jan 30, 2007 6:04 am
Projects :: Inactive
Location: Germany

Re: Little problem with the Lua system

Post 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. :P *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. :D
Post Reply