Possible to tell AI to use a Supply Truck to help allies?

Information and discussion for custom maps and mods.
Post Reply
User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Mon Oct 15, 2018 8:26 pm

Hello,

my very first post in this forum.

I'am a modder and asking myself it is possible to tell an AI player somehow to sent a built Supply Truck to an allied building to help with money.
In the "Traits" for "HackyAI" on GitHub i cant find any trait that can possible make this happen, also in the Supply Truck actor itself i cant find a way cause it is not a form of "AutoTarget" because it has no armament.

Any suggestions or answers?

User avatar
Materianer
Posts: 161
Joined: Mon Jul 04, 2016 8:27 am

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Materianer » Tue Oct 16, 2018 6:43 am

I think its not possible to do it with changing the yaml but it should be possible if you make a lua file.
You can give actors a DeliverCash command there.
If your interested in i can help you

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Tue Oct 16, 2018 8:04 am

I thought/feared so that it is not possible with just yaml files.

My knowledge of lua is zero but it would be quite usefull to know, i also want to make AI units with the "DelicersExperience" trait to promote other units, so i would also need lua for that.

Yes, please help me out here :) or is there some tutorial site like "how to use lua in openra 101"?

abcdefg30
Posts: 297
Joined: Mon Aug 18, 2014 6:00 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by abcdefg30 » Fri Oct 19, 2018 5:21 pm

OpenRA's Lua API is detailed here: https://github.com/OpenRA/OpenRA/wiki/Lua-API
The rest is just normal Lua programming (http://lua-users.org/wiki/TutorialDirectory might be helpful).

User avatar
Materianer
Posts: 161
Joined: Mon Jul 04, 2016 8:27 am

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Materianer » Sat Oct 20, 2018 12:55 am

Sorry i'm working on a minigame at the moment and the end seem to be near, thats why i have not so much time.

I made an untested code for what you might need for what you try to do.

https://pastebin.com/vpuMR2K4

Note its untested and just an idea how it could work, you could also maybe try a Trigger.OnProduction or so maybe.


You're a modder i think it should be easy for you to dive into lua the possibilities are awesome if you go this way.

You could for example let the ai check wich of his allies has the lowest cash and support him then with the supply truck.

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Sat Oct 27, 2018 9:11 pm

abcdefg30 wrote:
Fri Oct 19, 2018 5:21 pm
OpenRA's Lua API is detailed here: https://github.com/OpenRA/OpenRA/wiki/Lua-API
The rest is just normal Lua programming (http://lua-users.org/wiki/TutorialDirectory might be helpful).
thanks for the Informations :)

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Sat Oct 27, 2018 9:18 pm

Materianer wrote:
Sat Oct 20, 2018 12:55 am
Sorry i'm working on a minigame at the moment and the end seem to be near, thats why i have not so much time.

I made an untested code for what you might need for what you try to do.

https://pastebin.com/vpuMR2K4

Note its untested and just an idea how it could work, you could also maybe try a Trigger.OnProduction or so maybe.


You're a modder i think it should be easy for you to dive into lua the possibilities are awesome if you go this way.

You could for example let the ai check wich of his allies has the lowest cash and support him then with the supply truck.
Thanks for the "Demo" :)

Well, iam IT-Technician in real life, which helps me to more easily understand certain things but i have no idea of Scripts or Programming Languages such as LUA.
My first glance at LUA is like "WHOA what the F...? i have no idea what that is about" :)
I don't know yet if i will put on the time and effort to learn LUA, altough it would be exceptionally usefull for Modding, especially for custom AI experience which is exactly what i would need to boost the quality of my Mod.

Time will show ;)

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Thu Nov 01, 2018 9:30 pm

i checked the code and its not working.

but

i startet to read some LUA tutorial pages and i'm on it to get it to work! :)

Tried to change some values in it but it still does not do anything, i'm not gicing up yet :)


EDIT: HELL YEAH the code is working! i found out what i was doing wrong and i got an understanding of how and why the code works. Thanks a bunch :) now i can build on top of the code and do some additional stuff.

one last question, is it only possible for a single map to do these scripts or also for any map you are playing, or in other words for the whole game/mod?

User avatar
MustaphaTR
Posts: 195
Joined: Mon Aug 04, 2014 6:38 am
Location: Kastamonu, Turkey

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by MustaphaTR » Fri Nov 02, 2018 7:58 am

