From Bohemia Interactive Community
Jump to navigation Jump to search

I'm Markus 30 years old and from germany.

In my free time i do a lot of .sqf and config.cpp scripting and testing.

Current Project: Group Link 4 Special FX Edition

FSM: ( Fine State Machine )

In Arma 2 we have 2 different .fsm which are used to set how A.I. should behave in combat.

1. NativeFSM ( CACharacters\CfgFSMs.hpp )
2. ScriptedFSM ( CACharacters\Scripts\Danger.fsm )

Bouth FSMs are initialized in the "CACharacter" >> "CfgVehicles" >> "CAManBase".

The NativeFSM is used to control the general behaviour of A.I. units in combat.
It will choose if A.I. should go to cover or attack a known enemy.
If A.I. should reload while in cover or if A.I. should look for any other ( may better ) cover.
It also let you choose if A.I. should provide cover or if they should try fighting on their own.

The ScriptedFSM is used to control the general behaviour of A.I. in situations which are dangerous.
This is something like a Event Handler which is triggering after a specific event happend.
The ScriptedFSM Conditions:

  • Detect Enemys: This will trigger every time A.I. has detected a enemy unit.
  • Detect Weapon fire: This will trigger every time a unit has fired a weapon.

Note: The A.I. which should detect weapon fire must have the chance to know more then 0 about the unit which has fired the weapon.

  • Detect Enemys Near: This will trigger every time A.I. has detected a enemy unit which is very close.
  • Detect Explosions: This will trigger every time after something is exploded? ( Havent seen this so far... )
  • Detect Dead Bodys: This will trigger every time A.I. has detected a dead body. Note: Exploded vehicles are triggered here too.
  • Detect Stop Fire: This will trigger randomly and make A.I. to stop moving for 4 - 8 sec.

If multiple conditions match then they will be triggered given to the priority set in the event.

Global Array System

Each "Global Variable" will be stored in the memory. This means many "Global Variable" will need much memory space. You can reduce the resources used from "Global Variable" by using a "Gloabal Array" which stores all needed values instead of creating a new "Global Variable" for each value.

Default: ( Bad ) Global_Bool = True; Global_Number = 30; Global_Distance = 500; Global_Array = []; Now we have created 4 different "Global Variable" which will need 3x more memory like the optimized way.

Examples: if (Global_Bool) then { Global_Bool = False; ....... };

if (count _array < Global_Number) then { ....... };

if (player distance _object < Global_Distance) then { ....... };

if !(_object in Global_Array) then { Global_Array = Global_Array + [_object]; ....... } else { Global_Array = Global_Array - [_object]; ....... };

Optimized: ( Good ) Global_System = [True, 30, 500, [] ]; Now we have stored all values in only 1 "Global Variable" called "Global_System".

You can check / select the needed value by using (Global_System select Index). Index is the position ( number ) in which the given value was stored.

Select the Bool: True (Global_System select 0)

Select the Number: 30 (Global_System select 1)

Select the Array: [] (Global_System select 3)

Examples: if (Global_System select 0) then { Global_System set [0, False]; ....... };

if (count _array < (Global_System select 1) ) then { ....... };

if (player distance _object < (Global_System select 2) ) then { ....... };

if !(_object in (Global_System select 3) ) then { Global_System set [3, (Global_System select 3) + [_object] ]; ....... } else { Global_System set [3, (Global_System select 3) - [_object] ]; ....... };