Skip to content

Instantly share code, notes, and snippets.

@bosoy
Last active June 16, 2016 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bosoy/bf528d465f37406a290ee97b378ba356 to your computer and use it in GitHub Desktop.
Save bosoy/bf528d465f37406a290ee97b378ba356 to your computer and use it in GitHub Desktop.
/*
Функция контроля экипажа техники.
Автор: Dimon UA
Параметры:
0. _this - техника
1. - места что блокируются
"driver"
"gunner"
"commander" - блокировка места командира - разрешено только для var_restrictedVeh_commander
"crew" - блокировка всей техники (вкл. пассажиров) разрешено только для var_restrictedVeh_allcrew
[0,1] - блокировка туррели
["cargo",2] - блокировка пассажирского места с индексом 2
2. - "east"/"west"/"guer"/"civ"/"" - проверка игрока на сторону (опционально)
Примеры запуска в ините
_=[this,"driver","gunner"] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
_=[this,"driver","gunner"] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
_=[this,"driver","gunner","commander"] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
_=[this,"driver","gunner","commander"] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
_=[this,"driver","gunner","commander","east"] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
_=[this,"driver","gunner","commander","east",[0,1],["cargo",3]] call compile preprocessFileLineNumbers "fnc_inCrew_a3.sqf";
*/
#define Cfgman (configFile >> "CfgVehicles" >>(typeOf _unitToCheck) >> "_generalmacro")
#define allcrew (typeOf _unitToCheck) in var_restrictedVeh_allcrew
#define iscrew (_vehicle iskindof "landvehicle" && (toLower(gettext Cfgman) find "crew" > -1 || toLower(gettext Cfgman) find "driver" > -1 || ((typeOf _unitToCheck) in var_restrictedVeh_commander)) || (_vehicle iskindof "air" && toLower(gettext Cfgman) find "pilot" > -1) || allcrew )
//======================= функция сканирования действий игрока внутри техники =====================//
fnc_Crewcontrol = {
private ["_typein", "_place", "_veh", "_move","_closeturrets","_closecargo"];
_player = _this select 0;
_place = assignedVehicleRole _player;
_veh = (vehicle _player); //фикисируем технику
_move=false;
_index = -1;
_blockpositions = _veh getVariable "BLOCKPOS";
_positions = _blockpositions select 0;
_closeturrets = _blockpositions select 1;
_closecargo = _blockpositions select 2;
_oldpos= _player getVariable "POSPLAYER";
_move = ((_place select 0) in _positions)
|| ((_place select 0) == "Turret" && {(_place select 1) in _closeturrets})
|| ((_place select 0) == "cargo" && {(_veh getCargoIndex _player) in _closecargo});
// если переменая _move активна то запускаем возврат игрока на предыдущее место.
if _move then
{
call {
if ((_oldpos select 0) in ["commander","gunner","driver"]) exitwith {_player action [format ["moveTo%1",(_oldpos select 0)], _veh]};
if ((_oldpos select 0) == "cargo") exitwith {_player action ["moveTocargo", _veh,(_oldpos select 1)]};
if ((_oldpos select 0) == "Turret") exitwith {_player action ["moveToTurret", _veh,(_oldpos select 1)]};
};
_move = false;hint "this place you are not available";
}else{
_player setVariable ["POSPLAYER", _place,true];
};
};
//================= функция запускаемая при входе в технику ========================//
fnc_inCrewfilter = {
private ["_type", "_vehicle", "_unitToCheck", "_balca", "_side", "_warningMsg", "_state","_closeturrets","_closecargo"];
_vehicle = _this select 0;
_unitToCheck = _this select 2;
_blockpositions = _vehicle getVariable "BLOCKPOS";
_positions = _blockpositions select 0;
_closeturrets = _blockpositions select 1;
_closecargo = _blockpositions select 2;
_side = _blockpositions select 3;
_exit = false;
_position= assignedVehicleRole _unitToCheck;
if (isnil {_vehicle getVariable "CREW_GETININDEX"}) then { _vehicle setVariable ["CREW_GETININDEX",_type,true];};
if !(local _unitToCheck) exitWith {};
//если необходимо то делаем проверку на сторону
if (count (_side)>0 && {!(toLower (str (side (group _unitToCheck))) in _side)}) exitwith {moveOut _unitToCheck;hint "Not available your side";};
//====================================================================
if ((!("crew" in _positions) && {iscrew}) || (("crew" in _positions) && {allcrew})) exitwith {}; // если игрок подошел заданным параметрам то выходим из скрипта
_exit = ((_position select 0) in _positions)
|| ((_position select 0) == "Turret" && {(_position select 1) in _closeturrets})
|| ((_position select 0) == "cargo" && {(_vehicle getCargoIndex _unitToCheck) in _closecargo})
|| (_unitToCheck in (crew _vehicle) && {"crew" in _positions});
if _exit exitwith {moveOut _unitToCheck;hint "You are not authorised to crew this vehicle!";_exit = false;};
if ((_position select 0) == "cargo" && {count (_position) <2}) then {_position pushback (_vehicle getCargoIndex _unitToCheck)};
_unitToCheck setVariable ["POSPLAYER", _position,true];
_unitToCheck addEventHandler ["SeatSwitchedMan",{_this call fnc_Crewcontrol}];
_unitToCheck addEventHandler ["GetOutMan",{(_this select 0) setVariable ["POSPLAYER", [],true];(_this select 0) removeAllEventHandlers "SeatSwitchedMan";(_this select 0) removeAllEventHandlers "GetOutMan"}];
};
//=======================================================================
private ["_object", "_closepos", "_result", "_side","_closecargo","_closeturrets"];
_object = _this select 0; //фиксируем обьект
_blockpos=[[],[],[],[]];
{
call {
if (_x isEqualType [] && {_x in (allTurrets _object)}) exitwith {(_blockpos select 1) pushback _x};
if (_x isEqualType [] && {(_x select 0) == "cargo"}) exitwith {(_blockpos select 2) pushback _x};
if (typeName _x == "STRING" && {_x in ["west","east","guer","civ"]}) exitwith {(_blockpos select 3) pushback _x};
if (typeName _x == "STRING") exitwith {(_blockpos select 0) pushback _x};
};
} foreach _this;
if ("gunner" in (_blockpos select 0)) then {(_blockpos select 1) pushBack [0]};
if ("commander" in (_blockpos select 0)) then {(_blockpos select 1) pushBack [[0],0]};
_object setVariable ["BLOCKPOS", _blockpos,true];
_object addEventHandler ["GetIn",{_this call fnc_inCrewfilter}];
_object addEventHandler ["killed",{(_this select 0) removeAllEventHandlers "Getin";(_this select 0) removeAllEventHandlers "killed"}];
if (!isDedicated) then {
waitUntil{(player==player)};
waitUntil{alive player};
waitUntil{local player};
var_restrictedVeh_commander = [];
var_restrictedVeh_allcrew = [];
if (!isnil {isCrew} ) then { var_restrictedVeh_allcrew=var_restrictedVeh_allcrew + isCrew;};
//проверяем не находится ли игрок в технике, если находится запускаем проверку его позиции
if (vehicle player != player && {!isnil {(vehicle player) getVariable "CREW_GETININDEX"}}) then { [[(vehicle player),"",player],(vehicle player) getVariable "CREW_GETININDEX"] call fnc_inCrew};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment