What's a jar.scar?
------------------------------------------------------------------ THIS SCRIPT WAS WRITTEN BY: jojorabbit------------------------------------------------------------------ Fix for AI using reward units aka jojorabbit`s AI reward unit fix aka jar------------------------------------------------------------------ @author: jojorabbit-- @version: v 1.0 b270412-- @filename: jar.scar-- This file fixes AI usage of reward units, in vCoH ai uses all or none reward units-- If you are gonna use this with other mod give me credits---------------------------------------------------------------------------------------------------------------------------------- REFERENCE------------------------------------------------------------------ ALLIED UPGRADES-- upgrade\upgrade_allied_105.lua-- upgrade\upgrade_allied_hellcat.lua-- upgrade\upgrade_allied_jumbo.lua-- upgrade\upgrade_allied_staghound.lua-- AXIS UPGRADES-- upgrade\upgrade_axis_geschutzwagen.lua-- upgrade\upgrade_axis_schwimmwagen.lua-- upgrade\upgrade_axis_tiger_ace.rgd-- upgrade\upgrade_axis_officer.rgd-- COMMONWEALTH UPGRADES-- upgrade\upgrade_british_comet.lua-- upgrade\upgrade_british_kangaroo.lua-- upgrade\upgrade_british_staghound.lua-- upgrade\upgrade_british_sas.lua -- THIS IS/(WILL BE) HANDLED IN aiutil.scar-- PANZER ELITE UPGRADES-- upgrade\upgrade_panzer_elite_hotchkiss.lua-- upgrade\upgrade_panzer_elite_jagdpanzer.lua-- upgrade\upgrade_panzer_elite_jagdtiger.lua-- upgrade\upgrade_panzer_elite_schwimmwagen.lua-- upgrade\upgrade_panzer_elite_nashorn.rgd-- SOVIET UPGRADES-- upgrade\upgrade_soviets_is3-- upgrade\upgrade_soviets_kv1-- upgrade\upgrade_soviets_su_122.rgd-- OSTHEER UPGRADES-- NONE TILL IT IS FINISHED------------------------------------------------------------------ INIT----------------------------------------------------------------function OnInit() print("JAR Init") AddRewardUnitsToAIPlayers()endScar_AddInit(OnInit)------------------------------------------------------------------ CONSTANTS----------------------------------------------------------------isDebug = true -- turn on/off logging-- ALLIESR_ALLIES_SHERMAN_105 = BP_GetUpgradeBlueprint("upgrade/upgrade_allied_105.lua")R_ALLIES_HELLCAT = BP_GetUpgradeBlueprint("upgrade/upgrade_allied_hellcat.lua")R_ALLIES_SHERMAN_JUMBO = BP_GetUpgradeBlueprint("upgrade/upgrade_allied_jumbo.lua")R_ALLIES_STAGHOUND = BP_GetUpgradeBlueprint("upgrade/upgrade_allied_staghound.lua")ALLIES_REWARD_UNITS = { R_ALLIES_SHERMAN_105, R_ALLIES_HELLCAT, R_ALLIES_SHERMAN_JUMBO, R_ALLIES_STAGHOUND,}-- AXISR_AXIS_GESCHUTZEWAGEN = BP_GetUpgradeBlueprint("upgrade/upgrade_axis_geschutzwagen.lua")R_AXIS_SCHWIMMWAGEN = BP_GetUpgradeBlueprint("upgrade/upgrade_axis_schwimmwagen.lua")R_AXIS_TIGER_ACE = BP_GetUpgradeBlueprint("upgrade/upgrade_axis_tiger_ace.lua")R_AXIS_LW_OFFICIER = BP_GetUpgradeBlueprint("upgrade/upgrade_axis_officer.lua")-- tableAXIS_REWARD_UNITS = { R_AXIS_GESCHUTZEWAGEN, R_AXIS_SCHWIMMWAGEN, R_AXIS_TIGER_ACE, R_AXIS_LW_OFFICIER,}-- COMMONWEALTHR_CW_COMET = BP_GetUpgradeBlueprint("upgrade/upgrade_british_comet.lua")R_CW_KANGAROO = BP_GetUpgradeBlueprint("upgrade/upgrade_british_kangaroo.lua")R_CW_STAGHOUND = BP_GetUpgradeBlueprint("upgrade/upgrade_british_staghound.lua")CW_REWARD_UNITS = { R_CW_COMET, R_CW_KANGAROO, R_CW_STAGHOUND,}-- PER_PE_HOTCHKISS = BP_GetUpgradeBlueprint("upgrade/upgrade_panzer_elite_hotchkiss.lua")R_PE_JAGDPANZER = BP_GetUpgradeBlueprint("upgrade/upgrade_panzer_elite_jagdpanzer.lua")R_PE_JAGDTIGER = BP_GetUpgradeBlueprint("upgrade/upgrade_panzer_elite_jagdtiger.lua")R_PE_SCHWIMMWAGEN = BP_GetUpgradeBlueprint("upgrade/upgrade_panzer_elite_schwimmwagen.lua")R_PE_NASHORN = BP_GetUpgradeBlueprint("upgrade/upgrade_panzer_elite_nashorn.lua")PE_REWARD_UNITS = { R_PE_HOTCHKISS, R_PE_JAGDPANZER, R_PE_JAGDTIGER, R_PE_SCHWIMMWAGEN, R_PE_NASHORN,}-- SOVR_SOV_IS3 = BP_GetUpgradeBlueprint("upgrade/upgrade_soviets_is3.lua")R_SOV_KV1 = BP_GetUpgradeBlueprint("upgrade/upgrade_soviets_kv1.lua")R_SOV_SU122 = BP_GetUpgradeBlueprint("upgrade/upgrade_soviets_su_122.lua")SOVIET_REWARD_UNITS = { R_SOV_IS3, R_SOV_KV1, R_SOV_SU122,}-- OST------------------------------------------------------------------ METHODS----------------------------------------------------------------function AddRewardUnitsToAIPlayers() for i = 1, World_GetPlayerCount() do local player = World_GetPlayerAt(i) -- only for AI players if(AI_IsEnabled(player)) then local race = Player_GetRaceName(player) LogOutput("AI race= "..race) -- ALLIES if(race == TRACE_ALLIES) then rewardTable = ALLIES_REWARD_UNITS -- AXIS elseif(race == TRACE_AXIS) then rewardTable = AXIS_REWARD_UNITS -- CW elseif(race == TRACE_ALLIES_COMMONWEALTH) then rewardTable = CW_REWARD_UNITS -- PE elseif(race == TRACE_AXIS_PANZER_ELITE) then rewardTable = PE_REWARD_UNITS -- SOV elseif(race == TRACE_ALLIES_SOVIETS) then rewardTable = SOVIET_REWARD_UNITS -- OST end if(rewardTable ~= nil) then LogOutput("rewardtable size "..#rewardTable) ApplyRewardUnits(player, rewardTable) end end endendfunction ApplyRewardUnits(player, rewardTable)--~ local rndTable = Table_GetRandomItem() local randomTest = World_GetRand(1, 100) LogOutput("Test: rnd= "..randomTest) for n = 1, table.getn(rewardTable) do local rnd = World_GetRand(1, 100) LogOutput("Test: "..n.." rnd= "..rnd) if((rnd % 2) == 0) then LogOutput("Activating - "..BP_GetName(rewardTable[n])) Command_PlayerUpgrade(player, rewardTable[n], true, false) end endendfunction LogOutput(message) if(isDebug) then print(message) endend
...import("NIS.scar")import("Debugger.scar")import("GarrisonBuilding.scar")import("jar.scar")...
Excellent! so if I download attached file and put it in folder - what will happen? Abit confused on how this works since I don't really understand your explanation sorry xD This will affect if AI will choose to build Jagdpanzer and not Hetzer?Also what about my earlier issue with command_tree_pref? Did you manage to see my attached file and see if I did anything wrong? Please help me on that.
Ahhh I see what you mean now that explains it better thanks jojo ^^ So will this file improve the chance that AI will build Jagdpanzer instead of Hetzer? Or is it still 50/50 chance? There's really no way at all to make AI 100% build Jagdpanzer instead of Hetzer by editing this file?Again I really appreciate the time you're taking and the help you're giving me in teaching a noob like me jojo. I don't mean to sound impatient but I'm sorry if I gave you that impression. It's just that when I get started on a new piece of work that I have no experience on, I am eager to learn and move forward. So since I am stuck with this error/AI still building other doctrines I get frustrated that something went wrong and I want to know how to fix it otherwise I feel unsettled like work is unfinished. Hope you understand how I feel ^^
for n = 1, table.getn(rewardTable) do local rnd = World_GetRand(1, 100) LogOutput("Test: "..n.." rnd= "..rnd) --if((rnd % 2) == 0) then -> this is commented -> %2 basically means 50%-50% chances LogOutput("Activating - "..BP_GetName(rewardTable[n])) Command_PlayerUpgrade(player, rewardTable[n], true, false) --end -> this is commented end
So to explain it simply, having AI choose 100% reward units won't be good and having AI 100% not choose reward units is also not good so I will have to stick with 50/50 chance in order to get the units I want. What I thought would be possible is just to single out AI to use jagdpanzer only not hetzer and the rest of the reward units can stay normal but I guess this is not possible since earlier in the thread you said it is not possible to force AI to build what you want, even though it's a single reward unit like Jagdpanzer instead of Hetzer, since it is all or nothing am I correct? ^^
if(race == TRACE_ALLIES) then rewardTable = ALLIES_REWARD_UNITS -- AXISelseif(race == TRACE_AXIS) then -- rewardTable = AXIS_REWARD_UNITS -> this needs to be commented. -- CWelseif(race == TRACE_ALLIES_COMMONWEALTH) then rewardTable = CW_REWARD_UNITS -- PE
-- AXIS elseif(race == TRACE_AXIS) then --rewardTable = AXIS_REWARD_UNITS -- commented cuz STUG IV UI_ForceCommanderTreeChoice(player, COMMANDER_TREE.AXIS.BLITZKRIEG) -- this is added -- CW elseif(race == TRACE_ALLIES_COMMONWEALTH) then rewardTable = CW_REWARD_UNITS -- PE elseif(race == TRACE_AXIS_PANZER_ELITE) then rewardTable = PE_REWARD_UNITS UI_ForceCommanderTreeChoice(player, COMMANDER_TREE.ELITE.TANK_DESTROYER) -- force tank d.
It was before but now AI can take 1...n reward units means Wehr AI could take only Geshutzewagen or only schwimmwagen or both.To make it simple.AI goes through all reward units and takes 50% chances that AI will choose reward unit.Before it was all reward units or none.
I wont explain this it is fixed in internal version as i told post ago, sometimes AI will choose 1...n units. You cant tell AI what units too build in late game, well you could make some sort of your AI mod
Oh I see you added new line of code! Is this in the jar.scar file that you sent me or in command_tree_pref.ai? The code looks different from the first file you told me to work on. So what will I do with the modified command_tree_pref.ai file?