Page 1 of 2

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

Posted: Mon Oct 15, 2018 8:26 pm
by Zeruel87
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?

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

Posted: Tue Oct 16, 2018 6:43 am
by Materianer
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

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

Posted: Tue Oct 16, 2018 8:04 am
by Zeruel87
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"?

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

Posted: Fri Oct 19, 2018 5:21 pm
by abcdefg30
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).

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

Posted: Sat Oct 20, 2018 12:55 am
by Materianer
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.

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

Posted: Sat Oct 27, 2018 9:11 pm
by Zeruel87
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 :)

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

Posted: Sat Oct 27, 2018 9:18 pm
by Zeruel87
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 ;)

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

Posted: Thu Nov 01, 2018 9:30 pm
by Zeruel87
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?

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

Posted: Fri Nov 02, 2018 7:58 am
by MustaphaTR
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.

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

Posted: Fri Nov 02, 2018 11:19 am
by Zeruel87
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)

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

Posted: Fri Nov 02, 2018 12:01 pm
by abcdefg30
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")').

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

Posted: Sat Nov 03, 2018 8:52 am
by Zeruel87
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.

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

Posted: Fri Nov 16, 2018 6:44 pm
by Zeruel87
I'am clueless, any idea or help please.

does the error music in the main menu come from the fact that i don't have a shellmap? does this produce the error causing the error music?

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

Posted: Sat Nov 17, 2018 12:56 pm
by Zeruel87
i did look at the "blank-shellmap" map.yaml file and added the "multi0" to "Players:", the error music still occurs after a few seconds and the "lua.log" is plain empty


in the debug-log i find this, is this maybe the cause?

scores.mix: failed to resolve filenames for 4 unknown hashes
Found 2 domains for movement class 431 on map Blank Shellmap.
Found 1 domains for movement class 2048 on map Blank Shellmap.
Found 2 domains for movement class 2491 on map Blank Shellmap.
Found 1 domains for movement class 0 on map Blank Shellmap.

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

Posted: Sat Nov 17, 2018 1:43 pm
by Zeruel87
OKAY I GOT IT !

1. thing was - YES i needed to add "multi0" into the map.yaml of the shellmap
2. thing is i added "MusicPlaylist: -DefeatMusic:" also to the shellmap, now everything is as i wanted it to be :)

I Have to say:

Thank you all for your help big time :)

Thanks Materianer
Thanks abcdefg30
Thanks MustaphaTR