Advertisement
Guest User

personal_plyer_bike_v0.2

a guest
Dec 10th, 2014
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.18 KB | None | 0 0
  1. //
  2. // jahangir13: 12/2014 - Personal Player Bike v0.2
  3. // (jahangir@gmx.de)
  4. // Personal bike for players (temporarily spawned). Can be packed/unpacked.
  5. // PlayerUID is stored with the bike, so you can only pack your own bike.
  6. // If packed, overall damage is remembered and uniformly assigned to bike if unpacked again.
  7. //
  8. // Place script into the mission folder (or custom folder within the mission folder)
  9. // Code to copy and instructions at end of file (init.sqf / fn_selfActions.sqf / battleye / Antihack)
  10. //
  11.  
  12. private ["_zedAttractDist", "_distToPlayer", "_packUnpackTime", "_keepDamage", "_degrees", "_getOnBikeDirectly", "_ownername", "_location", "_positionBike", "_playerdir", "_bike"];
  13.  
  14. //#################################################################################################################
  15. // Config options to change
  16. _zedAttractDist = 30; // distance in meter zombies get attracted
  17. _distToPlayer = [0,4,1]; // distance of spawned bike in front of player (4 meter, 1m above)
  18. _packUnpackTime = 8; // time to pack/unpack in seconds
  19. _keepDamage = true; // remember overall bike damage
  20. _degrees = 40; // degrees of the angle the bike has in relation to the player (easier to get the menu with angle)
  21. _getOnBikeDirectly = true; // player hops onto the bike directly as driver after unpacking
  22. // No need to change anything below
  23. //#################################################################################################################
  24.  
  25. if ( dayz_combat == 1 ) exitWith { cutText [format["You cannot pack/unpack the bike while in combat!"], "PLAIN DOWN"] };
  26. if (r_player_unconscious) exitWith { cutText [format["You cannot get a bike while unconscious!"], "PLAIN DOWN"] };
  27.  
  28. // part: unpack player bike
  29. if (_this select 3 == "unpack") then {
  30.    
  31.     s_playerHadBike = false;
  32.     {
  33.         _ownername = _x getVariable["Ownername", "nil"];
  34.             if ( _ownername == getPlayerUID player ) exitWith {        
  35.                 s_playerHadBike = true;
  36.             };
  37.     } count (player nearEntities [["MMT_Civ"], 25000]);
  38.    
  39.     // exit if already unpacked
  40.     if ( s_playerHadBike ) then {
  41.         cutText [format["Your bike is already unpacked!"], "PLAIN DOWN"];
  42.         breakOut "leaveScript";
  43.     };
  44.    
  45.     // spawn in front of player, 4m distance
  46.     _location = [];
  47.     _location = (getPosATL player) findEmptyPosition [2,8,"MMT_Civ"];
  48.     // if no suitable position found, message the player
  49.     if ( count _location == 0 ) then {
  50.         cutText [format["No suitable position found. Look for more space."], "PLAIN DOWN"];
  51.         breakOut "leaveScript";
  52.     };
  53.    
  54.     // in front of the player where he was looking when executing the command
  55.     _positionBike = player modelToWorld _distToPlayer;
  56.     // get direction of player at executing the command
  57.     _playerdir = getDir player;
  58.    
  59.     player removeAction s_player_unpackbike;
  60.     player playActionNow "Medic";
  61.     // attract zombies
  62.     [player,"repair",0,false,_zedAttractDist] call dayz_zombieSpeak;
  63.     [player,_zedAttractDist,true,(getPosATL player)] spawn player_alertZombies;
  64.    
  65.     sleep _packUnpackTime;
  66.  
  67.     _bike = createVehicle ["MMT_Civ", _location, [], 0, "CAN_COLLIDE"];
  68.     _bike setVariable ["MalSar",1,true];
  69.    
  70.     // assign bike to player (playeruid)
  71.     _bike setVariable["Ownername", (getPlayerUID player), true];
  72.    
  73.     // set damage (uniformly distributed)
  74.     if (_keepDamage) then {
  75.         _bike setDammage s_bikeDamage;
  76.     };
  77.     // set position and direction
  78.     _bike setVehiclePosition [_positionBike, [], 0];
  79.     _bike setDir (_playerdir - _degrees);
  80.     player reveal _bike;
  81.    
  82.     cutText [format["Unpacked the bike"], "PLAIN DOWN"];
  83.  
  84.     player switchMove "";
  85.     player playActionNow "stop";
  86.     // Get player on bike as driver
  87.     if ( _getOnBikeDirectly ) then {
  88.         player moveInDriver _bike;
  89.     };
  90.    
  91.     s_playerHadBike = true;
  92. };
  93.  
  94. // part: pack player bike
  95. if (_this select 3 == "pack") then {
  96.  
  97.     // only the own bike (playeruid in variable Ownername) can be packed
  98.     _ownername = cursorTarget getVariable["Ownername", "nil"];
  99.     if ( _ownername != getPlayerUID player ) exitWith { cutText [format["This is not your bike, you cannot pack it!"], "PLAIN DOWN"] };
  100.  
  101.     _bike = cursorTarget;
  102.     if (typeOf _bike == "MMT_Civ") then {
  103.         if ( _keepDamage ) then {
  104.             s_bikeDamage = getDammage _bike;
  105.         };
  106.    
  107.         _bike setVariable["Ownername", nil, true];
  108.         player removeAction s_player_packbike;
  109.         player playActionNow "Medic";
  110.         // Attract zombies
  111.         [player,"repair",0,false,_zedAttractDist] call dayz_zombieSpeak;
  112.         [player,_zedAttractDist,true,(getPosATL player)] spawn player_alertZombies;
  113.        
  114.         sleep _packUnpackTime;
  115.        
  116.         deletevehicle _bike;
  117.        
  118.         cutText [format["Packed the bike"], "PLAIN DOWN"];
  119.        
  120.         player switchMove "";
  121.         player playActionNow "stop";
  122.        
  123.         s_playerHadBike = false;
  124.     } else {
  125.         cutText [format["Look at the bike to re-pack it!"], "PLAIN DOWN"];
  126.     };
  127. };
  128.  
  129. //--------------------------------------------------------------------------------------------------------------------------------------------------
  130.  
  131. // Variable initialization: Place somewhere at end of init.sqf in the mission (or where you initialize variables normally).
  132. /* copy from below line
  133.  
  134. // jahan - begin player bike
  135. s_playerHadBike = false;
  136. s_player_unpackbike = -1;
  137. s_player_packbike = -1;
  138. s_bikeDamage = 0;
  139. // check for existing player bike
  140. {
  141.     _ownername = _x getVariable["Ownername", "nil"];
  142.     if ( _ownername == getPlayerUID player ) exitWith {          
  143.         s_playerHadBike = true;
  144.     };
  145. } count (player nearEntities [["MMT_Civ"], 25000]);
  146. // jahan - end player bike
  147.  
  148. copy until above line */
  149.  
  150. //--------------------------------------------------------------------------------------------------------------------------------------------------
  151.  
  152. // fn_selfAction.sqf part: Place somewhere at the beginning (change 2 paths to point to player_bike.sqf script (here custom\jtools\)!)
  153. /* copy from below line
  154.  
  155. ///// ################ jahan - Begin Player Bike ########################################        
  156. if ((speed player < 1) && !(player isKindOf "PZombie_VB") && _canDo && !_inVehicle ) then {  
  157.    
  158.     ///// unpack bike addaction:
  159.     if( ( isNull cursorTarget ) ) then {
  160.         if ((s_player_unpackbike < 0) && (!s_playerHadBike)) then {
  161.             s_player_unpackbike = player addAction [("<t color=""#DF01D7"">" + ("Unpack Bike") +"</t>"),"custom\jtools\player_bike.sqf","unpack",-1,false,true,"", ""];
  162.         };
  163.     } else {
  164.         player removeAction s_player_unpackbike;
  165.         s_player_unpackbike = -1;
  166.     };
  167.  
  168.     ///// pack bike addaction:
  169.     if ( !(isNull cursorTarget) && (player distance cursorTarget < 3) && (typeOf cursorTarget == "MMT_Civ") ) then {
  170.         if ((s_player_packbike < 0) && ( s_playerHadBike )) then {
  171.             s_player_packbike = player addAction [("<t color=""#DF01D7"">" + ("Pack Bike") +"</t>"),"custom\jtools\player_bike.sqf","pack",-1,false,true,"", ""];
  172.         };
  173.     } else {
  174.         player removeAction s_player_packbike;
  175.         s_player_packbike = -1;
  176.     };
  177. };
  178. ///// ################ jahan - End Player Bike ########################################
  179.  
  180. copy until above line */
  181.  
  182. //--------------------------------------------------------------------------------------------------------------------------------------------------
  183.  
  184. // Battleye: (if you don't want/need damage comment out the damage lines and don't add this to the BE filters)
  185. /* If kicked by Battleye script restriction (setDammage):
  186. Find the line:
  187. 5 "setDammage"
  188. and add this at the end:
  189. !="_bike setVariable[\"Ownername\", _playeruid, true];"
  190. So that it looks like this:
  191. 5 "setDammage" !="_bike setVariable[\"Ownername\", _playeruid, true];"
  192. */
  193.  
  194. /* If killed when sitting on the bike:
  195. Add the classname of the bike (MMT_Civ) to the array in your custom variables.sqf:
  196. DZE_safeVehicle = ["ParachuteWest","ParachuteC","MMT_Civ" ];
  197. or at the init.sqf player bike lines (but after variables.sqf is called)
  198. DZE_safeVehicle = DZE_safeVehicle + ["MMT_Civ"];
  199. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement