Page 1 of 1

(Yay!) AI Hero Support with Random heroes [Solved]

Posted: Wed Aug 29, 2012 12:21 am
by ARCTroopaNate
I have random heroes being loaded and I wanted to make the AI use them, so I get archers script, I've done it before so I'm thinking it'll work fine, nope soap. Help would be appreciated.

Random Hero Script
Hidden/Spoiler:
function DecideHeroes(aalya, anakin, kiyadimundi, yoda, macewindu, obiwan, countdooku, yoda, darthmaul, grievous, jangofett)

local herocis = countdooku + darthmaul + grievous + jangofett
local herorep = macewindu + aalya + anakin + kiyadimundi + obiwan + yoda

herostrCis = 0
herostrRep = 0
supportstrCis = 0
supportstrRep = 0


local heroreprand = math.random(1, herorep)

if heroreprand <= macewindu then
herostrRep = "rep_hero_macewindu"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (aalya + macewindu) then
herostrRep = "rep_hero_aalya"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (anakin + aalya + macewindu) then
herostrRep = "rep_hero_anakin"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_kiyadimundi"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (obiwan + kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_obiwan"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (yoda + obiwan + kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_yoda"
supportstrRep = "rep_inf_ep3_rifleman"
end

local herocisrand = math.random(1, herocis)


if herocisrand <= (countdooku) then
herostrCis = "cis_hero_countdooku"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (darthmaul + countdooku) then
herostrCis = "cis_hero_darthmaul"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (grievous + darthmaul + countdooku) then
herostrCis = "cis_hero_grievous"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (jangofett + grievous + darthmaul + countdooku) then
herostrCis = "cis_hero_jangofett"
supportstrCis = "cis_inf_marine"
end


end
Lua
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

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

-- Empire Attacking (attacker is always #1)
CIS = 1
REP = 2
GAR = 3
-- 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()

DisableBarriers("cambar1")
DisableBarriers("cambar2")
DisableBarriers("cambar3")
DisableBarriers("turbar1")
DisableBarriers("turbar2")
DisableBarriers("turbar3")
DisableBarriers("camveh")
SetMapNorthAngle(180, 1)
AddAIGoal (GAR, "Deathmatch", 100)

AICanCaptureCP("CP1", GAR, true)
AICanCaptureCP("CP2", GAR, true)
AICanCaptureCP("CP3", GAR, true)
AICanCaptureCP("CP4", GAR, true)
AICanCaptureCP("CP5", GAR, true)
AICanCaptureCP("CP6", GAR, true)

--This defines the CPs. These need to happen first
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"}
cp6 = CommandPost:New{name = "CP6"}

--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}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)



conquest:Start()

herosupport:AddSpawnCP("CP1","CP1Spawn")
herosupport:AddSpawnCP("CP2","CP2Spawn")
herosupport:AddSpawnCP("CP3","CP3Spawn")
herosupport:AddSpawnCP("CP4","CP4Spawn")
herosupport:AddSpawnCP("CP5","CP5Spawn")
herosupport:AddSpawnCP("CP6","CP6Spawn")
herosupport:Start()

EnableSPHeroRules()

WeatherMode = math.random(1,4)

if WeatherMode == 1 then
ReadDataFile("dc:BFE\\sky.lvl", "nabsunrise")
elseif WeatherMode == 2 then
ReadDataFile("dc:BFE\\sky.lvl", "nabday")
elseif WeatherMode == 3 then
ReadDataFile("dc:BFE\\sky.lvl", "nabnight")
elseif WeatherMode == 4 then
ReadDataFile("dc:BFE\\sky.lvl", "nabcloud")
end
end


function ScriptInit()
if not ScriptCB_InMultiplayer() then
DecideHeroes(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
elseif ScriptCB_InMultiplayer() then
herostrCis = "cis_hero_darthmaul"
herostrRep = "rep_hero_obiwan"
end

StealArtistHeap(1200*1024)
-- Designers, these two lines *MUST* be first!
SetPS2ModelMemory(3100000)
ReadDataFile("ingame.lvl")




ReadDataFile("sound\\nab.lvl;nab2cw")
ReadDataFile("dc:SIDE\\comaat.lvl",
"cis_hover_aat")
ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_rocketeer",
"cis_inf_rifleman")
ReadDataFile("dc:SIDE\\rep.lvl",
"rep_inf_ep2_rocketeer",
"rep_inf_ep2_rifleman")
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper",
herostrRep,
supportstrRep,
"rep_walk_oneman_atst")

ReadDataFile("SIDE\\cis.lvl",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_officer",
"cis_inf_droideka",
herostrCis,
supportstrCis)

ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_laser")


ReadDataFile("SIDE\\gar.lvl",
"gar_inf_soldier")

SetupTeams{
rep = {
team = REP,
units = 32,
reinforcements = 150,
soldier = { "rep_inf_ep2_rifleman",9, 25},
assault = { "rep_inf_ep2_rocketeer",1, 4},
engineer = { "rep_inf_ep3_engineer",1, 4},
sniper = { "rep_inf_ep3_sniper",1, 4},
officer = {"rep_inf_ep3_officer",1, 4},
special = { "rep_inf_ep3_jettrooper",1, 4},

}
}
SetupTeams{
cis = {
team = CIS,
units = 32,
reinforcements = 150,
soldier = { "cis_inf_rifleman",9, 25},
assault = { "cis_inf_rocketeer",1, 4},
engineer = { "cis_inf_engineer",1, 4},
sniper = { "cis_inf_sniper",1, 4},
officer = {"cis_inf_officer",1, 4},
special = { "cis_inf_droideka",1, 4},
}
}
SetupTeams{
gar = {
team = GAR,
units = 5,
reinforcements = 50,
soldier = { "gar_inf_soldier",5},
}
}

AddUnitClass(CIS, supportstrCis, 1, 4)
AddUnitClass(REP, supportstrRep, 1, 4)

--if ScriptCB_InMultiplayer() then
--SetHeroClass(REP, herostrRep)
--SetHeroClass(CIS, herostrCis)
--else
--end

SetTeamAsEnemy(GAR, ATT)
SetTeamAsEnemy(ATT, GAR)


SetTeamAsFriend(GAR, DEF)
SetTeamAsFriend(DEF, GAR)

-- Level Stats
ClearWalkers()
AddWalkerType(0, 3) -- 8 droidekas with 0 leg pairs each
AddWalkerType(1, 3) -- ATSTs
local weaponCnt = 220
SetMemoryPoolSize("Aimer", 50)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 128)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 18)
SetMemoryPoolSize("EntitySoundStream", 1)
SetMemoryPoolSize("EntitySoundStatic", 44)
SetMemoryPoolSize("EntityHover", 4)
SetMemoryPoolSize("MountedTurret", 11)
SetMemoryPoolSize("Navigator", 40)
SetMemoryPoolSize("Obstacle", 450)
SetMemoryPoolSize("PathFollower", 40)
SetMemoryPoolSize("PathNode", 200)
SetMemoryPoolSize("TreeGridStack", 400)
SetMemoryPoolSize("UnitAgent", 40)
SetMemoryPoolSize("UnitController", 40)
SetMemoryPoolSize("Weapon", weaponCnt)
SetMemoryPoolSize("EntityFlyer", 6)

SetSpawnDelay(10.0, 0.25)
ReadDataFile("NAB\\nab2.lvl","naboo2_Conquest")
SetDenseEnvironment("true")
--AddDeathRegion("Water")
AddDeathRegion("Waterfall")
SetMaxFlyHeight(25)
SetMaxPlayerFlyHeight (25)



-- Sound

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "all_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
OpenAudioStream("sound\\nab.lvl", "nab2")
OpenAudioStream("sound\\nab.lvl", "nab2")
OpenAudioStream("sound\\nab.lvl", "nab2_emt")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 1)

SetLowReinforcementsVoiceOver(REP, REP, "rep_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(REP, CIS, "rep_off_victory_im", .1, 1)
SetLowReinforcementsVoiceOver(CIS, CIS, "cis_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(CIS, REP, "cis_off_victory_im", .1, 1)

SetOutOfBoundsVoiceOver(2, "repleaving")
SetOutOfBoundsVoiceOver(1, "cisleaving")

SetAmbientMusic(REP, 1.0, "rep_nab_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_nab_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2,"rep_nab_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_nab_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_nab_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2,"cis_nab_amb_end", 2,1)

SetVictoryMusic(REP, "rep_nab_amb_victory")
SetDefeatMusic (REP, "rep_nab_amb_defeat")
SetVictoryMusic(CIS, "cis_nab_amb_victory")
SetDefeatMusic (CIS, "cis_nab_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")






-- Camera Stats
--Nab2 Theed
--Palace
AddCameraShot(0.038177, -0.005598, -0.988683, -0.144973, -0.985535, 18.617458, -123.316505);
AddCameraShot(0.993106, -0.109389, 0.041873, 0.004612, 6.576932, 24.040697, -25.576218);
AddCameraShot(0.851509, -0.170480, 0.486202, 0.097342, 158.767715, 22.913860, -0.438658);
AddCameraShot(0.957371, -0.129655, -0.255793, -0.034641, 136.933548, 20.207420, 99.608246);
AddCameraShot(0.930364, -0.206197, 0.295979, 0.065598, 102.191856, 22.665434, 92.389435);
AddCameraShot(0.997665, -0.068271, 0.002086, 0.000143, 88.042351, 13.869274, 93.643898);
AddCameraShot(0.968900, -0.100622, 0.224862, 0.023352, 4.245263, 13.869274, 97.208542);
AddCameraShot(0.007091, -0.000363, -0.998669, -0.051089, -1.309990, 16.247049, 15.925866);
AddCameraShot(-0.274816, 0.042768, -0.949121, -0.147705, -55.505108, 25.990822, 86.987534);
AddCameraShot(0.859651, -0.229225, 0.441156, 0.117634, -62.493008, 31.040747, 117.995369);
AddCameraShot(0.703838, -0.055939, 0.705928, 0.056106, -120.401054, 23.573559, -15.484946);
AddCameraShot(0.835474, -0.181318, -0.506954, -0.110021, -166.314774, 27.687098, -6.715797);
AddCameraShot(0.327573, -0.024828, -0.941798, -0.071382, -109.700180, 15.415476, -84.413605);
AddCameraShot(-0.400505, 0.030208, -0.913203, -0.068878, 82.372711, 15.415476, -42.439548);

herosupport = AIHeroSupport:New{gameMode = "conquest",}
herosupport:SetHeroClass(REP, "herostrRep")
herosupport:SetHeroClass(CIS, "herostrCis")

end
Error log
Hidden/Spoiler:
uf_updateClassIndex(): Added class: herostrRep

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\LuaCallbacks_Mission.cpp(1379)
Hero class "herostrRep" not found for team 2 (check the side's .req file)

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\Team.cpp(658)
Team missing hero class "0xc3fcf04f" (check the side's .req file)
uf_updateClassIndex(): Added class: herostrCis

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\LuaCallbacks_Mission.cpp(1379)
Hero class "herostrCis" not found for team 1 (check the side's .req file)

Message Severity: 2
C:\Battlefront2\main\Battlefront2\Source\Team.cpp(658)
Team missing hero class "0x61a0d035" (check the side's .req file)
Right now the heroes do not appear and cannot be played as.

Sorry for multiple question threads, I'm just going into depths I've never been in before. :lol:

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 12:16 pm
by Teancum
My recommendation would be to add a bunch of print statements throughout your script so you can look in BFront2.log to determine where it breaks. For example:
Hidden/Spoiler:
function DecideHeroes(aalya, anakin, kiyadimundi, yoda, macewindu, obiwan, countdooku, yoda, darthmaul, grievous, jangofett)
Print("DecideHeroes() was called, executing...")
local herocis = countdooku + darthmaul + grievous + jangofett
local herorep = macewindu + aalya + anakin + kiyadimundi + obiwan + yoda

herostrCis = 0
herostrRep = 0
supportstrCis = 0
supportstrRep = 0

Print("Getting a random number for REP hero. That number is...")
local heroreprand = math.random(1, herorep)
Print(heroreprand)
if heroreprand <= macewindu then
herostrRep = "rep_hero_macewindu"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (aalya + macewindu) then
herostrRep = "rep_hero_aalya"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (anakin + aalya + macewindu) then
herostrRep = "rep_hero_anakin"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_kiyadimundi"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (obiwan + kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_obiwan"
supportstrRep = "rep_inf_ep3_rifleman"
elseif heroreprand <= (yoda + obiwan + kiyadimundi + anakin + aalya + macewindu) then
herostrRep = "rep_hero_yoda"
supportstrRep = "rep_inf_ep3_rifleman"
end
Print("REP hero is")
Print(herostrRep)
Print("REP support is")
Print(supportstrRep)

local herocisrand = math.random(1, herocis)


if herocisrand <= (countdooku) then
herostrCis = "cis_hero_countdooku"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (darthmaul + countdooku) then
herostrCis = "cis_hero_darthmaul"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (grievous + darthmaul + countdooku) then
herostrCis = "cis_hero_grievous"
supportstrCis = "cis_inf_marine"
elseif herocisrand <= (jangofett + grievous + darthmaul + countdooku) then
herostrCis = "cis_hero_jangofett"
supportstrCis = "cis_inf_marine"
end


end

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 12:34 pm
by Maveritchell
Does your mission.req load both archer's script and my script?

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 12:47 pm
by ARCTroopaNate
It loads both archers script and my mods script, which is based off of your script.

Tean, I tried what you said and it crashes now

Error log
Hidden/Spoiler:
Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call global `Print' (a nil value)
stack traceback:
(none): in function `DecideHeroes'
(none): in function `ScriptInit'

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 1:18 pm
by Webster27
Fix this "aalya" to "aayla" for a start :wink:

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 1:23 pm
by ARCTroopaNate
No thank you, Aalya is how pandemic spelled it, pandemic spelled it wrong. :lol:

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 1:24 pm
by willinator
Webster27 wrote:Fix this "aalya" to "aayla" for a start :wink:
Not necessarily, the makers of the game weren't very good at consistent spelling, so sometimes Aayla shows up as aayla or aalya. It's that way for a couple of other things I think.

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 1:44 pm
by Webster27
ARCTroopaNate wrote:No thank you, Aalya is how pandemic spelled it, pandemic spelled it wrong. :lol:
:faint: okay, me trying to be clever didn't work out :D. I looked at the ODF's and it was called Aalya :cpu:. Well then I don't really know, sorry.

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 4:13 pm
by Marth8880
ARCTroopaNate wrote:It loads both archers script and my mods script, which is based off of your script.

Tean, I tried what you said and it crashes now

Error log
Hidden/Spoiler:
Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call global `Print' (a nil value)
stack traceback:
(none): in function `DecideHeroes'
(none): in function `ScriptInit'
Spelling matters; it's "print", not "Print". For example:

Code: Select all

print("WHY THE HECK WON'T MY FREAKIN COMBAT DRONES WORK?!?!?")

Re: AI Hero Support with Random heroes

Posted: Wed Aug 29, 2012 8:10 pm
by ARCTroopaNate
Ok, I'll try, I just copied what Tean wrote, I guess I'll try with lowercase "p"s

EDIT: Tried it, map is no longer crashing but heroes still don't spawn and they're not playable.

New Error log (relevant part)
Hidden/Spoiler:
DecideHeroes() was called, executing...
Getting a random number for REP hero. That number is...
2
REP hero is
rep_hero_aalya
REP support is
rep_inf_ep3_rifleman
EDIT: Firefang helped me solve it, there were two unneeded quotations marks, boy is battlefront a silly penguin. :faint: