Ambu5h

Trying to make units do animations

10 posts in this topic

Alright... so i was using occupation vehicles in my server for creating roaming vehicles and boats.

Now i noticed that they seem to crash alot, get out of the vehicle for no reson or spawn in the middle of the woods on Tanoa.
Plenty of resons for me to finally start with a hello world script that replaces the roaming boats and vehicles.

Now.... roaming boats was easy... mission file side script that spawns a couple of groups and sets waypoints.
Easy... got that working perfect.

Now i was starting on the vehicles....
They spawn... Crew gets created and assigned waypoints set... vehicles start driving.
BUT as i was expecting... 1 hour in a 2 of the 4 vehicles have started to do some treehugging losing their frontwheels.
Vehicle is immobile... crew gets out... and moves away.

So i started looking at how occupation handles these things.
Occupations couples in a MPEventHandler "getout" to the vehicle to capture AI getting out of vehicles.

So i completely rewrote the getout function to stop units from moving away... set them to combat except for one.
This one unit then gets the command to stop moving... goto GREEN mode and start a repairing animation. However this animation never comes up of shows.
 

Spoiler

        _wp = group _unit addWaypoint [position _vehicle, 0];
        _wp setWaypointType "HOLD";
        _wp setWaypointBehaviour "SAFE";  // combat
        _wp setWaypointspeed "LIMITED";
        _wp setWaypointCompletionRadius 2;
        
        _unit disableAI "TARGET";
        _unit disableAI "AUTOTARGET";
        _unit disableAI "AUTOCOMBAT";
        _unit disableAI "COVER";  
        _unit disableAI "SUPPRESSION";    
        _unit disableAI "FSM";
        _unit disableAI "ANIM";
        
        _unit setCombatMode "GREEN";
        _unit setBehaviour "SAFE";

        diag_log "NEWSPAWNER GETOUT: Bandit repairing vehicle!";
        [] spawn { sleep 3; };

         _unit doMove (position _vehicle);
        [] spawn { sleep 4; };

         _unitDir = getDir _vehicle;
         _unit setDir _unitDir;
         _unit setUnitPos "MIDDLE";
        [] spawn  {  sleep 2;  };           

         _unit playMoveNow "Acts_carFixingWheel";            
        [] spawn  { sleep 5; };
 

        _vehicle setDamage 0;
        _unit switchMove "";
        [] spawn  { sleep 10; };

       

But the animations never show. And the sleepcommand is not executed (will do everything in half a second).
Now im quite sure this is becouse im spawning units in the mission file script (as server). And the Getout function is handled serverside (still by occupation in @exilemod/addons so far).
Yes i agree, right now its getting quite the mess.

My question thus is...... can i either move the getout function to the missionfile (still detecting the exiting of vehicles by AI).
Or how can i get this specific unit to play the repair vehicle animation visible for ALL players?
sleep command doesnt work serverside so i implemented it into a [] spawn function but this doesnt seem to work aswell. Any tips here would be appreciated.
Ive still got alot to do on this so some parts dont exacly function the way they are suppose to at the moment but most of it is fine.
Here are my complete files for now:

Spawner:

Spoiler

/** Simple PATROL by Ambu5h **/
 
diag_log "NEWSPAWNER: enabled!";
 
if (!isServer) exitWith{};
 
private [
"_wayPoints",
"_wpcycle",
"_vehicle",
"_spawnDelay",
"_spawnRandDelay",
"_spawnMinDelay",
"_maxVehicles",
"_maximumCrew",
"_debug",
"_group",
"_randVehicle",
"_wp",
"_vehiclesToUse",
"_speed",
"_randomSpeeds",
"_completionRadius"
];
 
/** Config ******************************************************************************************************************************************/

