player2_dz

Untitled

Aug 18th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 8.24 KB | None | 0 0
  1. /*
  2.     Laptop in Mayor Building
  3.         Option to start bank heist
  4.             Have to hold spot for 600 seconds
  5.             Given X coins if still there at end
  6. */
  7.  
  8. /*---------------------------------------------------------------------------
  9.     Config
  10. ---------------------------------------------------------------------------*/
  11. p2h_objectPosition        = [13715.8,2908.5,0.738091];                              //Hackable Object World Positon (X,Y,Z)
  12. p2h_objectDirection       = 181.245;                                                //Hackable Object Direction (NESW)
  13. p2h_objectModelName       = "RU_functionary2";                                      //Name of the laptop model
  14. p2h_objectActionText      = "Rob The Mayor";                                        //Text on the scroll action of the laptop
  15. p2h_objectCollect         = "Collect Funds";                                        //Text to display at end of hack on the laptop scroll action
  16. p2h_hackLengthMinutes     = 10;                                                     //How long it takes to hack the bank
  17. p2h_hackRewardMinMax      = [1000000,5000000];                                      //Hack reward min and max
  18. p2h_minPlayersToRun       = 10;                                                     //Min player count on server before starting
  19. p2h_maxHackDistance       = 50;                                                     //Max distance from the laptop the hacker can be before it gets cancelled
  20. p2h_minHackDistance       = 5;                                                      //How close the player has to be to start and end the hack
  21. p2h_hackStartAnnouncement = "The mayor is being robbed!";                           //Global message to display when someone starts robbing
  22. p2h_hackMidAnnouncement   = "The mayor is still being robbed!";                     //Global message to display when someone is half way through robbing
  23. p2h_hackEndAnnoucnement   = "The mayor has been robbed!";                           //Global message to display when someone finishes robbing
  24. p2h_hackerRanAway         = "The mayors robber has ran away with out the money!";   //Global message to display when someone starts robbing and runs away
  25. p2h_hackerDied            = "The mayors robber has died!";                          //Global message to display when the hacker dies
  26.  
  27. if (p2h_testMode) then {}
  28.     p2h_hackLengthMinutes = 10;
  29.     p2h_minPlayersToRun = 1;
  30. };
  31.  
  32. p2h_init = {
  33.     //Client Side
  34.     if (!isDedicated && !isServer && hasInterface) exitWith {
  35.  
  36.         //Global var inits
  37.         p2h_isHacking    = 0;
  38.         p2h_action       = -1;
  39.         p2h_hackProgress = 0;
  40.         p2h_cStartHack = nil;
  41.         p2h_sHackStarted = nil;
  42.  
  43.         //Client side files
  44.         p2h_actionLoop = compile preprocessFileLineNumbers "p2h\p2h_actionLoop.sqf";
  45.         p2h_getMoney   = compile preprocessFileLineNumbers "p2h\p2h_getMoney.sqf";
  46.         p2h_startHack  = compile preprocessFileLineNumbers "p2h\p2h_startHack.sqf";
  47.         p2h_endHack    = compile preprocessFileLineNumbers "p2h\p2h_endHack.sqf";
  48.         p2h_getMsg     = compile preprocessFileLineNumbers "p2h\p2h_getMsg.sqf";
  49.  
  50.         //Start action loop
  51.         [] spawn {
  52.             while {true} do {
  53.                 call p2h_actionLoop;
  54.                 uiSleep 0.05;
  55.             };
  56.         };
  57.     };
  58.  
  59.     //Server Side
  60.     if (isServer) exitWith {
  61.  
  62.  
  63.  
  64.     };
  65.    
  66. };
  67.  
  68. //Start Hacking (Server-Side)
  69. p2h_serverStartHacking = {
  70.    
  71.     //Get player who started the hack
  72.     _playerObj = objNull;
  73.     _playerObj = _this;
  74.  
  75.     if (isNil '_playerObj')         exitWith {};
  76.     if (isNull _playerObj)          exitWith {};
  77.  
  78.     //Get id to send msg to
  79.     _playerId = owner _playerObj;
  80.     if (isNil '_playerObj')         exitWith {};
  81.     if (_playerId < 1)              exitWith {};
  82.  
  83.     //Start timer
  84.     _timer = 0;
  85.     _timer = p2h_hackLengthMinutes * 60;
  86.  
  87.     //Send message back to hacker to confirm hack has started
  88.     p2h_sHackStarted = true;
  89.     _playerId publicVariableClient "p2h_sHackStarted";
  90.     p2h_sHackStarted = nil;
  91.  
  92.     //Send announcement
  93.     p2h_hackMsg = p2h_hackStartAnnouncement;
  94.     publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  95.  
  96.     //Track if player is alive/dead/ran away
  97.     _quit = false;
  98.  
  99.     //if sent halfway msg
  100.     _halfwayMsgSent = false;
  101.  
  102.     //every second
  103.     while {true} do {
  104.  
  105.         uiSleep 1;
  106.         _timer = _timer - 1;
  107.  
  108.         //player alive check
  109.         if ((!alive _playerObj) || (isNull _playerObj)) exitWith {
  110.             _quit = true;
  111.             //Send announcement
  112.             p2h_hackMsg = p2h_hackerDied;
  113.             publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  114.         };
  115.  
  116.         //player dist check
  117.         if ((_playerObj distance p2h_objectPosition) > p2h_maxHackDistance) exitWith {
  118.             _quit = true;
  119.             //Send announcement
  120.             p2h_hackMsg = p2h_hackerRanAway;
  121.             publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  122.         };
  123.  
  124.         //if we at the half way point
  125.         _halfwayMsgSent = true;
  126.         _halfway = 30;
  127.         _halfway = p2h_hackLengthMinutes * 60;
  128.         _halfway = _halfway / 2;
  129.         _halfway = _halfway + 1;
  130.         if ((_timer < _halfway) && !_halfwayMsgSent) then {
  131.             //Send announcement
  132.             _halfwayMsgSent = true;
  133.             p2h_hackMsg = p2h_hackMidAnnouncement;
  134.             publicVariable "p2h_hackMsg";   p2h_hackMsg = nil;
  135.         };
  136.        
  137.         //if we finished
  138.         if (_timer < 1) exitWith {
  139.  
  140.             //Send message to players
  141.             p2h_hackMsg = "The funds are ready to collect! You have 120 seconds before they expire!";
  142.             publicVariable "p2h_hackMsg";   p2h_hackMsg = nil;
  143.         };
  144.  
  145.     };
  146.  
  147.     if (_quit) exitWith {
  148.     };
  149.  
  150.  
  151.     //Wait for player to send collect funds signal & check player doesnt run away or dies
  152.     _newTimer = 120;
  153.  
  154.     while {true} do {
  155.  
  156.         uiSleep 1;
  157.         _newTimer = _newTimer - 1;
  158.  
  159.         //player alive check
  160.         if ((!alive _playerObj) || (isNull _playerObj)) exitWith {
  161.             _quit = true;
  162.             //Send announcement
  163.             p2h_hackMsg = p2h_hackerDied;
  164.             publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  165.         };
  166.  
  167.         //player dist check
  168.         if ((_playerObj distance p2h_objectPosition) > p2h_maxHackDistance) exitWith {
  169.             _quit = true;
  170.             //Send announcement
  171.             p2h_hackMsg = p2h_hackerRanAway;
  172.             publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  173.         };
  174.  
  175.         //new timer check
  176.         if (_newTimer < 1) exitWith {
  177.             _quit = true;
  178.             //Send announcement
  179.             p2h_hackMsg = p2h_hackerRanAway;
  180.             publicVariable "p2h_hackMsg"; p2h_hackMsg = nil;
  181.         };
  182.  
  183.        
  184.         //Wait for player to send collect funds signal & check player doesnt run away or dies
  185.  
  186.  
  187.     };
  188.  
  189.  
  190.     if (_quit) exitWith {
  191.     };
  192.  
  193.  
  194.     //Give funds to player
  195.  
  196.     //Send funds collected status to player
  197.  
  198.     //Reset timer
  199.  
  200.     //Reset object hack status
  201.  
  202.     //Send finished message to all
  203.  
  204. };
  205.  
  206. //Start hacking (Client-Side)
  207. p2h_startHack = {
  208.  
  209.     //Get input (the hack object)
  210.     _hackObj = objNull;
  211.     _hackObj = _this select 3;
  212.  
  213.     if (isNil '_hackObj') then {
  214.         _hackObj = objNull;
  215.     };
  216.  
  217.     if (isNull _hackObj) then {
  218.         //Get object
  219.         _objlist = [];
  220.         _objlist = p2h_objectPosition nearObjects 5;
  221.         _hackObj = objNull;
  222.         {
  223.             _obj = objNull;
  224.             _obj = _x;
  225.  
  226.             if ((typeOf _obj) == p2h_objectModelName) then {
  227.                 _hackObj = _obj;
  228.             };
  229.         } forEach _objlist;
  230.     };
  231.  
  232.     //Send message to server
  233.     p2h_cStartHack = nil;
  234.     p2h_cStartHack = player;
  235.     publicVariableServer "p2h_cStartHack";
  236.  
  237.     //Wait for response message
  238.     p2h_sHackStarted = nil;
  239.     waitUntil{!isNil "p2h_sHackStarted"};
  240.  
  241.     //Set object status to being hacked
  242.     _hackObj setVariable ["status", true, true];
  243.  
  244.     //Show message that hacking has begun and not to stray too far from the hack site
  245.     systemChat(format["ROBBING STARTED! TIME LEFT: %1 Minutes", p2h_hackLengthMinutes]);
  246.     systemChat(format["DO NOT MOVE MORE THAN %1m FROM HERE OR THE ROBBERY WILL END WITH NO REWARD.", p2h_minHackDistance]);
  247. };
  248.  
  249.  
  250.  
  251. //Action Loop
  252. p2h_actionLoop = {
  253.  
  254.     //player info
  255.     _isAlive        = alive player;
  256.     _playerPos      = getPosATL player;
  257.     _playerDist     = (_playerPos distance p2h_objectPosition);
  258.  
  259.     //Get object
  260.     _objlist = [];
  261.     _objlist = p2h_objectPosition nearObjects 5;
  262.     _hackObj = objNull;
  263.     {
  264.         _obj = objNull;
  265.         _obj = _x;
  266.  
  267.         if ((typeOf _obj) == p2h_objectModelName) then {
  268.             _hackObj = _obj;
  269.         };
  270.     } forEach _objlist;
  271.  
  272.     //Get if object is being robbed already
  273.     _hackObjStatus = false;
  274.     _hackObjStatus = _hackObj getVariable ["status", false];
  275.  
  276.     //Wait a sec to catch var
  277.     sleep 0.1;
  278.  
  279.     //If player is close enough and not already hacking and objects not being robbed already
  280.     if ((!(p2h_isHacking > 0)) && (_playerPos < p2h_minHackDistance) && (!_hackObjStatus)) then {
  281.        
  282.         if (p2h_action > -1) then {
  283.         } else {
  284.             //Add action
  285.             p2h_action = player addAction [p2h_objectActionText, "p2h\p2h_startHackAction.sqf", _hackObj];
  286.         };
  287.  
  288.     } else {
  289.  
  290.         //If action is displayed remove it
  291.         if (p2h_action > -1) then {
  292.             player removeAction p2h_action;
  293.         };
  294.     };
  295.  
  296.  
  297. };
  298.  
  299.  
  300. //Server Side
  301.  
  302.  
  303.  
  304. //While server is running...
  305. while {true} do {
  306.  
  307.     player addAction ["Hint Hello!", { hint format ["Hello %1!", _this select 3] }, name player];
  308.  
  309.  
  310.  
  311. };
Advertisement
Add Comment
Please, Sign In to add comment