Jump to content

Recommended Posts

Hey guys,

i hope for ur help. I wanna spawn AI gunners for a vehicle the player has chosen to drive.

createVehicleCrew is no option cause i wont spawn inside of the vec. I wanna spawn outside and let em get in.

 

For that I wanna know if the vehicle chosen by player has a gunner and/or a commander seat and how much turrets it has.
Also I need to get the correct turretPath to that turrets.

 

Additional it would be nice to spawn some AI which should take their seat at these cargo seats from where they are able to shoot with their own guns.

So I need the cargo index of that seats

Any help is apreciated. Thanks a lot.

Share this post


Link to post
Share on other sites
Guest

You may take a look into the config. They will surely give you the seats.

Share this post


Link to post
Share on other sites

You may take a look into the config. They will surely give you the seats.

How can I do that by scipt?

okay for commander and gunner i think this this could be a solution:

 

if (isNil {commander _vec}) then{hint "no commander 
seat";}else{hint "commander seat available";};

Edit: I found allTurrets now but I dont know what FFV-turrets are. Could someone explain it?

 

Edit: FFV means Fire From Vehicle

Edited by sarogahtyp
  • Like 1

Share this post


Link to post
Share on other sites

Check fullCrew function. Looks like exactly what you need.

 

That looks excellent. Thank u very much. I will try it.

Share this post


Link to post
Share on other sites

With ur help I got some working peace of code now. Thank u for that.
But there r some problems with it.

First, would someone tell me how I can do a spoiler in this forum, please?

The main problem is that it works perfect in 2D editors preview but if i test it at my dedicated server then the spawned A.I. is directly moved into the vehicle via moveIn command but then it gets out instantly.
After that it tries to get in again and again but it will get out instantly every time.

Only for copilots of huron and ghosthawk it is working. They dont leave the vehicle.

 

 

 

ai_gunners.sqf:

 

if (isServer) then
{
 _vec = _this select 0;
 _player = driver _vec;
 _turrets = fullCrew [_vec,"", true];
 _squadpos = getMarkerPos "gunnermarker";
 _turret_num = (count _turrets)-1;
 _leader = false;
 _squad = [];

 for "_x" from 0 to _turret_num do
 {
  _cur_tur = _turrets select _x; //get values for actual vec
  _c_t1 = _cur_tur select 0; //unit at seat or objNull
  _c_t2 = _cur_tur select 1; //role for seat (driver,gunner,commander,turret,cargo)
  _c_t3 = _cur_tur select 2; //cargo index
  _c_t4 = _cur_tur select 3; //path to seat
  _c_t5 = _cur_tur select 4; //boolean value, true if a person is able to fire from this seat

  if(isNull _c_t1) then //check if seat is empty
  {
// ******* handle commander seat
   if((_c_t2 == "commander") or (_c_t2 == "Commander")) then //check role of seat
   {
    _temp_squad = [_squadpos, WEST, 1] call BIS_fnc_spawnGroup; //spawn 1 soldier

    {
     _x setSkill 1;
     _x assignAsCommander _vec;
     _x assignAsTurret [_vec, _c_t4];
     [_x] allowGetIn true;
     [_x] orderGetIn true;
     _x moveInCommander _vec;
    }forEach units _temp_squad;

    if (!_leader) then //move ai in the correct squad
    {
     _squad = _temp_squad;
     _leader = true;
    }
    else
    {
     {
      [_x] join _squad;
     }forEach units _temp_squad;
    };
   };

// ******* handle gunner seat

   if((_c_t2 == "gunner") or (_c_t2 == "Gunner")) then
   {
    _temp_squad = [_squadpos, WEST, 1] call BIS_fnc_spawnGroup;

    {
     _x setSkill 1;
     _x assignAsGunner _vec;
     _x assignAsTurret [_vec, _c_t4];
     [_x] allowGetIn true;
     [_x] orderGetIn true;
     _x moveInGunner _vec;
    }forEach units _temp_squad;

    if (!_leader) then
    {
     _squad = _temp_squad;
     _leader = true;
    }
    else
    {

     {
      [_x] join _squad;
     }forEach units _temp_squad;
    };
   };

// ******* handle turret

   if((_c_t2 == "turret") or (_c_t2 == "Turret")) then
   {
    _temp_squad = [_squadpos, WEST, 1] call BIS_fnc_spawnGroup;

    {
     _x setSkill 1;
     _x assignAsTurret [_vec, _c_t4];
     [_x] allowGetIn true;
     [_x] orderGetIn true;
     _x moveInTurret [_vec, _c_t4];
    }forEach units _temp_squad;

    if (!_leader) then
    {
     _squad = _temp_squad;
     _leader = true;
    }
    else
    {

     {
      [_x] join _squad;
     }forEach units _temp_squad;
    };
   };

/* this part is not working for some reason but it could be unnecessary because all desired A.I. is spawning without it

// ******* handle cargo
   if(((_c_t2 == "cargo") or (_c_t2 == "Cargo")) and (_c_t5 == true)) then
   {
    _temp_squad = [_squadpos, WEST, 1] call BIS_fnc_spawnGroup;

    {
     _x setSkill 1;
     _x assignAsCargo [_vec, _c_t4];
     [_x] allowGetIn true;
     [_x] orderGetIn true;
     _x moveInCargo [_vec, _c_t4];
    }forEach units _temp_squad; 

    if (!_leader) then
    {
     _squad = _temp_squad;
     _leader = true;
    }
    else
    {

     {
      [_x] join _squad;
     }forEach units _temp_squad;
    };
   };
*/

  }; //empty seat check end
 }; // for do end

//make the squad aggressive
 _squad setCombatMode "RED";
 _squad setBehaviour "COMBAT";

 waitUntil //wait for players death or until he is disconnected
 {
  sleep 1;
  (!(alive _player) or (isNull _player))
 };

// delete whole squad

 {
  deleteVehicle _x;
 } forEach units _squad;
}; //Server end

Share this post


Link to post
Share on other sites

1. assignAsCargo does not take array as right argument.

2. moveInCargo's right argument's second element in array must be Number, i.e. cargoIndex, not Array (in your case turretPath)

3. Even if you use _c_t3 instead of _c_t4 you might not sit all soldiers from squad on the same place (using same cargo index for all). Collect all free cargo indexes and move one soldier per one cargo index.

  • Like 1

Share this post


Link to post
Share on other sites

1. assignAsCargo does not take array as right argument.

2. moveInCargo's right argument's second element in array must be Number, i.e. cargoIndex, not Array (in your case turretPath)

3. Even if you use _c_t3 instead of _c_t4 you might not sit all soldiers from squad on the same place (using same cargo index for all). Collect all free cargo indexes and move one soldier per one cargo index.

 

Thank u.  U found the mistakes in the  uncommented code but i think i dont need the cargo seats cause they r also turrets and r coverd by the "handle turrets" part of the script.

 

_temp_squad consist of 1 unit only so point 3. isnt a mistake.

 

but my main problem is that the AI gets out of the vecs instantly after embarking it.

Share this post


Link to post
Share on other sites

Consider using AddVehicle to prevent them from leaving it, maybe?

It usually works for me.

  • Like 1

Share this post


Link to post
Share on other sites

Consider using AddVehicle to prevent them from leaving it, maybe?

It usually works for me.

 

thank u. sounds good. i will give it a try.

Share this post


Link to post
Share on other sites

Okay guys, with ur hints it is now a good working script and it works with a dedicated server too.

If anyone wish to use it just do it.

 

The only thing what I dont like with it is that the driver the spawned AI and the vehicle must be in the same group.

I created a new group and moved all into that.

I wish I could let the driver/player in his own group. but i think there is no solution for that problem.

 

But as I said, script is working now and I m happy with it.

 

Thanks a lot.
 

 

 


if (!isServer) exitWith {true};
/*
	Author: Sarogahtyp
	Title: SSAIG - Sarogahtyps Simple AI Gunners

	Description: Embarks AI gunners for a player driven vehicle. Is thought to be executed server/HC-side and not on client.

	Arguments:
	object - vehicle which should be filled with AI gunners
	
	Return value:
	boolean - true if script has been finished
*/

params [["_vec", objNull, [objNull]]];

if ((!(_vec in vehicles) and !isPlayer _vec) or isNull _vec or damage _vec isEqualTo 1) exitWith {true};

_player = driver _vec;

if (!isPlayer _player or isNull _player or !alive _player) exitWith {true};

if (isNull objectParent _player) exitWith {["You can get AI gunners for any vehicle here."] remoteExec ["hintSilent", _player]; true}; 

_spawn_pool = ["B_Soldier_GL_F","B_HeavyGunner_F"];
_turrets = fullCrew [_vec, "", true];
_squadpos = _vec getPos [10, random 360];
_squad = createGroup [west, false];
_vec_full = true;

// ********** Check if there is a seat where an AI can be spawned and spawn it
{
 _x params ["_c_t1", "_c_t2", "_c_t3", "_c_t4", "_c_t5"];

 //turret empty?
 if(isNull _c_t1) then  
 {
  //is turret just a "turret" type?
  if(toLower _c_t2 isEqualTo "turret") then
  {
   _unit = _squad createUnit [(selectRandom _spawn_pool), (_squadpos getPos [2, (random 360)]), [], 0, "NONE"];
   _unit assignAsTurret [_vec, _c_t4];  
   _unit moveInTurret [_vec, _c_t4];
   _vec_full = false;
  }
  else
  {
   // is turret gunner seat?
   if(toLower _c_t2 isEqualTo "gunner") then
   {
    _unit = _squad createUnit [(selectRandom _spawn_pool), (_squadpos getPos [2, (random 360)]), [], 0, "NONE"];
    _unit assignAsGunner _vec;
    _unit moveInGunner _vec; 
    _vec_full = false;
   }
   else
   {
    // is turret commander seat?
    if(toLower _c_t2 isEqualTo "commander") then
    {
     _unit = _squad createUnit [(selectRandom _spawn_pool), (_squadpos getPos [2, (random 360)]), [], 0, "NONE"];
     _unit assignAsCommander _vec;  
     _unit moveInCommander _vec; 
     _vec_full = false;
    }
    else
    {
     // is turret cargo seat and one can fire a gun from it?
     if(toLower _c_t2 isEqualTo "cargo" and _c_t5) then
     {
      _unit = _squad createUnit [(selectRandom _spawn_pool), (_squadpos getPos [2, (random 360)]), [], 0, "NONE"];
      _unit assignAsCargo _vec;  
      _unit moveInCargo [_vec, _c_t3];
      _vec_full = false;
     }; // cargo end
    }; // commander end
   }; // gunner end
  }; // turret end
 }; // empty seat end
 true
} count _turrets;

//exit if no AI was spawned
if (_vec_full) exitWith {["You ve no empty seat to shoot from on your vehicle."] remoteExec ["hintSilent", _vec]; true};

["AI gunners embarked. They ll engage enemies now."] remoteExec ["hintSilent", _player];

//track _units for later deletion
[_vec, _squad] spawn 
{
 params ["_vec", "_squad"];
 
 // make squad agressive and skilled
 _squad setCombatMode "RED";
 _squad setBehaviour "COMBAT";

{
 _x setSkill 1;
 _x setskill ["aimingAccuracy", 1];
 _x setskill ["aimingShake", 1];
 _x setskill ["aimingSpeed", 1];
 _x setskill ["endurance", 1];
 _x setskill ["spotDistance", 1];
 _x setskill ["spotTime", 1];
 _x setskill ["courage", 1];
 _x setskill ["reloadSpeed", 1];
 _x setskill ["commanding", 1];
 _x setskill ["general", 1];
 true
} count (units _squad);

 _timeout = time + 3600;
	
 waitUntil 
 {
  sleep (60 + random 60); 
  (damage _vec isEqualTo 1 or isNull _vec or {alive _x} count units _squad < 1 or time > _timeout)
 };

 _squad deleteGroupWhenEmpty true;

 {
  deleteVehicle _x;
  true
 } count units _squad;
};
true

 

Edited by sarogahtyp
Updated to complete rewritten version
  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×