_vehiclesToUse = [
    "O_T_LSV_02_armed_black_F",
    "B_T_LSV_01_armed_black_F",
    "Exile_Car_HMMWV_M2_Green",
    "CUP_O_BTR40_MG_TKM",
    "CUP_RG31_M2_OD",
    "CUP_O_GAZ_Vodnik_PK_RU",
    "CUP_BAF_Jackal2_L2A1_W",
    "Exile_Car_Offroad_Armed_Guerilla02",
    "B_Truck_01_box_F",
    "B_Truck_01_fuel_F",
    "B_T_Truck_01_ammo_F",
    "O_Truck_02_covered_F",
    "NLD_DAF_Transport_Covered",
    "NLD_DAF_medical",
    "Ural_RU",
    "CUP_B_HMMWV_SOV_USA",
    "CUP_O_Datsun_PK",
    "CUP_I_Datsun_PK",
    "Exile_Car_Offroad_Armed_Guerilla07",
    "C_Van_01_box_F"
];

_randomSpeeds = [
    "LIMITED",
    "NORMAL",
    "FULL"
];

_spawnDelay = 180;            // Initial delay time of spawning the first vehicle.
_spawnRandDelay = 600;        // Random amount of time after the first vehicle has spawned, at _spawnDelay.
_spawnMinDelay = 200;       // Minimum amount of time before next vehicle will spawn
                            // Set these values low for debuging perposes (IE: 100/600/200)

_maxVehicles = 4;            // Maximum number of vehicles to spawn.
_maximumCrew = 3;             // Set this to a normal amount to prevent zamaks or ikarus busses to spawn with a ton of AI.
                            // This is max crew per vehicle.
/** DEBUG *******************************************************************************************************************************************/
_debug = true;
 
/** Waypoints ***************************************************************************************************************************************/
/** Recommended not to use to many and a decent distance away from the coast. *******************/
/** AI In boats tend to get stuck on shorelines.                              *******************/

_completionRadius = 20;    // Radius in which the reaching of the waypoint is triggered

// In order to eliminate vehicles going onto dirt tracks, place as many of these as possible avoiding offroad tracks as shortcuts.
_wayPoints = [
    [10949.2,13066.3, 2],   //Starting position. Make sure to end where your started.
    [11012.5,13288,   2],
    [12539.8,12670,   2],
    [13584.5,11981.7, 2],
    [13568.5,11803.1, 2],
    [13710.9,11828.2, 2],
    [13810.7,11789.8, 2],
    [14060.1,12187.5, 2],
    [13810.7,11789.8, 2],
    [14297.6,11450.2, 2],
    [14582.4,10913.1, 2],
    [14020.4,10686.2, 2],
    [13488.4,11366.9, 2],
    [13076.1,10665,   2],
    [13043.9,9978.31, 2],
    [13731.9,9374.38, 2],
    [14351.3,8693.1,  2],
    [13998.4,7994.31, 2],
    [12381.2,8032.86, 2],
    [12324.2,8410.86, 2],
    [11915.6,9251.98, 2],
    [11052.2,9820.88, 2],
    [11856,10147.1,   2],
    [11328,10345.3,   2],
    [12185.9,10554.3, 2],
    [12151.1,10237.5, 2],
    [12284.9,10002.5, 2],
    [12923.1,11332.9, 2],
    [11855.8,11578.4, 2],
    [10951.4,11459.4, 2],
    [10263.7,11646.6, 2],
    [9420.95,12317.9, 2],
    [10346.8,13372.7, 2],
    [10984.6,13319.8, 2],
    [10955.1,13067.3, 2] // Approx same as starting position
];

if (_debug) then
{ diag_log format["NEWSPAWNER: Patrol delayed by %1 seconds.", _spawnDelay]; };

uiSleep _spawnDelay;

