Trying to cancel attack orders when intel is lost

Everything about mods can be found here.

Moderator: Morax

Trying to cancel attack orders when intel is lost

Postby Sabranan » 29 Apr 2019, 12:40

So my situation is I know how to extract files from the scds and I've got a very basic mod structure set up, which I've tested with something very simple (changing the mass extractors to extract more mass). That works nicely, but I'm looking to do something more interesting.

Essentially this is what I want to do as pseudocode:

Code: Select all
For Unit in Units
   If Unit.HasWeapon then
      If Unit.HasAttackOrder then
         If not (Unit.Target.Visible or Unit.Target.OnRadar) then
            Unit.Order.Cancel()
         End If
      End If
   End If
End For

So pretty much loop through every active unit, check if it meets the conditions and if it does, cancel the current order.

But I don't understand exactly where I should be doing this. I can't really find any documentation on creating your own methods that do anything to attack orders. I have looked through the code in FA 3619 and found a few routines that look promising, but I've had to admit to myself that I just don't know how to properly isolate them into a mod when there's so much other code I don't need.

Anyone able to point me in the right direction here?
Sabranan
Crusader
 
Posts: 10
Joined: 29 Apr 2019, 12:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: Sabranan

Re: Trying to cancel attack orders when intel is lost

Postby Franck83 » 29 Apr 2019, 13:04

Some useful links :

Unit Creation Guide: https://bit.ly/2P2kc1E
FAF wiki modding guide: https://bit.ly/2AfHewT
Robotnik's basic modding guide (Video ~20min): https://bit.ly/2PUu96D
Rackover's UnitDB (For attaining unit IDs): https://bit.ly/2Rc91FC
Modding Efficiently: https://bit.ly/2PVPXiw
Creating a Modding Test Loop: https://bit.ly/2r4mzaW
Ai modding guide: https://bit.ly/2DVILw2
Wide variety of blender tutorials (Youtube user Jayanam): https://bit.ly/2IezVbS

To clear orders tree :
Code: Select all
IssueClearCommands({ unit })


To issue orders :
Code: Select all
IssueAttack(YourUnit, YourTarget)


Don't change scd files, but create a mod. Because you will be able to share it and avoid desyncs.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Trying to cancel attack orders when intel is lost

Postby Sabranan » 29 Apr 2019, 14:05

Ok, so it seems like the ModBootstrap idea is where I need to start, since it runs a loop that executes on demand. Even if I want to change it to be just every beat or on a timer that should at least give me a proof of concept. But unless I'm doing something stupid this doesn't seem to be in the vault, or anywhere?
Sabranan
Crusader
 
Posts: 10
Joined: 29 Apr 2019, 12:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: Sabranan

Re: Trying to cancel attack orders when intel is lost

Postby Uveso » 29 Apr 2019, 14:30

Sabranan wrote:But unless I'm doing something stupid this doesn't seem to be in the vault, or anywhere?


Too late :)

There are already mods in the vault that only change a single code line or are more than stupid ^^

Btw, here are all commands that you can use in the LUA "sim-state" :
https://github.com/FAForever/fa/blob/develop/engine/Sim.lua

And all commands you can use fro the LUA "user-state":
https://github.com/FAForever/fa/blob/develop/engine/User.lua

Sim-state commands are for files like unit.lua, defaultantiprojectile.lua, aibrain.lua ...
Basically all functions that run inside the sim and need to be synced with other players.

user-state commands are for the user interface and used in files like User.lua, lobby.lua.
Mostly used for UI elements.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Trying to cancel attack orders when intel is lost

Postby Sabranan » 29 Apr 2019, 14:48

That's potentially very useful but I'm not at the point of actually running any commands yet lol. I'm still trying to get into a position where I have a loop running every game beat. Or at all.
Sabranan
Crusader
 
Posts: 10
Joined: 29 Apr 2019, 12:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: Sabranan

Re: Trying to cancel attack orders when intel is lost

Postby Sabranan » 29 Apr 2019, 16:32

Ok, some progress has been made.

I have an infinite loop which just posts a log to the console.

Problem is, that just freezes the game because it runs forever, but hey, at least I know it's doing something!

But that presents me with an issue, how can I have a loop running constantly but in its own thread so it doesn't completely stall everything else?
Sabranan
Crusader
 
Posts: 10
Joined: 29 Apr 2019, 12:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: Sabranan

Re: Trying to cancel attack orders when intel is lost

Postby Franck83 » 29 Apr 2019, 16:38

You can't interrupt sim so infinite loops will freeze the game.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Trying to cancel attack orders when intel is lost

Postby Sabranan » 29 Apr 2019, 16:45

Then I must be missing something because there's a load of "while true do" loops without any exit clauses I can see scattered around the lua, but these still run without locking it up.
Sabranan
Crusader
 
Posts: 10
Joined: 29 Apr 2019, 12:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: Sabranan

Re: Trying to cancel attack orders when intel is lost

Postby Uveso » 29 Apr 2019, 19:23

Just add a WaitTick inside your loop:
Code: Select all
WaitTicks(1)  -- Waits 0.1 seconds


[edit] this will only work in case you forked a thread.
Last edited by Uveso on 29 Apr 2019, 19:29, edited 1 time in total.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Trying to cancel attack orders when intel is lost

Postby Franck83 » 29 Apr 2019, 19:28

Then I must be missing something because there's a load of "while true do" loops without any exit clauses I can see scattered around the lua, but these still run without locking it up.


They are made only under threads, not on the main sim execution.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest