Madin 10 Posted December 31, 2015 I am trying out ways to get the AI to load infantry into transports (ie Missile squads into the GDI APC). The lua attempt is not looking good. I just tried the 'GrabPassenger' special power, but that is not working (probably because they got rid of the 'SpecialPowerType' enum. Needless to say, the 'AutoPickUpUpdate' also does not work. Any ideas on how I could do this? Share this post Link to post
Ravendark 43 Posted December 31, 2015 cheesy it? AI only upgrade(maybe dependant on easy, medium, hard etc ai) that changes the commandset of the warfactory into one that has a apc pre loaded with missile squads. This will make it look like the ai loads apc's. Share this post Link to post
Lauren 77 Posted January 1, 2016 When you tried the GrabPassenger, did you also add an AISpecialPowerUpdate for it? Share this post Link to post
Madin 10 Posted January 1, 2016 When you tried the GrabPassenger, did you also add an AISpecialPowerUpdate for it? Yes I did (I used 'BUFF_ALLY'). However I tested if the support power would work for me the player, and it didn't. Share this post Link to post
Madin 10 Posted January 3, 2016 Units created using the 'TransportContain' 'UpgradeCreation' element, cannot fire from a transport or be ejected from the transport. <xs:complexType name="UpgradeCreation"> <xs:sequence></xs:sequence> <xs:attribute name="Upgrade" type="UpgradeTemplateRef" /> <xs:attribute name="Template" type="GameObjectWeakRef" /> <xs:attribute name="Num" type="SageUnsignedInt" /> </xs:complexType> Share this post Link to post
Madin 10 Posted May 28, 2017 This is a bumping of this old issue. I feel that there is a lot more that has been done with LUA over the past year and a half, so I figured that it might worth getting some fresh input on this. Please check the opening post of this thread for some background information. Getting AI infantry squads to enter a transport if it is close (if possible being able to exclude certain infantry from entering transports), and finally getting the AI transport to eject passengers when its health reaches 'REALLYDAMAGED'. This is so the AI can make use of transports that allow passengers to fire their weapon, it is not about getting the AI to pick up, and drop off passengers intelligently. Share this post Link to post
Madin 10 Posted May 30, 2017 (edited) My test transport has this Script events code: <ModelConditionEvent Name="TransportEmpty"> <Conditions>-MOVING -LOADED</Conditions> </ModelConditionEvent> <!-- Just -LOADED does not work! --> <ScriptedEvent Name="TransportIsEmpty" /> <!-- Transport has space! --> <EventList Name="SovietHalfTrackFunctions" Inherit="BaseScriptFunctions"> <EventHandler EventName="OnCreated" ScriptFunctionName="OnSovietHalfTrackCreated" DebugSingleStep="false"/> <EventHandler EventName="TransportEmpty" ScriptFunctionName="OnSovietHalfTrackEmpty" DebugSingleStep="false"/> </EventList> My Transports script.lua: function OnSovietHalfTrackEmpty(self) ObjectBroadcastEventToAllies(self, "TransportIsEmpty", 200) -- "I have a space, get inside!" ExecuteAction("SHOW_MILITARY_CAPTION", "HALFTRACK_EMPTY", 5) end The test infantry squad has this simple set up: <EventList Name="SovietConscriptFunctions" Inherit="BaseScriptFunctions"> <EventHandler EventName="TransportIsEmpty" ScriptFunctionName="SovietConscriptEnterTransport" DebugSingleStep="false"/> </EventList> <!-- Received from transport! --> function SovietConscriptEnterTransport(self,other) -- ExecuteAction("NAMED_STOP",self) ExecuteAction("NAMED_ENTER_NAMED", self, other) -- "OK, I am going in!" ExecuteAction("SHOW_MILITARY_CAPTION", "GETTING_IN_TRANSPORT", 5) end The transports broadcast is sent and received, but infantry squad does not budge! I fear my LUA code is too simple. Edited May 30, 2017 by Madin 1 Share this post Link to post
Lauren 77 Posted May 31, 2017 Is the script called by the squad or squad members? Share this post Link to post
Madin 10 Posted May 31, 2017 7 hours ago, Lauren said: Is the script called by the squad or squad members? By the squad. Share this post Link to post
Ravendark 43 Posted May 31, 2017 I think the problem could be with -MOVING -LOADED conditions. The transition from MOVING into not MOVING gets covered by -MOVING. But you basically have no transition from LOADED to empty as you need it to trigger -LOADED. Because your transport isn't LOADED to start with it doesn't trigger -LOADED. You might be better of trying only -MOVING as a event conditions and use TestModelcondition LOADED =/= 1 instead in your script. Share this post Link to post
Egozi44 27 Posted May 31, 2017 (edited) A bit unrelated as it has nothing to do with apcs ;p In KW there's a snowy map (forgot it name) which the Tib spikes are on a hill that you can only approach if you use air transport, that not stops the AI from getting them, while I never bothered to view the replays of how it does it I assume it either use transport (may just be a script in that specific map) or either it cheat it way to it, may be worth a check, unless you already tested it decade ago... Edited May 31, 2017 by Egozi44 Share this post Link to post
Madin 10 Posted May 31, 2017 5 hours ago, Ravendark said: I think the problem could be with -MOVING -LOADED conditions. The transition from MOVING into not MOVING gets covered by -MOVING. But you basically have no transition from LOADED to empty as you need it to trigger -LOADED. Because your transport isn't LOADED to start with it doesn't trigger -LOADED. You might be better of trying only -MOVING as a event conditions and use TestModelcondition LOADED =/= 1 instead in your script. In terms of cleaning the code up, you are right. However the Lua is being sent and received, it is just that the infantry do not do anything (I have messages to show if the script completes). Share this post Link to post
Stygs 25 Posted May 31, 2017 Might be a long shot, but there are a couple of similiar functions in BFME (similiar in the sense that Unit A reacts to a ObjectBroadcastEvent from Unit B ) and the LUA is allways triggered by the squad members, not the squad object itself. Share this post Link to post
Madin 10 Posted May 31, 2017 11 minutes ago, Stygs said: Might be a long shot, but there are a couple of similar functions in BFME (similar in the sense that Unit A reacts to a ObjectBroadcastEvent from Unit B ) and the LUA is always triggered by the squad members, not the squad object itself. Thanks! I tried that, but it made no difference. I also tried it on an individual unit (Engineer), and it still did nothing. Share this post Link to post
Stygs 25 Posted May 31, 2017 I am no LUA expert, but that kinda sounds like the unit might not know what the "other" parameter refers to. Have you tried ExecuteAction("NAMED_DELETE", other) (or somethnig else) to test of the truck is correctly identified? 1 Share this post Link to post
Madin 10 Posted May 31, 2017 12 minutes ago, Stygs said: I am no LUA expert, but that kinda sounds like the unit might not know what the "other" parameter refers to. Have you tried ExecuteAction("NAMED_DELETE", other) (or something else) to test of the truck is correctly identified? Good idea. I used "NAMED_ATTACK_NAMED" instead of "NAMED_DELETE", and sure enough the infantry attacked the transport. Share this post Link to post
Mjjstral 25 Posted May 31, 2017 (edited) Some quick untested additons: PassengerTable={} function OnReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)],1 do ExecuteAction("NAMED_EXIT_ALL",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end function SovietConscriptEnterTransport(self,other) -- ExecuteAction("NAMED_STOP",self) if PassengerTable[tostring(self)] == nil then PassengerTable[tostring(self)]={} end tinsert(PassengerTable[tostring(self)],other) ExecuteAction("UNIT_AI_TRANSFER",self,0) --stop ai interference (optional) ExecuteAction("NAMED_ENTER_NAMED", self, other) ExecuteAction("SHOW_MILITARY_CAPTION", "GETTING_IN_TRANSPORT", 5) end function OnSovietHalfTrackEmpty(self) if GetHealth(self) > 25 then --and not EvaluateCondition("UNIT_HAS_PASSENGER",GetObj.String(self)) --optional ObjectBroadcastEventToAllies(self, "TransportIsEmpty", 200) ExecuteAction("SHOW_MILITARY_CAPTION", "HALFTRACK_EMPTY", 5) end end CompareTable = { LT=0, LE=1, EQ=2, GE=3, GT=4, NE=5, ["<"]=0, ["<="]=1, ["=="]=2, [">="]=3, [">"]=4, ["~="]=5 } function GetHealth(object) object=GetObj.String(object) for i=1,101,1 do if EvaluateCondition("UNIT_HEALTH",object,CompareTable["<"],i) then return i-1 end end return 0 end Edited May 31, 2017 by Mjjstral 1 Share this post Link to post
Madin 10 Posted June 1, 2017 Thanks again! This is still not working, exact same issues as before (message is sent and received, but the infantry does not budge). Share this post Link to post
Madin 10 Posted June 1, 2017 (edited) OK I tried my original rubbish code with the "GetObj.String(other) and GetObj.String(self) instead of other and self ", and it worked! So I will try and integrate that into your improved code (I wonder if there are other issues I have been having that might be solved by this, like certain special powers not working...). Edited June 1, 2017 by Madin 1 Share this post Link to post
Mjjstral 25 Posted June 1, 2017 This is really interesting and yes this will also probably solve your problem with ExecuteAction("NAMED_FIRE_SPECIAL_POWER_AT_NAMED",...) in the other thread. I think at least the argument for other must be a string named object. Good to know. Share this post Link to post
Madin 10 Posted June 1, 2017 It is interesting! The only issue I am having with your code is that this part breaks my scripts lua: function OnReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)],1 do ExecuteAction("NAMED_EXIT_ALL",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end This stops the other scripts from working, just by being there (ie it does not need to be triggered by the 'REALLYDAMAGED' state). Can you see anything wrong? (it does not output an error). Share this post Link to post
Mjjstral 25 Posted June 1, 2017 Ah sorry bracket was't closed (syntax error): function OnReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)]),1 do ExecuteAction("NAMED_EXIT_ALL",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end Important: Put the error function I gave you above all custom code, because if there is a syntax error above it doesn't even get loaded! 1 Share this post Link to post
Madin 10 Posted June 1, 2017 6 minutes ago, Mjjstral said: Ah sorry bracket was't closed (syntax error): function OnReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)]),1 do ExecuteAction("NAMED_EXIT_ALL",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end Important: Put the error function I gave you above all custom code, because if there is a syntax error above it doesn't even get loaded! OK got it, thanks! I'll do stress testing with the AI at a future date, on to the next issue! Share this post Link to post
Madin 10 Posted November 12, 2017 <EventList Name="SovietHalfTrackFunctions" Inherit="BaseScriptFunctions"> <EventHandler EventName="OnCreated" ScriptFunctionName="OnSovietHalfTrackCreated" DebugSingleStep="false"/> <EventHandler EventName="TransportEmpty" ScriptFunctionName="OnSovietHalfTrackEmpty" DebugSingleStep="false"/> <EventHandler EventName="ReallyDamaged" ScriptFunctionName="OnSovietHalfTrackReallyDamaged" DebugSingleStep="false"/> </EventList> function OnSovietHalfTrackReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)]),1 do ExecuteAction("NAMED_EXIT_ALL",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end The squad being ejected on 'REALLY_DAMAGED' does not work (the squad entering the transport works though!). Share this post Link to post
Mjjstral 25 Posted November 13, 2017 19 hours ago, Madin said: The squad being ejected on 'REALLY_DAMAGED' does not work (the squad entering the transport works though!). I found the error: "NAMED_EXIT_ALL" gives a command to the transporter to thorw out it's inmates. So becomes much more simple: function OnSovietHalfTrackReallyDamaged(self) --add the lua event to scriptevents.xml too ExecuteAction("NAMED_EXIT_ALL",self) if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)]),1 do ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end If you want to give the exit commands to the inmates one by one you can use this: function OnSovietHalfTrackReallyDamaged(self) --add the lua event to scriptevents.xml too if PassengerTable[tostring(self)] == nil then return end for i=1,getn(PassengerTable[tostring(self)]),1 do ExecuteAction("NAMED_EXIT_BUILDING",PassengerTable[tostring(self)][i]) ExecuteAction("UNIT_AI_TRANSFER",PassengerTable[tostring(self)][i],1) --enable ai in case it was disabled end PassengerTable[tostring(self)]=nil end So to sum up: "NAMED_EXIT_ALL" = command for object harboring units, "NAMED_EXIT_BUILDING" = command for units within transporters (or buildings). 1 Share this post Link to post