for "_i" from 1 to _maxVehicles do
{
    _side = createCenter EAST;
    
    _randVehicle = _vehiclesToUse call BIS_fnc_selectRandom;

    _vehicle = createVehicle [_randVehicle, _wayPoints select 0, [], 0, "NONE"];
    
    if(!isNull _vehicle) then
    {
        if (_debug) then
        { diag_log format["NEWSPAWNER: Patrol number %2 created location: %1 - Type: %3", _wayPoints select 0, _i, _randVehicle]; };

        _vehicle setVariable ["vehPos",_wayPoints select 0,true];
        _vehicle setVariable ["vehClass",_randVehicle,true];
        _vehicle setFuel 1;
        _vehicle engineOn true;
        _vehicle addEventHandler ["getout", "_this call SC_fnc_getOut;"];
        
        clearWeaponCargoGlobal   _vehicle;
        clearMagazineCargoGlobal _vehicle;
        clearItemCargoGlobal     _vehicle;
        clearWeaponCargoGlobal   _vehicle;
        
        _vehicle lock 1;            
        _vehicle setVehicleLock "LOCKED";
        _vehicle setVariable ["ExileIsLocked", -1, true];
        
        _vehicle setVariable ["ExileIsPersistent", false];
        _vehicle setSpeedMode "LIMITED";
        _vehicle limitSpeed 60;
        _vehicle action ["LightOn", _vehicle];
 
         _group = createGroup _side;
        
        _group setVariable ["DMS_AllowFreezing",false];
        _group setVariable ["DMS_LockLocality",false];
        _group setVariable ["DMS_SpawnedGroup",true];
        _group setVariable ["DMS_Group_Side", _side];
        
        _group addVehicle _vehicle;

        _amountOfCrew = 0;
        
        _vehicleRoles = (typeOf _vehicle) call bis_fnc_vehicleRoles;
        {
            _safeSpawn = [_wayPoints select 0, 20, 40, 15, 0, 20, 0] call BIS_fnc_findSafePos;
            _vehicleRole = _x select 0;
            _vehicleSeat = _x select 1;
            
            if(_vehicleRole == "Driver") then
            {
                   _unit = [_group, _safeSpawn, "random", "difficult", "EAST", "Vehicle", []] call DMS_fnc_SpawnAISoldier;
                _amountOfCrew = _amountOfCrew + 1;
                
                _unit setCombatMode "GREEN";
                _unit setBehaviour "SAFE";
                
                _unit disableAI "FSM";    
                _unit disableAI "MOVE";                              
                _unit disableAI "TARGET";
                _unit disableAI "AUTOTARGET";
                _unit disableAI "AUTOCOMBAT";
                _unit disableAI "COVER";
                _unit disableAI "SUPPRESSION";
                _unit allowFleeing 0;
                _unit setSkill 1;
                _unit allowCrewInImmobile true;

                _unit assignAsDriver _vehicle;
                _unit moveInDriver _vehicle;                
                _unit setVariable ["DMS_AssignedVeh",_vehicle];
                _unit setVariable ["SC_drivenVehicle", _vehicle,true];
                _vehicle setVariable ["SC_assignedDriver", _unit,true];    

                if(_debug) then
                { diag_log format["NEWSPAWNER: Patrol number %1. Added Driver! - Side:%2 - Role:%3 - Vehicle:%4", _i, _side, _vehicleRole, typeOf _vehicle]; };
            };
            if(_vehicleRole == "Turret" && _amountOfCrew < _maximumCrew) then
            {
                _unit = [_group, _safeSpawn, "random", "difficult", "EAST", "Vehicle", []] call DMS_fnc_SpawnAISoldier;
                _amountOfCrew = _amountOfCrew + 1;                
                
                _unit setCombatMode "GREEN";
                _unit setBehaviour "SAFE";
                
                _unit allowCrewInImmobile true;
                _unit allowFleeing 0;
                _unit setSkill 0.5;
                _unit disableAI "FSM";
                _unit disableAI "MOVE";    
                _unit disableAI "TARGET";
                _unit disableAI "AUTOTARGET";
                _unit disableAI "AUTOCOMBAT";
                _unit disableAI "COVER";
                _unit disableAI "SUPPRESSION";
                
                _unit assignAsGunner _vehicle;
                _unit moveInTurret [_vehicle, _vehicleSeat];
                _unit setVariable ["DMS_AssignedVeh",_vehicle];
                _unit setVariable ["SC_drivenVehicle", _vehicle,true];
                
                if(_debug) then
                { diag_log format["NEWSPAWNER: Patrol number %1. Added Gunner! - Side:%2 - Role:%3 - Vehicle:%4", _i, _side, _vehicleRole, typeOf _vehicle]; };
            };
            if(_vehicleRole == "CARGO" && _amountOfCrew < _maximumCrew) then
            {
                _unit = [_group, _safeSpawn, "random", "difficult", "EAST", "Vehicle", []] call DMS_fnc_SpawnAISoldier;               
                _amountOfCrew = _amountOfCrew + 1;                                                        
                
                _unit setCombatMode "GREEN";
                _unit setBehaviour "SAFE";
                
                _unit disableAI "FSM";
                _unit disableAI "MOVE";  
                _unit disableAI "TARGET";
                _unit disableAI "AUTOTARGET";
                _unit disableAI "AUTOCOMBAT";
                _unit disableAI "COVER";
                _unit disableAI "SUPPRESSION";
                _unit setSkill 1;
                _unit allowCrewInImmobile true;
                _unit allowFleeing 0;  
                
                _unit assignAsCargo _vehicle;
                _unit moveInCargo _vehicle;
                _unit setVariable ["DMS_AssignedVeh",_vehicle];
                _unit setVariable ["SC_drivenVehicle", _vehicle,true];
                
                if(_debug) then
                { diag_log format["NEWSPAWNER: Patrol number %1. Added Cargo! - Side:%2 - Role:%3 - Vehicle:%4", _i, _side, _vehicleRole, typeOf _vehicle]; };
            };                  
            
        } forEach _vehicleRoles;
        
        [units _group] orderGetIn true;
        
        _wpin = _group addWaypoint [_wayPoints select 0, 0];
        _wpin setWaypointType "GETIN";
        _wpin setWaypointBehaviour "SAFE";  // combat
        _wpin setWaypointspeed "FULL";
                
        if (_debug) then
        { diag_log format["NEWSPAWNER: Patrol number %1 ordered to get in. Waiting 15 seconds for waypoints.", _i]; };
        
        sleep 15;
        
        {
            _speed = _randomSpeeds call BIS_fnc_selectRandom;
            _wp = _group addWaypoint [_x, 0];
            _wp setWaypointType "MOVE";
            _wp setWaypointBehaviour "COMBAT";  // combat
            _wp setWaypointspeed _speed;
            _wp setWaypointCompletionRadius _completionRadius;
            
            if (_debug) then
            { diag_log format["NEWSPAWNER: Patrol %2. Added waypoint %1 - Speed: %3", _x, _i, _speed]; };
            
        }foreach _wayPoints;

        _speed = _randomSpeeds call BIS_fnc_selectRandom;
        _wpcycle = _group addWaypoint [_wayPoints select 0, 0]; // Set first waypoint as cycle position
        _wpcycle setWaypointType "CYCLE";
        _wpcycle setWaypointBehaviour "COMBAT";
        _wpcycle setWaypointspeed _speed;
        _wp setWaypointCompletionRadius _completionRadius;
        
        {
            _unit = _x;
            if (((assignedVehicleRole _unit) select 0) == "Driver") then
            {
                _unit disableAI "FSM";  
                _unit enableAI "MOVE";
                _unit disableAI "TARGET";
                _unit disableAI "AUTOTARGET";
                _unit disableAI "AUTOCOMBAT";
                _unit disableAI "COVER";
                _unit disableAI "SUPPRESSION";
                _unit allowFleeing 0;
                _unit allowCrewInImmobile true;
                _unit setName "A bandit";
                
                if(_debug) then
                { diag_log "NEWSPAWNER: Patrol driver properties set. Waiting 15 seconds."; };
                
                sleep 15;
            };
            
            if (((assignedVehicleRole _unit) select 0) == "Turret") then
            {
                _unit enableAI "FSM";
                _unit enableAI "MOVE";  
                _unit enableAI "TARGET";
                _unit enableAI "AUTOTARGET";
                _unit enableAI "AUTOCOMBAT";
                _unit enableAI "COVER";
                _unit enableAI "SUPPRESSION";
                _unit allowFleeing 0;
                _unit allowCrewInImmobile true;
                _unit setName "A bandit";
                _unit setCombatMode "RED";
                _unit setBehaviour "COMBAT";
                
                if(_debug) then
                { diag_log "NEWSPAWNER: Patrol gunner properties set"; };
            }
            else
            {
                _unit enableAI "FSM";
                _unit enableAI "MOVE";  
                _unit enableAI "TARGET";
                _unit enableAI "AUTOTARGET";
                _unit enableAI "AUTOCOMBAT";
                _unit enableAI "COVER";
                _unit enableAI "SUPPRESSION";
                _unit allowCrewInImmobile true;
                _unit setName "A bandit";
                _unit setCombatMode "RED";
                _unit setBehaviour "COMBAT";
                
                if(_debug) then
                { diag_log "NEWSPAWNER: Patrol cargo properties set"; };
            };
        }forEach units _group;
    };
    
    _vehicle lock 0;            
    _vehicle setVehicleLock "UNLOCKED";
    _vehicle setVariable ["ExileIsLocked", 0, true];
    
    _nextDelay = 0;
    if (_spawnMinDelay > _spawnRandDelay) then
    { _nextDelay = _spawnMinDelay; }
    else                                          //  Just to prevent stupidity
    { _nextDelay = _spawnMinDelay + random (_spawnRandDelay - _spawnMinDelay); };


    if (_debug) then
    { diag_log format["NEWSPAWNER: Next patrol delayed for %1 seconds.", _nextDelay]; };
    
    sleep _nextDelay;
};


