Author: Bl2ck Dog
Author Website:

Requirements:

Version: 09-04-2013

Short description: Interactive Whiteboard, Check Pilot/Gunner, Simple Heli Door Script, Keep Gunner, Weapon Restriction, Loadout

Date: 2013-09-05 07:48


Comments: (2)
Rating:



 





B2 Scripts

by
Bl2ck Dog


Description:
Set of scripts


Weapon Restriction:
Tired of diver-sniper-antitank-Rambos ruining your server realistic gameplay? Here's simple solution.
This script allows to restrict weapons to certain soldier classes.
It also restricts 2 levels down the classtree, so you don't have to add all the scope variants to the list.
Be careful with the classnames, they are case sensitive.
Works with units and weapons added with mods.


Example (put in mission's init.sqf)
0 = [["B_soldier_AT_F","B_soldier_LAT_F"],["launch_NLAW_F","launch_RPG32_F","launch_Titan_base","launch_Titan_short_base"]] execVM "scripts\b2_restrictions.sqf";
0 = [["B_recon_M_F","B_sniper_F"],["srifle_GM6_F","srifle_LRR_F"]] execVM "scripts\b2_restrictions.sqf";
0 = [["B_recon_M_F","B_recon_JTAC_F","B_soldier_M_F","B_sniper_F"],["srifle_EBR_F","arifle_MXM_F"]] execVM "scripts\b2_restrictions.sqf";
0 = [["B_soldier_AR_F"],["LMG_Mk200_F","LMG_Zafir_F"]] execVM "scripts\b2_restrictions.sqf";
0 = [["B_diver_TL_F","B_diver_F"],["arifle_SDAR_F"]] execVM "scripts\b2_restrictions.sqf";

This restrict ATs, sniper and marksman rifles, LMGs and underwater weapons to respective classes.

PHP Code:
///////////////////////////////////////////////////////////////////////////////////////////////////
//  B2 Weapon Restriction Script v1.01                                                           //
//  Execute from mission init.sqf                                                                //
//  [classesArray,weaponsArray] execVM "scripts\b2_restrictions.sqf";                            //
//  0 = [["B_recon_M_F"],["srifle_GM6_F","srifle_LRR_F"]] execVM "scripts\b2_restrictions.sqf";  //
///////////////////////////////////////////////////////////////////////////////////////////////////

if (isDedicated) exitWith {};

private ["_r_class","_r_weap","_p_weap","_p_weap_base","_p_weap_base2","_p_weap_name","_s_weap","_s_weap_base","_s_weap_base2","_s_weap_name"];

while {true} do
{
  sleep 1;
  _r_class = _this select 0;
  _r_weap = _this select 1;

  _p_weap = primaryWeapon player;
  _p_weap_base = configName(inheritsFrom (configFile >> "CfgWeapons" >> _p_weap));
  _p_weap_base2 = configName(inheritsFrom (configFile >> "CfgWeapons" >> _p_weap_base));
  _p_weap_name = getText(configFile >> "CfgWeapons" >>_p_weap >> "displayName");
  
  _s_weap = secondaryWeapon player;
  _s_weap_base = configName(inheritsFrom (configFile >> "CfgWeapons" >> _s_weap));
  _s_weap_base2 = configName(inheritsFrom (configFile >> "CfgWeapons" >> _s_weap_base));
  _s_weap_name = getText(configFile >> "CfgWeapons" >>_s_weap >> "displayName");
  
  if (((_p_weap in _r_weap) || (_p_weap_base in _r_weap) || (_p_weap_base2 in _r_weap)) && !(typeOf player in _r_class))
  then {
    player removeWeapon _p_weap;
    hint format ["RESTRICTED WEAPON\n\nYou are not qualified\nto use %1",_p_weap_name];
  };
  
  if (((_s_weap in _r_weap) || (_s_weap_base in _r_weap) || (_s_weap_base2 in _r_weap)) && !(typeOf player in _r_class))
  then {
    player removeWeapon _s_weap;
    hint format ["RESTRICTED WEAPON\n\nYou are not qualified\nto use %1",_s_weap_name];
  };
} forEach allUnits;


Check Pilot/Gunner:
Made this two scritps for my missions, by combining them you can easily control the restrictions.
CheckPilot works for any actual drivers/pilots/copilots in any vehicle, CheckGunner - for any gunners.



For example (put in mission's init.sqf):
["Helicopter","B_Helipilot_F"] execVM "scripts\b2_checkPilot.sqf"; 
["Heli_Attack_01_base_F","B_Helipilot_F"] execVM "scripts\b2_checkGunner.sqf"; 
["Heli_Attack_02_base_F","B_Helipilot_F"] execVM "scripts\b2_checkGunner.sqf"; 

This allows only Bluefor pilots to fly all helicopters and man gunner positions in Attack helis, but also won't restrict anyone from using turrets in Transport helis (I don't think you need 2 years in flight school to handle minigun). Same way it can be used for any vehicles.

Known issue/feature: it only allows one class to be assigned on each type of vehicle.

PHP Code:
///////////////////////////////////////////////////////////////////////////////////////////////////
//  B2 Check Pilot Script v1.06                                                                  //
//  Execute from mission init.sqf                                                                //
//  [class,vehicleType] execVM "scripts\b2_checkPilot.sqf";                                      //
//  ["Helicopter","B_Helipilot_F"] execVM "scripts\b2_checkPilot.sqf";                           //
//  ["Wheeled_APC_F","B_Crew_F"] execVM "scripts\b2_checkPilot.sqf";                             //
///////////////////////////////////////////////////////////////////////////////////////////////////

if (isDedicated) exitWith {};

private ["_vehType","_crewType","_crewTypeName","_veh","_seats"];

_vehType = _this select 0;
_crewType = _this select 1;
_crewTypeName = getText(configFile >> "CfgVehicles" >> _crewType >> "displayName");

if (typeOf player != _crewType) then {
  while {(true)} do {
    waitUntil {vehicle player != player};
    _veh = vehicle player;
    
    if (_veh isKindOf _vehType && !(_veh isKindOf "ParachuteBase")) then {
      _seats = [driver _veh];
      if (_veh isKindOf "Helicopter") then {_seats = _seats + [_veh turretUnit [0]];};
        if (player in _seats) then {
          player action ["GetOut",_veh];
          waitUntil {vehicle player == player};
          hint format ["RESTRICTED VEHICLE\n\nRequired class: %1",_crewTypeName];
          if (isEngineOn _veh) then {_veh engineOn false};
        };
    };
  };
};  

///////////////////////////////////////////////////////////////////////////////////////////////////
//  B2 Check Gunner Script v1.06                                                                 //
//  Execute from mission init.sqf                                                                //
//  [class,vehicleType] execVM "scripts\b2_checkGunner.sqf";                                     //
//  ["Heli_Attack_01_base_F","B_Helipilot_F"] execVM "scripts\b2_checkGunner.sqf";               //
//  ["Wheeled_APC_F","B_Crew_F"] execVM "scripts\b2_checkGunner.sqf";                            //
///////////////////////////////////////////////////////////////////////////////////////////////////

if (isDedicated) exitWith {};

private ["_vehType","_crewType","_crewTypeName","_veh","_seats"];

_vehType = _this select 0;
_crewType = _this select 1;
_crewTypeName = getText(configFile >> "CfgVehicles" >> _crewType >> "displayName");

if (typeOf player != _crewType) then {
  while {(true)} do {
    waitUntil {vehicle player != player};
    _veh = vehicle player;
    if (_veh isKindof _vehType && !(_veh isKindOf "ParachuteBase")) then {
      _seats = [gunner _veh];
      if (_veh isKindOf "Tank") then {_seats = _seats + [_veh turretUnit [0]]; };
      if (_veh isKindOf "Heli_Transport_01_base_F") then {_seats = _seats + [_veh turretUnit [2]];};
        if (player in _seats) then {
        player action ["GetOut",_veh];
        waitUntil {vehicle player == player};
        hint format ["RESTRICTED VEHICLE\n\nRequired class: %1",_crewTypeName];
      };
    };
  };
};  


Keep Gunner:
Redone script from scratch with completely different principle.
Now it spawns co-pilot and gunners in designated number of turrets.
Useful, if you don't like seeing Transport helicopters flying defenceless just because nobody wants to sit by the minigun whole time.
Don't use for playable slots - players won't be able to leave the turret.

Execute from any vehicle init:
0 = [vehicle,crewSide(opt),crewNum(opt),crewInit(opt)] execVM "scripts\b2_keepGunner.sqf";
0 = [this] execVM "scripts\b2_keepGunner.sqf"; - will spawn 1 bluefor crewman,

crewSide: west (default), east, independent
crewNum: 1 (default), 2, 3 (default for Ghosthawks)
crewInit: init string for each crew member, default - empty

///////////////////////////////////////////////////////////////////////////////////////////////////
//  B2 Keep Gunner Script v1.06                                                                  //
//  Exec from any vehicle init:                                                                  //
//  0 = [vehicle,crewSide(opt),crewNum(opt),crewInit(opt)] execVM "scripts\b2_keepGunner.sqf";   //
//    crewSide: west (default), east, independent                                                //
//    crewNum: 1 (default), 2, 3 (default for Ghosthawks)                                        //
//    crewInit: init string for each crew member, default - empty                                //
//  0 = [this,west,3] execVM "scripts\b2_keepGunner.sqf";                                        //
///////////////////////////////////////////////////////////////////////////////////////////////////

if (!isServer) exitWith {};

private ["_veh","_crewSide","_crewNum","_crewInit","_crewType","_crewHelm","_crewGrp","_crew"];

_veh = _this select 0;
_crewSide = if (count _this > 1) then {_this select 1;} else {west};
_crewNum = if (count _this > 2) then {_this select 2;} else {
  if (_veh isKindOf "Heli_Transport_01_base_F") then {3} else {1};
};
_crewInit = if (count _this > 3) then {_this select 3;} else {""};
///////////////////////////////////////////////////////////////////////////////

//Selecting type
if (_veh isKindOf "Helicopter") then {
  switch (_crewSide) do {
    case west: {_crewType = "B_Helipilot_F"; _crewHelm = "H_CrewHelmetHeli_B";};
    case east: {_crewType = "O_Helipilot_F"; _crewHelm = "H_CrewHelmetHeli_O";};
    case independent: {_crewType = "I_Helipilot_F"; _crewHelm = "H_CrewHelmetHeli_I";};  
  };
} else {
  switch (_crewSide) do {
    case west: {_crewType = "B_Crew_F";};
    case east: {_crewType = "O_Crew_F";};
    case independent: {_crewType = "I_Crew_F";};
  };
};

///////////////////////////////////////////////////////////////////////////////

//Spawning crew
_crewGrp = createGroup _crewSide;
for "_i" from 1 to _crewNum do {
_crewType createUnit [getPos _veh,_crewGrp,_crewInit];
_crew = (units _crewGrp);
};

//Adding helmets
sleep 0.1;
if (_veh isKindOf "Helicopter") then {
  {_x addHeadgear _crewHelm;} forEach _crew;
};

//Starting cycle
while {alive _veh} do {
  for "_i" from 0 to (_crewNum-1) do {
    {
      _x moveInTurret [_veh,[_i]];
      _x lock true;
      //[_x] joinSilent (driver _veh);
      //if (isNull (driver _veh)) then {[_x] joinSilent _crewGrp};
    } forEach _crew;
  };
  sleep 1;
};

//Clearing group, deleting bodies
deleteGroup _crewGrp;
{deleteVehicle _x} forEach _crew;  


Simple Heli Door Script:
Another simple script, that automatically opens GhostHawk doors while it's altitude is less then 8m and speed is less then 45 km/h.
Works pretty much same way as the landing gears.

Inspired by Heli Door Open Script by Delta 1 Actual



////////////////////////////////////////////////////////////////////////////////
//  B2 Heli Door Script v1.06                                                 //
//  Execute from any compatible Helicopter init field:                        //
//  0 = [this] execVM "scripts\b2_heliDoors.sqf";                             //
//                                                                            //
//  Credits:                                                                  //
//    Delta 1 Actual for his Heli Door Open Script                            //
//    DJPorterNZ for CH-49 and Mi-48 fix                                      //
//                                                                            //
//  Compatible Aircraft:                                                      //
//    UH-80 Ghost Hawk                                                        //
//    CH-49 Mohawk                                                            //
//    Mi-48 Kajman                                                            //
////////////////////////////////////////////////////////////////////////////////

if (!isServer) exitWith {};

private ["_veh","_alt","_speed"];

_veh = _this select 0;

switch (typeof _veh) do {
    // UH-80 Ghost Hawk
    case "B_Heli_Transport_01_F": {
    while {alive _veh} do {
      sleep 0.5;
      _alt = getPos _veh select 2;
      _speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
      if ((_alt < 8) && (_speed < 12)) then {
        _veh animateDoor ['door_R',1]; 
        _veh animateDoor ['door_L',1];
      } else {
        _veh animateDoor ['door_R',0]; 
        _veh animateDoor ['door_L',0];
      };
    };
  };
    // UH-80 Ghost Hawk (Camo)
    case "B_Heli_Transport_01_camo_F": {
    while {alive _veh} do {
      sleep 0.5;
      _alt = getPos _veh select 2;
      _speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
      if ((_alt < 8) && (_speed < 12)) then {
        _veh animateDoor ['door_R',1]; 
        _veh animateDoor ['door_L',1];
      } else {
        _veh animateDoor ['door_R',0]; 
        _veh animateDoor ['door_L',0];
      };
    };
  };
  // CH-49 Mohawk
  case "I_Heli_Transport_02_F": {
    while {alive _veh} do {
      sleep 0.5;
      _alt = getPos _veh select 2;
      _speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
      if ((_alt < 8) && (_speed < 12)) then {
        _veh animateDoor ['door_back_R',1]; 
        _veh animateDoor ['door_back_L',1];
        _veh animate ['CargoRamp_Open',1];
      } else {
        _veh animateDoor ['door_back_R',0]; 
        _veh animateDoor ['door_back_L',0];
        _veh animate ['CargoRamp_Open',0];
      };
    };
  };
  // Mi-48 Kajman
  case "O_Heli_Attack_02_F": {
    while {alive _veh} do {
      sleep 0.5;
      _alt = getPos _veh select 2;
      _speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
      if ((_alt < 8) && (_speed < 12)) then {
        _veh animateDoor ['door_R',1]; 
        _veh animateDoor ['door_L',1];
      } else {
        _veh animateDoor ['door_R',0]; 
        _veh animateDoor ['door_L',0];
      };
    };
  };
  // Mi-48 Kajman (Black)
  case "O_Heli_Attack_02_black_F": {
    while {alive _veh} do {
      sleep 0.5;
      _alt = getPos _veh select 2;
      _speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
      if ((_alt < 8) && (_speed < 12)) then {
        _veh animateDoor ['door_R',1]; 
        _veh animateDoor ['door_L',1];
      } else {
        _veh animateDoor ['door_R',0]; 
        _veh animateDoor ['door_L',0];
      };
    };
  };
}; 


PMC Offroad and ATV Script:
Simple script that turns any civillian offroad into PMC offroad: white, with push bar, roll bar and some backpacks attached to sides.
For ATV it simply makes it black.
Put this into any civillian offroad or any ATV init:
0 = [this] execVM "scripts\b2_pmcVeh.sqf";

PHP Code:
///////////////////////////////////////////////////////////////////////////////////////////////////
//  B2 PMC Offroad and ATV Script v1.01                                                          //
//  Put in civilian offroad init                                                                 //
//  0 = [this] execVM "scripts\b2_pmcVeh.sqf";                                                   //
///////////////////////////////////////////////////////////////////////////////////////////////////

if (!isServer) exitWith {};

private ["_veh"];

_veh = _this select 0;

if (_veh isKindOf "Offroad_01_base_F") then {
  _veh = _this select 0;
  _veh animate ["HideConstruction", 0];
  _veh animate ["HideBackpacks", 0];
  _veh animate ["HideBumper1", 1];
  _veh animate ["HideBumper2", 0];
  _veh animate ["HideDoor1", 0];
  _veh animate ["HideDoor2", 0];
  _veh animate ["HideDoor3", 0];
  _veh animate ["HideGlass1", 1];
  _veh animate ["HideGlass2", 1];

  //_veh setObjectTexture [0, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_BASE01_CO.paa"]; //Sand
  //_veh setObjectTexture [1, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_BASE01_CO.paa"]; //Sand
  _veh setObjectTexture [0, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_BASE02_CO.paa"]; //White
  _veh setObjectTexture [1, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_BASE02_CO.paa"]; //White
  //_veh setObjectTexture [0, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_ti_ca.paa"]; //Black
  //_veh setObjectTexture [1, "\A3\soft_F\Offroad_01\Data\Offroad_01_ext_ti_ca.paa"]; //Black
};

if (_veh isKindOf "Quadbike_01_base_F") then {
  _veh setObjectTexture [0, "A3\Soft_F_Beta\Quadbike_01\Data\Quadbike_01_CIV_BLACK_CO.paa"];
  _veh setObjectTexture [1, "A3\Soft_F_Beta\Quadbike_01\Data\Quadbike_01_wheel_CIVBLACK_CO.paa"];
}; 


Loadout Script:
Ok, here's the big one.
This script simply gives preset loadout to any unit.
It could be BLUEFOR medic carrying GREENFOR LMG and OPFOR uniform, or OPFOR soldier in PG Services clothes carrying RH Mk18.


It consist of two major parts:
First, "Armies", where you can set types of weapons and gear used by each particular army.
Second, "Loadouts", which sets weapon, camo, backpack and amount of ammunition that will be carried by each class of any army.

Current version works with this addons:
NATO SF and Russian Spetsnaz Weapons
UK Special Forces
PG Services - Private Military Company

Addons support works this way:
Server should have same addons as players to have proper ammo in vehicles and boxes - default ammo will be loaded otherwise.
If player connects with supported mods, he will have mod stuff loaded.
If player connects with no mods, he will have preset loadout with BIS weapons. He won't see modded weapons or camo, but at least he won't be kicked straight away as if placed units or ammobox from mod in editor.

Execute from unit's init:
0 = [unit,class,army,silencers] execVM "scripts\b2_loadouts.sqf";

0 = [this,"grenadier","uksf",1] execVM "scripts\b2_loadouts.sqf"; - UKSF grenadier's loadout with silenced weapon
0 = [this,"medic","pmc"] execVM "scripts\b2_loadouts.sqf"; - PMC medic's loadout
0 = [this,"officer"] execVM "scripts\b2_loadouts.sqf"; - default army officer's loadout
0 = [this] execVM "scripts\b2_loadouts.sqf"; - default army/default loadout (soldier without backpack)

Currently there are one default-"oops-something-gone-wrong" army and two example armies:
"uksf" - United Kingdom Special Forces (supports massi's NATO Weapons and UK SFTG)
"pmc" - Private Military Contractors (supports massi's NATO Weapons and PG Services)

Classes:
"officer"
"grenadier"
"eod"
"lmg_gunner"
"marksman"
"rifleman_at"
"medic"
"sniper"
"spotter"
"pilot"
"crewman"
"diver"

"hunter" - for vehicles

Feel free to adjust "armies", individual loadouts and implemented mods to your particular unit's needs.


Interactive Whiteboard Script (WIP):
Well, name says it all. See example mission, to find out how it works.
It's based on this script from A2: http://www.armaholic.com/page.php?id=15289
[X] in trigger exec field ( 0 = [X] execVM "intel\init.sqf"; ) controls board rotation.
0 means board will be facing south, while 90 - facing east.



It still has couple unsolved issues: only first player who joins the server able to control the Whiteboard, placing and rotation could be simplified, board flickering while loading next texture, lightsource not visible to other players etc.


Changelog:
v09-04-2013
  • New scripts added: Weapon Restriction Script & Loadout Script
  • Updated all scripts


  • Forum topic:
    - BI forums




    Enable javascript to be able to download from Armaholic please!



    Tags: No tags