Lua scripting problem [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
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Lua scripting problem [Solved]

Post by Deviss »

Hi there to everybody, i have a little question about scripting, i never got the solution.
My problema is i have many script with my legion (...x_con.lua) and i added this code:
Hidden/Spoiler:
[code]
------------------------------------------------------------
--This is code for cycling rifleman models
------------------------------------------------------------
--KinetosImpetus

SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
--this little part ^ was for debugging really, it isn't necessary

-- Timer for skins--

--interval is the number of seconds between model changes
--maxskin is the number of versions to use

interval = 3 --i had been testing this at 10 second waves, but it could be changed
--in MP, it will probably cause each 15 second spawn-wave to be the same model
skintimer = CreateTimer("timeout") -- i don't know what significance "timeout" has, copied from hoth campaign this way
SetTimerValue(skintimer , interval )
--ShowTimer(skintimer ) --uncomment this line to see the timer onscreen
skin = 1
maxskin = 2

OnTimerElapse(
function(timer)


if (skin == 1) then
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_ep3sniper")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_ep3sniper_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_ep3_Clone_Commander_Faie")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_ep3_Clone_Commander_Faie_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_Mandalorian_Soldier")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_Mandalorian_Soldier_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARC_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARC_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_WeStar_M5a")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_WeStar_M5s")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_wrist_caster")
SetClassProperty("rep_clone7", "GeometryName", "rep_inf_SandTrooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "rep_inf_SandTrooper_low1")
end
if (skin == 2) then
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
end



skin = skin + 1

if (skin > maxskin) then
skin = 1
end

--ShowTimer(nil)
--DestroyTimer(timer)



SetTimerValue(skintimer , interval )
StartTimer(skintimer)


end,
skintimer
)

-------------------------------------------------------------------------
--resume normal conquest script, or whatever gamemode...
--------------------------------------------------------------------------

StartTimer(skintimer) --starts the timer the first time, after it starts, it will restart itself one ending.

--------------wait start the timer first! ok, now go...
---------------------------------------------------------------------
[/code]
to every lua's, so when i want modify one model, i must modify it in every lua (more than 40 lua files xD) my question is, is there a way for make it something like put that code in one lua like this: legion50x_con.lua
Hidden/Spoiler:
[code]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

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

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

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

function ScriptPostLoad()

------------------------------------------------------------
--This is code for cycling rifleman models
------------------------------------------------------------
--KinetosImpetus

SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
--this little part ^ was for debugging really, it isn't necessary

-- Timer for skins--

--interval is the number of seconds between model changes
--maxskin is the number of versions to use

interval = 3 --i had been testing this at 10 second waves, but it could be changed
--in MP, it will probably cause each 15 second spawn-wave to be the same model
skintimer = CreateTimer("timeout") -- i don't know what significance "timeout" has, copied from hoth campaign this way
SetTimerValue(skintimer , interval )
--ShowTimer(skintimer ) --uncomment this line to see the timer onscreen
skin = 1
maxskin = 2

OnTimerElapse(
function(timer)


if (skin == 1) then
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_ep3sniper")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_ep3sniper_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_ep3_Clone_Commander_Faie")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_ep3_Clone_Commander_Faie_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_Mandalorian_Soldier")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_Mandalorian_Soldier_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARC_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARC_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_WeStar_M5a")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_WeStar_M5s")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_wrist_caster")
SetClassProperty("rep_clone7", "GeometryName", "rep_inf_SandTrooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "rep_inf_SandTrooper_low1")
end
if (skin == 2) then
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
end



skin = skin + 1

if (skin > maxskin) then
skin = 1
end

--ShowTimer(nil)
--DestroyTimer(timer)



SetTimerValue(skintimer , interval )
StartTimer(skintimer)


end,
skintimer
)

end
function ScriptInit()

ReadDataFile("dc:SIDE\\Republic.lvl",
"Republic_1",
"Republic_2",
"Republic_3",
"Republic_4",
"Republic_5",
"Republic_6",
"Republic_7",
"Republic_8",
"Republic_9")

ReadDataFile("dc:SIDE\\50X.lvl",
"rep_clone1",
"rep_clone2",
"rep_clone3",
"rep_clone4",
"rep_clone5",
"rep_clone6",
"rep_clone7",
"rep_clone8",
"rep_clone9")
end[/code]
and call it from lua script adding only this line to every lua files:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
Conquest = ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("legion50x_con")

-- These variables do not change
ATT = 1
DEF = 2

-- Empire Attacking (attacker is always #1)
CIS = ATT
REP = DEF

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

function ScriptPostLoad()

i hope someone can help me :), thanks anyway
Last edited by Deviss on Tue Oct 08, 2013 7:42 pm, edited 1 time in total.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Lua scripting problem

Post by Marth8880 »

Did you add "legion50x_con" under the "scripts" header in your mission.req file?
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Lua scripting problem

Post by Deviss »

Marth8880 wrote:Did you add "legion50x_con" under the "scripts" header in your mission.req file?
yes, exactly :)
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: Lua scripting problem

Post by Teancum »

Why are you calling setup_teams again in legion50x_con.lua?
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Lua scripting problem

Post by Deviss »

Teancum wrote:Why are you calling setup_teams again in legion50x_con.lua?
because i dont know how make the legion50x_con.lua correcly , i tried moving the code part with those lines also, how must i make it correctly :)?
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: Lua scripting problem

