the code hits the following error: attempt to call method 'GetPosition' (a nil value)
Should have been called on initialAgent (the hero unit), rather than agent (a tracking table somewhere in the HeroGOAP mess). My bad.
Also, I just realized that the function I gave you won't work universally for both squad and solo attack, so here's a new CalculateWeights for each: http://pastebin.com/TD6JL0QG
oh - one more coding request if you think of it. I want to be able to evaluate if a flag is already locked. Currently, the AI seems to spam locks even if one is already on there... doesn't happen 100% of the time. Anyway, I've been working on the coding to improve the flag lock logic and this is would be a useful piece of code. Thx
This should be very simple - replace the existing 'if table.empty(flags) then' block with this, in both the InstantStatusFunction and ActionFunction: http://pastebin.com/M5KRKy2r
Edit: Actually, I'm already seeing a CanBeCaptured check in the ActionFunction, immediately after this where it chooses the flag to lock. Are you sure it's doubling up locks?
Edit 2: Oh. 'flag' is not defined as local prior to the flag-choosing loop, so it's being saved as a global when a flag is found. That means that once an AI has locked a flag, that flag will be stored in a global variable within the UseItemActions script module, and any situation where it can't find a capturable flag to lock, that variable will still hold the last flag that was locked (by any AI on either team) and will still pass the 'if not flag' check.
So, immediately after this line:
- flags = SortEntitiesByDistanceXZ(unit.Position, flags)
..and before the flag-locating loop, add this, so the flag isn't saved to a global:
- local flag = false