GETOUT function (@ExileMod/addons/a3_occupation/eventHandlers):

Spoiler

// Triggered if an AI unit leaves an AI vehicle

_unit     = _this select 0;
_vehicle = _this select 2;
_driver  = _vehicle getVariable "SC_assignedDriver";
_arrowClass = "Sign_Arrow_F";
_startRepair = false;
_oldWaypoints = null;

 

if(!alive _unit  ||  isPlayer _unit) exitWith {};

_vehicles = nearestObjects [_unit, ["LandVehicle"], 20];
{
    diag_log format ["NEWSPAWNER GETOUT: vehicles found:%1", typeOf _x];
    
    if (vehicle _x isKindOf "LandVehicle") then
    {
        _vehicle = vehicle _x;
        diag_log "NEWSPAWNER GETOUT: vehicles contains TYPE LAND";
    };
} foreach _vehicles;

if (!isNull _vehicle) then
{
    diag_log format ["NEWSPAWNER GETOUT: Vehicle:%1 found! Searching for damaged parts!", typeOf _vehicle];
    
    _hitpoint = ["HitLFWheel","HitLF2Wheel","HitRFWheel","HitRF2Wheel","HitLBWheel","HitLMWheel","HitRBWheel","HitRMWheel","HitFuel","HitEngine","HitEngine2","HitEngine3"];
    {
        if ((_vehicle getHitPointDamage _x) > 0) then
        {
            _startRepair = true;
            diag_log format ["NEWSPAWNER GETOUT: Damaged vehicle part found. Hitpoint:%1 - Damage:%2 - Vehicle:%3", _x, _vehicle getHitPointDamage _x, typeOf _vehicle];
        };
    } forEach _hitpoint;

    if (_startRepair) then
    {
        diag_log format ["NEWSPAWNER GETOUT: Damaged vehicle. Damage:%1 - Vehicle:%2", damage _vehicle, typeOf _vehicle];

        _oldWaypoints = waypoints group _unit;
        
        while {(count (waypoints group _unit)) > 0} do
        { deleteWaypoint ((waypoints group _unit) select 0); };
        
        _wp = group _unit addWaypoint [position _vehicle, 0];
        _wp setWaypointType "HOLD";
        _wp setWaypointBehaviour "SAFE";  // combat
        _wp setWaypointspeed "LIMITED";
        _wp setWaypointCompletionRadius 2;
        
        _unit disableAI "TARGET";
        _unit disableAI "AUTOTARGET";
        _unit disableAI "AUTOCOMBAT";
        _unit disableAI "COVER";  
        _unit disableAI "SUPPRESSION";    
        _unit disableAI "FSM";
        _unit disableAI "ANIM";
        
        _unit setCombatMode "GREEN";
        _unit setBehaviour "SAFE";

        [] spawn
        {
            diag_log "NEWSPAWNER GETOUT: Bandit repairing vehicle!";
            sleep 3;
        };
        
        [] spawn
        {
            _unit doMove (position _vehicle);
            sleep 5;
        };
        
        [] spawn
        {
            _unitDir = getDir _vehicle;
            _unit setDir _unitDir;
            _unit setUnitPos "MIDDLE";  
            sleep 2;
        };            
            
        [] spawn
        {
            _unit playMoveNow "Acts_carFixingWheel";
            sleep 15;
        };
        
        [] spawn
        {
            _vehicle setDamage 0;
            _unit switchMove "";
            sleep 10;
        };
        
        if (alive _unit) then
        {    
            diag_log "NEWSPAWNER GETOUT: Hitpoints restored!";

            
            _vehicle setVariable ["SC_assignedDriver", _unit,true];    
            _unit allowFleeing 0;
            _unit setSkill 1;
            _unit allowCrewInImmobile true;
            _unit assignAsDriver _vehicle;
            _unit moveInDriver _vehicle;  
            _unit action ["movetodriver", _vehicle];            
            _unit setVariable ["DMS_AssignedVeh",_vehicle];
            _unit setVariable ["SC_drivenVehicle", _vehicle,true];

            diag_log "NEWSPAWNER GETOUT: Driver moved back into vehicle!";
        };

        [] spawn
        {
            sleep 5;
            _vehicle setFuel 1;
            _vehicle engineOn true;
        };
        
        _wpin = group _unit addWaypoint [position _vehicle, 0];
        _wpin setWaypointType "GETIN";
        _wpin setWaypointBehaviour "SAFE";
        _wpin setWaypointspeed "FULL";

        [] spawn
        {     
            [units group _unit] orderGetIn true;
            sleep 5;
        };
        
        {
            _speed = _randomSpeeds call BIS_fnc_selectRandom;
            _wp = group _unit addWaypoint [_x, 0];
            _wp setWaypointType "MOVE";
            _wp setWaypointBehaviour "COMBAT";  // combat
            _wp setWaypointspeed _speed;
            _wp setWaypointCompletionRadius 20;
            
            diag_log format["NEWSPAWNER GETOUT: Added waypoint %1.", _x];
        }foreach _oldWaypoints;
        
        _unit enableAI "MOVE";  //make driver move on again

        diag_log format ["NEWSPAWNER GETOUT: Waypoint set to get back in vehicle. Damage: %1 - Vehicle: %2", damage _vehicle, _vehicle];
        
        _startRepair = false;
    }
    else
    { diag_log format ["NEWSPAWNER GETOUT: Vehicle: %1 has no damaged parts!", typeOf _vehicle]; };
}
else
{ diag_log "NEWSPAWNER GETOUT: No suitable vehicle found! Vehicle is null."; };



THIS SCRIPT IS NOT WORKING! IF YOU WANT TO USE IT. GOOD LUCK.

With kind regards,

 

Edited by Ambu5h

Share this post


Link to post
Share on other sites
Advertisement

Ill see if i can trigger a trigger wihout triggering being triggered by error exeptions being triggered.

 

 

 

 

 

 

 

 

 

 

... Trigger

Edited by Ambu5h

Share this post


Link to post
Share on other sites

its all good, that is why i laughed when Stokesmagee posted the picture. I think thats 1 thing that annoys people is having to scroll a page. Get a little twitchy

Share this post


Link to post
Share on other sites
3 minutes ago, tinboye said:

its all good, that is why i laughed when Stokesmagee posted the picture. I think thats 1 thing that annoys people is having to scroll a page. Get a little twitchy

Scrolling through logfiles seems to be all im doing lately haha.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.