Post by [RDH]Zerted »

Assuming all the code in your legion50x_con.lua works, wrap it all up in a function then call that function when it should run. Example:

Code: Select all

----start of file legion50x_con.lua
print("legion50x_con: Started loading")

function setup_legion50x()
    --all your legion50x_con setup code
end

print("legion50x_con: Finished loading")
----end of file legion50x_con.lua

Code: Select all

--somewhere inside ScriptPostLoad() or ScriptInit(): 
if setup_legion50x ~= nil then
    setup_legion50x()
else
    print("Oops, legion50x_con.lua wasn't loaded.  Something's wrong with my map setup...")
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Lua scripting problem

Post by Deviss »

Zerted... this work perfect!!!!, problem solved here my mission c_con.lua:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

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

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

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptPostLoad()

if setup_legion50x ~= nil then
setup_legion50x()
else
print("Oops, legion50x_con.lua wasn't loaded. Something's wrong with my map setup...")
end
and legion50x_con.lua:
Hidden/Spoiler:
----start of file legion50x_con.lua
print("legion50x_con: Started loading")

function setup_legion50x()
--all your legion50x_con setup code

------------------------------------------------------------
--This is code for cycling rifleman models
------------------------------------------------------------
--KinetosImpetus

SetClassProperty("rep_clone2", "GeometryName", "rep_inf_Marine_Commando")
SetClassProperty("rep_clone2", "GeometryLowRes", "rep_inf_Marine_Commando_low1")
SetClassProperty("rep_clone2", "ClothOdf", "rep_inf_Marine_Commando_cape")
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
--this little part ^ was for debugging really, it isn't necessary

-- Timer for skins--

--interval is the number of seconds between model changes
--maxskin is the number of versions to use

interval = 3 --i had been testing this at 10 second waves, but it could be changed
--in MP, it will probably cause each 15 second spawn-wave to be the same model
skintimer = CreateTimer("timeout") -- i don't know what significance "timeout" has, copied from hoth campaign this way
SetTimerValue(skintimer , interval )
--ShowTimer(skintimer ) --uncomment this line to see the timer onscreen
skin = 1
maxskin = 2

OnTimerElapse(
function(timer)


if (skin == 1) then
SetClassProperty("rep_clone2", "GeometryName", "rep_inf_ep3heavytrooper")
SetClassProperty("rep_clone2", "GeometryLowRes", "rep_inf_ep3heavytrooper_low1")
SetClassProperty("rep_clone2", "ClothOdf", "rep_inf_ep3heavytrooper_cape")
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_ep3sniper")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_ep3sniper_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_ep3_Clone_Commander_Faie")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_ep3_Clone_Commander_Faie_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_Mandalorian_Soldier")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_Mandalorian_Soldier_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARC_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARC_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_WeStar_M5a")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_WeStar_M5s")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_wrist_caster")
SetClassProperty("rep_clone7", "GeometryName", "rep_inf_SandTrooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "rep_inf_SandTrooper_low1")
end
if (skin == 2) then
SetClassProperty("rep_clone2", "GeometryName", "rep_inf_Marine_Commando")
SetClassProperty("rep_clone2", "GeometryLowRes", "rep_inf_Marine_Commando_low1")
SetClassProperty("rep_clone2", "ClothOdf", "rep_inf_Marine_Commando_cape")
SetClassProperty("rep_clone3", "GeometryName", "rep_inf_Death_Star_Gunner")
SetClassProperty("rep_clone3", "GeometryLowRes", "rep_inf_Death_Star_Gunner_low1")
SetClassProperty("rep_clone4", "GeometryName", "rep_inf_Clone_Marshall")
SetClassProperty("rep_clone4", "GeometryLowRes", "rep_inf_Clone_Marshall_low1")
SetClassProperty("rep_clone5", "GeometryName", "rep_inf_AT-RT_Driver")
SetClassProperty("rep_clone5", "GeometryLowRes", "rep_inf_AT-RT_Driver_low1")
SetClassProperty("rep_clone6", "GeometryName", "rep_inf_ARF_trooper")
SetClassProperty("rep_clone6", "GeometryLowRes", "rep_inf_ARF_trooper_low1")
SetClassProperty("rep_clone6", "WeaponName1", "rep_weap_inf_chaingun")
SetClassProperty("rep_clone6", "WeaponName2", "rep_weap_DC-15a_Carbine")
SetClassProperty("rep_clone6", "WeaponName4", "rep_weap_inf_fusioncutter")
SetClassProperty("rep_clone7", "GeometryName", "imp_inf_The_Force_Unleashed_EVO_Trooper")
SetClassProperty("rep_clone7", "GeometryLowRes", "imp_inf_The_Force_Unleashed_EVO_Trooper")
end



skin = skin + 1

if (skin > maxskin) then
skin = 1
end

--ShowTimer(nil)
--DestroyTimer(timer)



SetTimerValue(skintimer , interval )
StartTimer(skintimer)


end,
skintimer
)

-------------------------------------------------------------------------
--resume normal conquest script, or whatever gamemode...
--------------------------------------------------------------------------

StartTimer(skintimer) --starts the timer the first time, after it starts, it will restart itself one ending.

--------------wait start the timer first! ok, now go...
---------------------------------------------------------------------

end

print("legion50x_con: Finished loading")
----end of file legion50x_con.lua
Post Reply