You can edit the mod to have the LuaScript: trait on world.yaml. I handle the General's Powers in Generals Alpha and AI in Sole Survivor mods this way and this makes all the maps to read the lua. In that case .lua file should be in bits folder.

Tho if a map overrides LuaScript: trait, you may need to manually add the new file for AI there too.

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Fri Nov 02, 2018 11:19 am

when i put the code in to a lua and attatch it to the "world.yaml" with "World: LuaScript: Scrits: test.lua" and put the "test.lua" file in the "bits" or any other directory i get an error log:

Fatal Lua Error:
Stack Traceback
===============
(2) global C function 'error'
(3) Lua function '(anonymous)' at file 'C:\Program Files (x86)\OpenRA\/lua/sandbox.lua:150' (best guess)
Local variables:
arg = nil
ok = boolean: false
result = string: "[string \"test.lua\"]:4: attempt to index global 'Multi0' (a nil value)"
(4) tail call
(5) Lua function '?' at line 23 of chunk '"scriptwrapper.lua"]'
(6) global C function 'xpcall'
(7) Lua upvalue 'TryRunSandboxed' at line 23 of chunk '"scriptwrapper.lua"]'
Local variables:
fn = Lua function '?' (defined at line 20 of chunk "test.lua"])
(8) Lua function '?' at line 31 of chunk '"scriptwrapper.lua"]'

Error message
===============
C:\Program Files (x86)\OpenRA\/lua/sandbox.lua:150: [string "test.lua"]:4: attempt to index global 'Multi0' (a nil value)
===============
bei OpenRA.Scripting.ScriptContext.FatalError(String message)
bei System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
bei System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
bei Eluant.LuaRuntime.MethodWrapper.Invoke(Object[] parms)
bei Eluant.LuaRuntime.MakeManagedCall(IntPtr state, MethodWrapper wrapper)
bei Eluant.LuaRuntime.MethodWrapperCallCallback(IntPtr state)
bei Eluant.LuaRuntime.MethodWrapperCallCallbackWrapper(IntPtr state)
bei Eluant.LuaApi.lua_pcall(IntPtr L, Int32 nargs, Int32 nresults, Int32 errfunc)
bei Eluant.LuaRuntime.Call(IList`1 args)
bei Eluant.LuaRuntime.Call(LuaFunction fn, IList`1 args)
bei Eluant.LuaFunction.Call(IList`1 args)
bei OpenRA.Scripting.ScriptContext.WorldLoaded()
bei OpenRA.Mods.Common.Scripting.LuaScript.OpenRA.Traits.IWorldLoaded.WorldLoaded(World world, WorldRenderer worldRenderer)
bei OpenRA.World.LoadComplete(WorldRenderer wr)
bei OpenRA.Game.StartGame(String mapUID, WorldType type)
bei OpenRA.Game.LoadShellMap()
bei OpenRA.Mods.Common.LoadScreens.BlankLoadScreen.StartGame(Arguments args)
bei OpenRA.Game.InitializeMod(String mod, Arguments args)
bei OpenRA.Game.Initialize(Arguments args)
bei OpenRA.Game.InitializeAndRun(String[] args)
bei OpenRA.WindowsLauncher.RunGame(String[] args)
bei OpenRA.WindowsLauncher.Main(String[] args)

abcdefg30
Posts: 297
Joined: Mon Aug 18, 2014 6:00 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by abcdefg30 » Fri Nov 02, 2018 12:01 pm

Yes, not every map (the shellmaps in particular) have a player called "Multi0". You need to make sure that player actually exists (just test if the variable is NIL after using 'Multi0 = Player.GetPlayer("Multi0")').

User avatar
Zeruel87
Posts: 7
Joined: Mon Oct 15, 2018 8:18 pm

Re: Possible to tell AI to use a Supply Truck to help allies?

Post by Zeruel87 » Sat Nov 03, 2018 8:52 am

i dont get it... if i put the lua into a single map the code works.
if i put it into the bits folder so it applies to the whole mod / all maps then it crashes with the error message i postet.
is there something to rewrite if you put it for the whole mod?


EDIT: i just testet it again and it worked... i did not notice what i did wrong, but my guess is when i copied the code again there were Spaces at the beginning instead of Tabs... well, some beginners failure :P

the only thing thats left is, when i start the game the background music changes to the error music, i need to find a way to fix that.
to be exactly, when i enter the Main Menu the background music changes to to the error music.

Post Reply