-
Notifications
You must be signed in to change notification settings - Fork 148
/
example.sqf
40 lines (33 loc) · 1.7 KB
/
example.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
This is an example for a script that uses the CBA state machine system.
In this case, we're "sharpening the senses" of AI units that got attacked before.
Once they had contact, they stay alert.
This would simulate units that did not expect an attack, but are now aware that
they might come under fire again.
You can test this example by executing the following code in the debug console:
[] call compile preprocessFileLineNumbers "\x\cba\addons\statemachine\example.sqf"
*/
private _stateMachine = [{allGroups select {!isPlayer leader _x}}, true] call CBA_statemachine_fnc_create;
[_stateMachine, {}, {}, {}, "Initial"] call CBA_statemachine_fnc_addState;
[_stateMachine, {}, {}, {}, "Alert"] call CBA_statemachine_fnc_addState;
[_stateMachine, "Initial", "Alert", {combatMode _this == "YELLOW"}, {
// Set skill once on transition
// This could also be done in the onStateEntered function
{
_x setSkill ["spotDistance", ((_x skill "spotDistance") * 1.5) min 1];
_x setSkill ["spotTime", ((_x skill "spotTime") * 1.5) min 1];
} forEach (units _this);
}, "InCombat"] call CBA_statemachine_fnc_addTransition;
[_stateMachine, "Initial", "Alert", ["MyAddon_AlarmRaised"], {true}, {
{
_x setSkill ["spotDistance", ((_x skill "spotDistance") * 1.5) min 1];
_x setSkill ["spotTime", ((_x skill "spotTime") * 1.5) min 1];
} forEach (units _this);
}, "Alarm"] call CBA_statemachine_fnc_addEventTransition;
// This makes sure you can execute this through the debug console
_stateMachine spawn {
sleep 0.1;
private _output = [_this, true, true] call CBA_statemachine_fnc_toString;
copyToClipboard _output;
hintC _output;
};