#This code and Triggers and AI and General Scripting Advices

1 messages · Page 1 of 1 (latest)

restive totem
#

.

sinful steeple
#

Alright

restive totem
#

if we oversimplify things, Trigger is "Run this code", but with flowery extras on top. If extras are useful - feel free to use them. If you can live without them - there're plenty of ways to do stuff without a trigger blobdoggoshruggoogly

sinful steeple
#

Oh that went though wtf lol

restive totem
#

links getting automodded out or something?

sinful steeple
sinful steeple
#

I tried to embed it into just saying "ForEach" so it was easier to look at but discord didn't like it very much

restive totem
#

well, that's a total sidetrack, tbh. Long story short: https://community.bistudio.com/wiki/FSM is a very specialized kind of script, frequently AI or mission flow related, execFSM are meant for them. SQF is not FSM

sinful steeple
#

Gotcha

restive totem
#

ah, the fancy annotated links. Those are restricted totally to avoid phishing attacks of different levels of stupidity. Just raw-dog the full links here, with optional angle brackets to remove auto-previews (like <https://community.bistudio.com/wiki/FSM>)

sinful steeple
#

But to put out a smaller fire, ExecVM is the correct way to call a .sqf in the scenario folder from a trigger?

restive totem
#

ah, the philosophical question

#

if you only need to run it once - execVM is perfect. Your patrol script seems to be such a usecase

sinful steeple
#

I would like to be able to turn it off and on periodically, like have it on when the players are doing their walking simulator portions, but have it off when they are at an actual objective.

#

That is another thing I need to figure out too

restive totem
#

if you want to run some .sqf file multiple times - it's better to read the file once, save the code to variable (like TMC_patrolManager = compile preprocessFileLineNumbers "dynamicPatrol.sqf";) and after that call/spawn the code from variable.

#

ah, the feature creep

#

awkward, i've lost my track after creating a thread 🤣

#

okay, i'll engage in full-code "analysis" then

#

count, start anew!

#

a) lines before while {true} do { loop look sane and useful. Moving the parameters you're likely to change to the beginning of the file so they all fit together is a nice practice

#

b) usage of while {true} do {//some code; sleep _patrolInterval;}; loop looks sane and useful. Your code needs to work continuously - endless loop would take care of that.

#

c) inside the loop. private _leaders = allPlayers select { part is kiiinda suspicious. Are you sure you'd make all group leader slots seargeants and lieutenants? Maybe, say, private _leaders = allPlayers select {_x = leader _x}; or something would be more fitting

#

d) using a {code} forEach _leaders; loop looks sane and useful for what you've listed as your intent (the "finds every WEST squad leader and spawns a patrol" part of it, at least)

#

e) inside the d) loop, the spawning part was discussed before

#

f) inside the d) loop, the LAMBS part is, sadly, the thing i can't reason about, i've never used it blobdoggoshruggoogly And sorry, i'm not gonna dig code/documentation for that right now

#

g) for the "delete them faraway groups" part - making "ActivePatrols" a real variable was discussed before

#

h) looping over ActivePatrols with forEach and deleting elements of the same array as you go would bite you, because when you delete an element all later ones get shifted one place back. And when you finish with, say, 2nd one - the next iteration would take new 3rd one (the old 4th if the shift didn't happen), skipping the old 3rd one (which now became 2nd, but forEach wouldn't iterate over 2nd again). forEachReversed was introduced specifically to work with this, afaik (as the shift only touches elements that it already iterated over)

sinful steeple
# restive totem c) inside the loop. `private _leaders = allPlayers select {` part is kiiinda sus...

Yeah I didn't like that part either, this was the initial iteration of what it spit out before, the one I used in my last op with this went well, but it just didn't delete things correctly. So after a while if I wasn't directly paying attention to it, I would have like 50 patrols all over the map. So this time I wanted to make it find the player group leader and spawn off of his position, and delete when it was too far away from the leader.

sinful steeple
restive totem
#

i) inside the h) loop - i'm not sure about (group _x) distance (group _group) < _despawnDistance part of the select filter. Can maybe replaced with checking distances between group leaders. Which would shorten out to something like private _playerNearby = _leaders select {_x distance leader _group < _despawnDistance};

#

j) when the group gets deleted, it should be deleted from ActivePatrols (with ActivePatrols deleteAt _forEachIndex; if you switch to forEachReversed loop)

#

k) the disable/reenable creeped feature may be achieved by, say,

  1. defining another global variable/flag (say, TMC_patrolsDisabled = false; somewhere in the beginning
  2. checking for it in the beginning of you big while loop (say, if TMC_patrolsDisable then {sleep _patrolInterval; continue}; - it should skip any loop iterations when the flag is true)
  3. when you go to "walking sim" state - you set the flag to true AND you delete all patrol AI groups by iterating over ActivePatrols
  4. when you go back to combat state - you set the flag to false and let the history take its course, patrols would spawn on the next loop 😛
#

and sorry, i'd consider any further active code digging from my side as "too much work, don't wanna". But would probably answer specific questions (including deciphering parts of my ramblings) for some time blobdoggoshruggoogly