Random Side script crashing (new one...) [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
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Random Side script crashing (new one...) [Solved]

Post by Dreadnot9 »

Using this script:
Hidden/Spoiler:
--
-- Random Sides Script for Star Wars Battlefront II Copyright (c) 2007 A.A.5. Productionzorz, All rights reserved.
-- Side Setup Script, Star Wars Battlefront II and Zero Engine Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
function RandomSetupCIS()
if unexpected_condition then error() end
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_bdroid",
"cis_inf_sniper",
"cis_inf_rocketeer")

cissoldier = "cis_inf_bdroid"
cisassault = "cis_inf_rocketeer"
cissniper = "cis_inf_ig"

RandomSupport = math.random(1,8) --Pic a number between 1 and 10

if RandomSupport <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_engineer")

cisengineer = "cis_inf_engineer"
end

if RandomSupport >3 and RandomSetup <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_nemodian")

cisengineer = "cis_inf_nemodian"

end

if RandomSupport >5 and RandomSetup <8 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_geonosian")

cisengineer = "cis_inf_geonosian"

end

--------------

RandomHeavy = math.random(1,8) --Pic a number between 1 and 10

if RandomHeavy <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_sbd")

cisheavy = "cis_inf_sbd"
end

if RandomHeavy >3 and RandomSetup <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_sarge")

cisheavy = "cis_inf_sarge"

end

if RandomHeavy >5 and RandomSetup <8 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_merc")

cisheavy = "cis_inf_merc"

end

--------------

RandomSpecial = math.random(1,8) --Pic a number between 1 and 10

if RandomSpecial <5 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_airdroid")

cisspecial = "cis_inf_airdroid"
end

if RandomSpecial >4 and RandomSetup <8 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_droideka")

cisspecial = "cis_inf_droideka"

end

--if RandomSpecial >5 and RandomSetup <8 then --if math.random results in 6 or 7
-- ReadDataFile("dc:SIDE\\cis.lvl",
-- "rep_inf_assassin")
--
--cisspecial = "rep_inf_assassin"

--end

--------------

RandomOfficer = math.random(1,8) --Pic a number between 1 and 10

if RandomOfficer <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_bx")

cisofficer = "cis_inf_bx"
end

if RandomOfficer >3 and RandomSetup <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_OOM")

cisofficer = "cis_inf_OOM"

end

if RandomOfficer >5 and RandomSetup <8 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_magnaguard")

cisofficer = "cis_inf_magnaguard"

end

--end
end
I get this error and a ctd:
Hidden/Spoiler:
Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to compare nil with number
stack traceback:
(none): in function `RandomSetupCIS'
(none): in function `ScriptInit'
My guess is that I have to separate the math.random functions, but i'm not entirely sure how.
Last edited by Dreadnot9 on Fri Jul 12, 2013 1:50 am, edited 1 time in total.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Random Side script crashing (new one...)

Post by razac920 »

The error means that something you are using is not defined (so set to nil). Your script compares the value of "RandomSetup" many times -- but you don't define it. I'm guessing you forgot to replace it with either RandomSupport, RandomHeavy, RandomSpecial, and RandomOfficer, depending on the instance. Try fixing all the "if xxx and RandomSetup < xxx then" lines.
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Re: Random Side script crashing (new one...)

Post by Dreadnot9 »

razac920 wrote:The error means that something you are using is not defined (so set to nil). Your script compares the value of "RandomSetup" many times -- but you don't define it. I'm guessing you forgot to replace it with either RandomSupport, RandomHeavy, RandomSpecial, and RandomOfficer, depending on the instance. Try fixing all the "if xxx and RandomSetup < xxx then" lines.
Exactly the issue (sort of), I actually noticed this myself, and changed it. This, however, still did not work, so I defined individual functions for each class, as can be seen in my new script:
Hidden/Spoiler:
--
-- Random Sides Script for Star Wars Battlefront II Copyright (c) 2007 A.A.5. Productionzorz, All rights reserved.
-- Side Setup Script, Star Wars Battlefront II and Zero Engine Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
function RandomSetupREP()
if unexpected_condition then error() end
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_blank",
"rep_inf_rifleman",
"rep_inf_rocketeer",
"rep_inf_sniper")

repsoldier = "rep_inf_rifleman"
repassault = "rep_inf_rocketeer"
repsniper = "rep_inf_sniper"

function RandomSupportREP()
RandomSupport = math.random(1,8) --Pic a number between 1 and 10

if RandomSupport <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_medic")

repengineer = "rep_inf_medic"
end

if RandomSupport >3 and RandomSupport <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_engineer")

repengineer = "rep_inf_engineer"

end

if RandomSupport >5 and RandomSupport <9 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_support")

repengineer = "rep_inf_support"

end

end

--------------
function RandomHeavyREP()
RandomHeavy = math.random(1,8) --Pic a number between 1 and 10

if RandomHeavy <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_gunner")

repheavy = "rep_inf_gunner"
end

if RandomHeavy >3 and RandomHeavy <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_arc")

repheavy = "rep_inf_arc"

end

if RandomHeavy >5 and RandomHeavy <9 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_flametrooper")

repheavy = "rep_inf_flametrooper"

end

end

--------------
function RandomSpecialREP()
RandomSpecial = math.random(1,8) --Pic a number between 1 and 10

if RandomSpecial <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_shadow")

repspecial = "rep_inf_shadow"
end

if RandomSpecial >3 and RandomSpecial <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_jettrooper")

repspecial = "rep_inf_jettrooper"

end

if RandomSpecial >5 and RandomSpecial <9 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_assassin")

repspecial = "rep_inf_assassin"

end

end

--------------
function RandomOfficerREP()
RandomOfficer = math.random(1,8) --Pic a number between 1 and 10

if RandomOfficer <4 then --if math.random results in 2 or three (and maybe 1)
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_clone_commando")

repofficer = "rep_inf_clone_commando"
end

if RandomOfficer >3 and RandomOfficer <6 then --if math.random results in 4 or 5
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_radio")

repofficer = "rep_inf_radio"
end

if RandomOfficer >5 and RandomOfficer <9 then --if math.random results in 6 or 7
ReadDataFile("dc:SIDE\\modrep.lvl",
"rep_inf_commander")

repofficer = "rep_inf_commander"
end

end

end
It works quite well now, and you were spot on.
Though I may try it again without all the functions...

EDIT: yep, you don't have to separate them into separate functions (no RandomSupport() etc.)
Post Reply