Hi fellow scripters. Here is a source from Tajii and his Battlefield Balance.
https://www.twcenter.net/forums/show...1#post16074388
Hi fellow scripters. Here is a source from Tajii and his Battlefield Balance.
https://www.twcenter.net/forums/show...1#post16074388
Hi! Got another question for battle scripting.
Is there any way to know attribute of particular unit on battlefield, not only it's presence in army by I_BattleEnemyArmyNumberOfAttribute?
A particular unit, whats this mean? You can test with I_BattlePlayerArmyNumberOfAttribute as well.
Unless I misremember, you can also create a custom made up attribute for the unit (e.g. for french knights, create an attribute french_knights; it will do nothing except act as your script label). So this may be what you mean by particular unit.
If you mean a special specific unit that you recruited from a specific town 15 turns ago, and you want to differentiate it from another similar unit that you recruited 10 turns ago. Then I don't know how to do that, maybe there's a way using the new M2TW reverse engineered method.
I just checked the discord and see something which looks promising for the strat map (to find a specific unit).
Code:require('myconfigs') local selectedStack=nil; local selectedUnit=nil; function makeReplacement(unit) if(selectedUnit~=nil and unit.character~=nil) then print("Test replacement done!") unit.character:setBodyguardUnit(selectedUnit); end selectedUnit=unit; end function draw(device) if(selectedStack==nil) then do return end end ImGui.SetNextWindowSize(500, -1); local isOpen=true; isOpen=ImGui.Begin("bodyguard",isOpen,ImGuiWindowFlags.NoDecoration); if(selectedUnit~=nil) then ImGui.Text("You select for replacement: "..selectedUnit.eduEntry.Type.."\n Now select unit with character"); end if(ImGui.Button("Reset selection!")) then selectedUnit=nil; selectedStack=nil; end if(selectedStack~=nil) then local soldiersNum=selectedStack.numOfUnits; for i = 0, soldiersNum-1 do local unit = selectedStack:getUnit(i); ImGui.PushID(i); if(ImGui.Button(unit.eduEntry.Type)) then makeReplacement(unit); end ImGui.PopID() end end ImGui.End(); end function onCharacterSelected(namedCharacter) selectedStack=namedCharacter.character.armyLeaded; end
The AI Workshop Creator
Europa Barbaroum II AI/Game Mechanics Developer
The Northern Crusades Lead Developer
Classical Age Total War Retired Lead Developer
Rome: Total Realism Animation Developer
RTW Workshop Assistance MTW2 AI Tutorial & Assistance
Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)
Thanks for answering and Happy New Year!
No, I need to match unit's attribute while labelling it to make some scripted things during battle. At the moment I find only a way to check if current unit is missile unit or not. It's possible to check unit by unit for missile capability.
But attribute conditions works only for entire army.
How I want to use this? Stakes attribute could be useful, and mercenary_unit too, if we speak about vanilla ones.
I'm finishing my BAI patch for my TrueGeneral project, I surrendered to teach BAI config files to hold positions during defender role (missile units and skirmishers and sometimes the whole army starting to attack from the very beginning of the defending battle). I did it in general, but now I see some additional possibilities to make such script really interesting and realistic.
Well one big problem I never really tried to solve with battle scripting is that armies are labelled a bit randomly (according to playtesters), army 1 (apparently) can be human or ai. It isn't always the human army. This is just based on feedback from playtesters. I find it believable though.
A lot of things with battle scripting seem broken, I think it is because it was meant for historical battles mainly.
The AI Workshop Creator
Europa Barbaroum II AI/Game Mechanics Developer
The Northern Crusades Lead Developer
Classical Age Total War Retired Lead Developer
Rome: Total Realism Animation Developer
RTW Workshop Assistance MTW2 AI Tutorial & Assistance
Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)
In my experience AI army is defender by default, so if both armies are "attacker" in prebattle armies menu, then human army is attacker and AI is defender.
Also maybe it's obvious but I had to check it to be sure - engine count units in order of unit cards placed in army roster, not their placement on battlefield in formation.
As for my purpose - I_UnitTypeSelected is functional, even if unit name has more than one word in naming. It's a bit complicated to script all units type by type, so I think I can use condition which matches special ability. I want to script some specific things for mercenaries in player's army.
Also - there's an internal battle analyser in .exe, with operators like "WE_MISSILE/THEY_MISSILE" and so on. I suppose it's not functional, so I want to use one that scripted by myself.
I got same issue with labelling, when Player's army set to formation supposed to AI in battle, I had to change the code and seems that Player's army is always 0 and AI army is always 1, doesn't matter who is attacker and defender. At least in field open battles. Now all formations are designated correctly in my script.
First draft of my TrueGeneral Beta in EBII battle on medium difficulty
I see that every BAI should be adapted to particular mod because of difference in EDU parameters for units which have great influence on final performance.
Ok, I've spent this year in BAI coding, got some good progress and now I can say we have 4 different cases in battle labelling.
First is custom battle, when Player is always army 0 and Enemy is army 1. Also additional armies doesn't activate ReinforcementsArrived event, because they're already on the battlefield during placement phase.
Second case is regular campaign battle, when Player army is Attacker/Defender - it's a typical G5 script case. This way Player in attack is army 0, Enemy is army 1 and vise versa. Additional armies are coming as Reinforcements by event and could be matched after each event fires (every reinf army has it's own event).
Third case is situation when Player army comes to help to ally - in this case ally army is 0 0/1 0 army in Attack/Defend situation and Player is 0 1/1 1. I'm finding a campaign script method to verify this situation, looks like we need to match PreBattlePanelOpen event when AI attacks non local target.
And the last thing is Siege battles - it's similar to custom, when all armies are on the battlefield from the placement phase and Reinforcement event doesn't fire. But in difference between custom we have to match Player's army role as attacker/defender.
And one more thing - Ambush, there's no deployment phase so we have to label armies previously in the very beginning of I_InBattle condition. Same as Sally Out.