How to add random AI controlled heroes to your map (FAQ)
Posted: Tue Jun 23, 2009 8:37 pm
Even though Mav semi covered this in his DT tutorial this is just to add random AI controlled heroes to any SP map.
This requires a basic knowledge of scripting and how to add in units but otherwise not much else.
Note when I refer to .lua I am referring too abcc_con.lua or abcg_con.lua found in data_abc/common/scripts/abc abc=mod3 letter name
First download archer01's hero support script and read all the readmes and add in the hero support lines to your .lua
so now your script (relavent parts should look like this)
Remember
9- Now this is a VERY important part, the "SetHeroClass" function can only be used once for each team. If it is used a second time, nasty stuff will likely happen. Go through the script and remove all uses of the "SetHeroClass" function, except for the two you added earlier of course, so there won't be any problems. Your final script should have at most only two (2) mentions of "SetHeroClass". Don't forget about your text editor's search function when making sure this is so.
Now as of this point there should be AI controlled heroes running around your map but they should only be the ones that you called from the cis and rep side and put in the hero support script here
herosupport:SetHeroClass(REP, "rep_hero_nameofhero")
herosupport:SetHeroClass(CIS, "cis_hero_nameofhero")
Now for the randomness...
If you take math or know math at all you are familiar with probability and the nCr (read n choose r) function defined as n!/r!(n-r)! anyway done with the math lesson we will be using a .lua function which does just this
it is called math.random now you need to decide how many random heroes you would like in your map for the sake of this tutorial we will have 3
this script will tell the game how many heros we want paste this into the .lua right under
function ScriptPostLoad()
what this does is assign each hero to a number 1, 2, or 3 then it tells the game to pick one of those numbers for each team and that is the hero
this can be adapted for ALL and IMP just add this in instead
again this can be adapted for more than 3 heros just add more numbers
ie heroimpand = math.random(1, #) #=integer >1 and then add
elseif heroimpand == # then
heroImp = "imp_hero_heroname3" for the number of numbers you have (make it so it looks like the rest of the hero calls above it)
now this script isn't done yet you must call your heros with the hero support script
change these lines
herosupport:SetHeroClass(REP, "rep_hero_nameofhero")
herosupport:SetHeroClass(CIS, "cis_hero_nameofhero")
to
herosupport:SetHeroClass(CIS, heroCis)
herosupport:SetHeroClass(REP, heroRep)
this will tell the .lua to apply hero support on the hero that pops out of our random function
now we must make sure that the map will work in MP random heroes will crash multiplayer so we must add if not ScriptCB_InMultiplayer() then above where the hero support starts
all and all it should look like this
pay attention to the ends at the end there should be 2 of them
now since there are only heroes during SP how about adding them in MP (they will not be random)
copy these lines
if ScriptCB_InMultiplayer() then
heroCis = "cis_hero_heroname"
heroRep = "rep_hero_heroname"
end
right under
ReadDataFile("ingame.lvl")
you can pick any hero you want to be here it will just not be random
now lastly under where the setupteams section is add in the hero lines that you prieviously deleted for acher's script
all and all it should look like this under where the cis units are called
this will allow heroes to appear in multiplayer and not crash multiplayer
the final script will look like this
That is pretty much it just make sure that you have all 3 heroes called or however many you want.
Just a note this will cause the hero to appear below the last unit on the select screen so if you have 7 units it will appear somewhat off the screen this cannot be fixed.
If you have any questions email me at yankfan1950 at gmail dot com or just PM me here at GT if you use this credit Maveritchell for the TFU herosupport script which is what this is based of of Archer01 for his script and I would like credit as well for putting it all together
This requires a basic knowledge of scripting and how to add in units but otherwise not much else.
Note when I refer to .lua I am referring too abcc_con.lua or abcg_con.lua found in data_abc/common/scripts/abc abc=mod3 letter name
First download archer01's hero support script and read all the readmes and add in the hero support lines to your .lua
so now your script (relavent parts should look like this)
Hidden/Spoiler:
9- Now this is a VERY important part, the "SetHeroClass" function can only be used once for each team. If it is used a second time, nasty stuff will likely happen. Go through the script and remove all uses of the "SetHeroClass" function, except for the two you added earlier of course, so there won't be any problems. Your final script should have at most only two (2) mentions of "SetHeroClass". Don't forget about your text editor's search function when making sure this is so.
Now as of this point there should be AI controlled heroes running around your map but they should only be the ones that you called from the cis and rep side and put in the hero support script here
herosupport:SetHeroClass(REP, "rep_hero_nameofhero")
herosupport:SetHeroClass(CIS, "cis_hero_nameofhero")
Now for the randomness...
If you take math or know math at all you are familiar with probability and the nCr (read n choose r) function defined as n!/r!(n-r)! anyway done with the math lesson we will be using a .lua function which does just this
it is called math.random now you need to decide how many random heroes you would like in your map for the sake of this tutorial we will have 3
this script will tell the game how many heros we want paste this into the .lua right under
function ScriptPostLoad()
Hidden/Spoiler:
this can be adapted for ALL and IMP just add this in instead
Hidden/Spoiler:
ie heroimpand = math.random(1, #) #=integer >1 and then add
elseif heroimpand == # then
heroImp = "imp_hero_heroname3" for the number of numbers you have (make it so it looks like the rest of the hero calls above it)
now this script isn't done yet you must call your heros with the hero support script
change these lines
herosupport:SetHeroClass(REP, "rep_hero_nameofhero")
herosupport:SetHeroClass(CIS, "cis_hero_nameofhero")
to
herosupport:SetHeroClass(CIS, heroCis)
herosupport:SetHeroClass(REP, heroRep)
this will tell the .lua to apply hero support on the hero that pops out of our random function
now we must make sure that the map will work in MP random heroes will crash multiplayer so we must add if not ScriptCB_InMultiplayer() then above where the hero support starts
all and all it should look like this
Hidden/Spoiler:
now since there are only heroes during SP how about adding them in MP (they will not be random)
copy these lines
if ScriptCB_InMultiplayer() then
heroCis = "cis_hero_heroname"
heroRep = "rep_hero_heroname"
end
right under
ReadDataFile("ingame.lvl")
you can pick any hero you want to be here it will just not be random
now lastly under where the setupteams section is add in the hero lines that you prieviously deleted for acher's script
all and all it should look like this under where the cis units are called
Hidden/Spoiler:
the final script will look like this
Hidden/Spoiler:
That is pretty much it just make sure that you have all 3 heroes called or however many you want.
Just a note this will cause the hero to appear below the last unit on the select screen so if you have 7 units it will appear somewhat off the screen this cannot be fixed.
If you have any questions email me at yankfan1950 at gmail dot com or just PM me here at GT if you use this credit Maveritchell for the TFU herosupport script which is what this is based of of Archer01 for his script and I would like credit as well for putting it all together