demellion

Vehshop Functions

Jul 6th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.76 KB | None | 0 0
  1.  
  2. DT_fnc_saveVehicleDB = {
  3.     params [
  4.         ['_vehicleData',[],[[]]]
  5.     ];
  6.     _vehicleData params ['_classname','_shopClass','_colorData','_materialData','_paintData'];
  7.     private _players = allPlayers select {(owner _x) isEqualTo remoteExecutedOwner};
  8.     if (_players isEqualTo []) exitWith {};
  9.     private _player = _players select 0;
  10.     private _uid = getPlayerUID _player;
  11.  
  12.     // Create
  13.     private _vehicle = objNull;
  14.     private _createVehicle = getNumber (missionConfigFile >> "vehshop_config" >> "Shops" >> _shopClass >> "createVehicle");
  15.     if (_createVehicle isEqualTo 1) then {
  16.         private _spawnMarker = getText (missionConfigFile >> "vehshop_config" >> "Shops" >> _shopClass >> "spawnPointMarker");
  17.         private _markerPos = getMarkerPos _spawnMarker;
  18.         if (_markerPos isEqualTo [0,0,0]) then {_markerPos = getPos _player}; // Marker is undefined, spawn neaby player.
  19.         _markerPos = [_markerPos, 1, 50, 8, 1, 20, 0, [], _markerPos] call BIS_fnc_findSafePos;
  20.         _vehicle = _classname createVehicle _markerPos;
  21.         _player moveInAny _vehicle;
  22.         [_vehicle,[_colorData,_materialData,_paintData]] call DT_fnc_colorVehicle;
  23.     };
  24.  
  25.     // Life Framework
  26.     if (isNil {DB_fnc_asyncCall}) exitWith {}; // we dont have life framework  
  27.     private _type = switch (true) do {
  28.         case (_classname isKindOf "Car"): {"Car"};
  29.         case (_classname isKindOf "Air"): {"Air"};
  30.         case (_classname isKindOf "Ship"): {"Ship"};
  31.         default {"Car"}
  32.     };
  33.     private _side = switch (side _player) do {
  34.         case west:{"cop"};
  35.         case civilian: {"civ"};
  36.         case independent: {"med"};
  37.         default {"civ"};
  38.     };
  39.     private _plate = round(random(1000000));       
  40.     private _query = format ["
  41.         INSERT INTO vehicles (side, classname, type, pid, alive, active, inventory, color, plate, gear, damage, texdata)
  42.         VALUES ('%1', '%2', '%3', '%4', '%8','1','""[[],0]""', '%5', '%6','""[]""','""[]""', '%7')
  43.     ",_side,_classname,_type,_uid,0,_plate,[_colorData,_materialData,_paintData],_createVehicle];
  44.     [_query,1] call DB_fnc_asyncCall;
  45.  
  46.     // Key management
  47.     [_vehicle] remoteExecCall ["life_fnc_addVehicle2Chain",_player];
  48.     _vehicle setVariable ["dbInfo",[_uid,_plate],true];
  49.     [_uid,side _player,_vehicle,1] call TON_fnc_keyManagement;
  50.     _vehicle setVariable ["vehicle_info_owners",[[_uid,name _player]],true];
  51.     _vehicle disableTIEquipment true;
  52.     [_vehicle] call life_fnc_clearVehicleAmmo;
  53. };
  54.  
  55. DT_fnc_colorVehicle = {
  56.     params [
  57.         ['_vehicle',objNull,[objNull]],
  58.         ['_data',["",-1,[]],[[]]]
  59.     ];
  60.     _data params ['_colorData','_materialData','_paintData'];
  61.     _vehicle setVariable ['shopData',_data,true];
  62.     if !(_colorData isEqualTo '') then {_vehicle setObjectTextureGlobal [0,_colorData]};
  63.     if !(_materialData isEqualTo -1) then {
  64.         private _materials = getArray (missionConfigFile >> "vehshop_config" >> "materials");
  65.         if (_materialData > (count _materials - 1)) exitWith {};
  66.         private _material = (_materials select _materialData) select 1;
  67.         _vehicle setObjectMaterialGlobal [0,_material];
  68.     };
  69.     if !(_paintData isEqualTo []) then {
  70.         _paintData params ['_source','_sourceIndex'];
  71.         switch (_source) do {
  72.             case "textureSources": {
  73.                 private _textures = ('true' configClasses (configFile >> "CfgVehicles" >> typeOf _vehicle >> "textureSources")) apply {
  74.                     private _texture = (getArray (_x >> "textures")) select 0;
  75.                     _texture
  76.                 };
  77.                 private _texture = _textures select _sourceIndex;
  78.                 _vehicle setObjectTextureGlobal [0,_texture];
  79.             };
  80.             default {
  81.                 private _textures = getArray (missionConfigFile >> "vehshop_config" >> "Shops" >> _source >> typeOf _vehicle >> "customTextures");
  82.                 if (_sourceIndex > (count _textures - 1)) exitWith {};
  83.                 _textures = _textures apply {_x select 1};
  84.                 private _texture = _textures select _sourceIndex;
  85.                 _vehicle setObjectTextureGlobal [0,_texture];
  86.             };
  87.         };
  88.     }; 
  89. };
Add Comment
Please, Sign In to add comment