Page 1 of 1

Lua scripting problem [Solved]

Posted: Wed Oct 02, 2013 8:31 pm
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

Re: Lua scripting problem

Posted: Wed Oct 02, 2013 11:16 pm
by Marth8880
Did you add "legion50x_con" under the "scripts" header in your mission.req file?

Re: Lua scripting problem

Posted: Thu Oct 03, 2013 9:01 am
by Deviss
Marth8880 wrote:Did you add "legion50x_con" under the "scripts" header in your mission.req file?
yes, exactly :)

Re: Lua scripting problem

Posted: Thu Oct 03, 2013 12:21 pm
by Teancum
Why are you calling setup_teams again in legion50x_con.lua?

Re: Lua scripting problem

Posted: Thu Oct 03, 2013 12:37 pm
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 :)?

Re: Lua scripting problem

Posted: Tue Oct 08, 2013 5:37 am
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...")

Re: Lua scripting problem

Posted: Tue Oct 08, 2013 7:40 pm
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