maramizo

Untitled

Sep 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //items.js mimicks inventory checking.
  2. var Items = require('./items');
  3.  
  4. //DatabaseHelper is used throughout the script in order to mimick loading/saving.
  5. var DatabaseHelper = require('./mockDatabase');
  6.  
  7. //addiction.js contains all the functionality regarding overdose and addiction.
  8. var Addiction = require('./addiction');
  9.  
  10. var ODP_THRESHOLD = 10; //At more than 10 overdose points, player overdoses.
  11. var ODP_TIME = 120000; //Each ten minutes, player loses 1 overdose point.
  12.  
  13. var drugs = [
  14.     /*
  15.         Drug type:
  16.         {
  17.             name: string            - Name of drug.
  18.             FX_end: int (ms),       - Visual effects duration time.
  19.             HP_end: int (ms),       - HP bonus duration time.
  20.             HP: int                 - Amount of bonus HP.
  21.             Anims: array            - List of animations linked to drug.
  22.             ODP: int                - Amount of overdose points added.
  23.         }
  24.     */
  25.     {
  26.         name: "high quality cocaine",
  27.         FX_end: 360000,
  28.         HP_end: 1800000,
  29.         HP: 50,
  30.         Anims: ["DeadlineNeon"],
  31.         ODP: 4,
  32.     },
  33.     {
  34.         name: "high quality crack",
  35.         FX_end: 300000,
  36.         HP_end: 3600000,
  37.         HP: 100,
  38.         Anims: ["InchPurple"],
  39.         ODP: 3,
  40.     },
  41.     {
  42.         name: "low quality cocaine",
  43.         FX_end: 240000,
  44.         HP_end: 1200000,
  45.         HP: 20,
  46.         Anims: ["DrugsDrivingIn", "SwitchOpenNeutralFIB5"],
  47.         ODP: 2,
  48.     },
  49.     {
  50.         name: "low quality crack",
  51.         FX_end: 480000,
  52.         HP_end: 1200000,
  53.         HP: 40,
  54.         Anims: ["Dont_tazeme_bro", "PPPurple"],
  55.         ODP: 1,
  56.     },
  57.     {
  58.         name: "high quality weed",
  59.         FX_end: 360000,
  60.         HP_end: 3600000,
  61.         HP: 30,
  62.         Anims: ["MenuMGTournamentTint"],
  63.         ODP: 0,
  64.     },
  65.     {
  66.         name: "low quality weed",
  67.         FX_end: 600000,
  68.         HP_end: 1800000,
  69.         HP: 10,
  70.         Anims: ["ChopVision"],
  71.         ODP: 0,
  72.     },
  73.     {
  74.         name: "methadone",
  75.     },
  76.  
  77. ];
  78.  
  79. module.exports = {
  80.     //This could be also under "onItemUse" or similar functions in existing script.
  81.     //drugName can be replaced with an ID, and the switch cases properly set to match. I.e: 0 instead of "high quality cocaine", 1 instead of "high quality crack", etc.
  82.     attemptDrugUse: function(player, drugName){
  83.  
  84.         //Check if player has the drug he's attempting to use.
  85.         if(Items.hasItem(player, drugName) == false)
  86.             return false;
  87.  
  88.         var drugFoundFlag = false;
  89.         drugs.forEach((element, index) => {
  90.             if(element.name == drugName.toLowerCase()){
  91.                 drugFoundFlag = true;
  92.                 if(element.name != "methadone"){ //If the drug isn't methadone.
  93.                     if(this.experiencingEffects(player) == 1){ //Player is currently experiencing visual effects from a drug.
  94.                         player.outputChatBox("You have already recently used a drug.");
  95.                     }else if(player.getVariable('inOD') == true){
  96.                         player.outputChatBox("You are currently overdosed, you cannot do that.");
  97.                     }else{
  98.  
  99.                         //Add overdose points based on drug used.
  100.                         Addiction.addODP(player, element.ODP);
  101.  
  102.                         if(playerTimers[player]['ODPTimer'] == null){ //Do not restart the timer if it already exists by making sure it isn't already set.
  103.                             playerTimers[player]['ODPTimer'] = setInterval(() => {
  104.                                 Addiction.removeODP(player, 1);
  105.                             }, ODP_TIME);
  106.                             player.setVariable('ODPTimerStart', new Date().getTime());
  107.                         }
  108.  
  109.                         if(Addiction.getODP(player) > ODP_THRESHOLD){ //If player has more points than the threshold is set to.
  110.                             Addiction.OD(player); //Overdose the player.
  111.  
  112.                             if(this.experiencingEffects(player) == 2) //Player currently has an HP buff from a previous drug.
  113.                                 endEffects(player, 2); //Remove buffs without showing the "body returning to normal" message.
  114.                         }else{
  115.                             player.setVariable('drugTaken', {
  116.                                 id: index,
  117.                                 timeIngested: new Date().getTime(),
  118.                             });
  119.  
  120.                             player.setVariable('extraHP', player.getVariable('extraHP') + element.HP);
  121.                            
  122.                             var randAnimIndex = Math.floor(Math.random()*element.Anims.length);
  123.                             player.call(`startScreenFX`, [element.Anims[randAnimIndex], element.FX_end]); //Calling remote function to start the screen effect for 6 minutes.
  124.    
  125.                             if(player.health < 100 && element.name.substr(0, 3) != "low")
  126.                                 player.health = 100;
  127.                             else{
  128.                                 if(player.health < 100){
  129.                                     if((player.health + element.HP) > 100){
  130.                                         player.setVariable('extraHP', player.getVariable('extraHP') - (100 - player.health));
  131.                                         player.health = 100;
  132.                                     }else{
  133.                                         player.setVariable('extraHP', null);
  134.                                         player.health += element.HP;
  135.                                     }
  136.                                 }
  137.                             }
  138.  
  139.                             this.saveDrugsData(player);
  140.  
  141.                             //Timeout to end visual drug effects.
  142.                             playerTimers[player]['endEffects1'] = setTimeout(() => {
  143.                                 endEffects(player, 0, element.Anims[randAnimIndex])
  144.                             }, element.FX_end);
  145.  
  146.                             //Timeout to end bonus HP effect.
  147.                             playerTimers[player]['endEffects2'] = setTimeout(() => {
  148.                                 endEffects(player, 1)
  149.                             }, element.HP_end);
  150.  
  151.                             var displayHealth = player.health;
  152.                             if(player.getVariable('extraHP') != null)
  153.                                 displayHealth += player.getVariable('extraHP');
  154.  
  155.                             Items.removeItem(player, element.name, 1);
  156.                             player.outputChatBox(`The ${element.name} finds its way into your receptors, making you less susceptible to pain. You now have ${displayHealth} HP.`);
  157.    
  158.                         }
  159.                     }
  160.                 }else{
  161.                     if(player.getVariable('inOD') == true){
  162.                         Addiction.unOD(player);
  163.                         Addiction.setODP(player, 10);
  164.                     }
  165.                 }
  166.             }
  167.  
  168.             if(index == drugs.length-1 && drugFoundFlag == false){
  169.                 console.log('Invalid drug name.');
  170.                 return false;
  171.             }
  172.         });
  173.     },
  174.  
  175.     experiencingEffects: function(player){
  176.         if(playerTimers[player]['endEffects1'] != null) //If the timer is set so that visual effects have not yet been ended.
  177.             return 1; //This means that the player has both, FX and HP effects.
  178.         if(playerTimers[player]['endEffects2'] != null) //If the timer is set so that HP advantage has not yet been removed.
  179.             return 2; //Player only has HP effects.
  180.         return false;
  181.     },
  182.  
  183.     saveDrugsData: function(player){
  184.         //Saving drug taking data will be useful in case an OD happens and a medical team reviews the player's drug take history, or even for medical checkups at "work".
  185.         var drugsData = player.getVariable('drugTaken');
  186.         DatabaseHelper.saveData({
  187.             drug_id: drugsData.id,
  188.             timestamp: drugsData.timeIngested
  189.         }, "drugUsageData");
  190.  
  191.         DatabaseHelper.saveData({
  192.             //Save if player is experiencing effects.
  193.             experiencingEffects: this.experiencingEffects(player),
  194.  
  195.             //Save player's amount of extra HP.
  196.             extraHP: player.getVariable('extraHP'),
  197.  
  198.             //Save amount of HP time left on trip (if any, otherwise save as NULL).
  199.             timeleftOnTrip: (this.experiencingEffects(player) != false ? (drugs[drugsData.id].HP_end - (new Date().getTime() - drugsData.timeIngested)) : null)
  200.        
  201.             //Save the ID of the drug the player's on (if any, otherwise save as NULL).
  202.             onDrug: (this.experiencingEffects(player) != false ? drugsData.id : null),
  203.         }, "playerData");
  204.     },
  205.  
  206.     loadDrugsData: function(player){
  207.         var data = DatabaseHelper.loadData(['ODP_Timer', 'experiencingEffects', 'extraHP', 'timeleftOnTrip', 'onDrug']);
  208.  
  209.         var ODP_Timer = data[0];
  210.         var experiencingEffects = data[1];
  211.         var extraHP = data[2];
  212.         var timeleftOnTrip = data[3];
  213.         var onDrug = data[4];
  214.  
  215.         if(experiencingEffects != false && timeleftOnTrip > 0){
  216.            
  217.             if(extraHP > 0) //Player still has extraHP left in his extraHP bank.
  218.                 player.setVariable('extraHP', extraHP);
  219.  
  220.             if(timeleftOnTrip > (drugs[onDrug].HP_end - drugs[onDrug].FX_end)){ //Still has visual effect time remaining.
  221.  
  222.                 //Calculate FX time remaining by subtracting total duration left from HP duration.
  223.                 var FXtimeleft = (drugs[onDrug].HP_end - timeleftOnTrip);
  224.  
  225.                 var randAnimIndex = Math.floor(Math.random()*element.Anims.length);
  226.                 player.call(`startScreenFX`, [drugs[onDrug].Anims[randAnimIndex], FXtimeleft]); //Calling remote function to start the screen effect for 6 minutes.    
  227.            
  228.                 playerTimers[player]['endEffects1'] = setTimeout(() => {
  229.                     endEffects(player, 0, drugs[onDrug].Anims[randAnimIndex])
  230.                 }, FXtimeleft);
  231.             }
  232.             playerTimers[player]['endEffects2'] = setTimeout(() => {
  233.                 endEffects(player, 1)
  234.             }, drugs[onDrug].HP_end);
  235.         }
  236.  
  237.         //Creating a timer with the current time left, then setting an interval with the usual time once that time is over.
  238.         playerTimers[player]['ODPTimer'] = setTimeout(() => {
  239.             Addiction.removeODP(player, 1);
  240.             clearTimeout(playerTimers[player]['ODPTimer']);
  241.             playerTimers[player]['ODPTimer'] = setInterval(() => {
  242.                 Addiction.removeODP(player, 1);
  243.             }, ODP_TIME);
  244.         }, ODP_Timer);
  245.        
  246.         //Removing time left from the timer, then subtracting that from the current time so that the time left is what's remaining until ODP is subtracted.
  247.         player.setVariable('ODPTimerStart', new Date().getTime() - (ODP_TIME - ODP_Timer));
  248.     }
  249. }
  250.  
  251. //Change cocaine into crack using items. (TBD)
  252. function flipCocaine(player){
  253.  
  254. }
  255.  
  256. //Increase player skill in flipping cocaine into crack. (TBD)
  257. function increaseDrugSkill(player){
  258.  
  259. }
  260.  
  261. function endEffects(player, type, anim = null){
  262.     if(type == 0){ //Visual effect ending.
  263.  
  264.         //End effect on client.
  265.         player.call(`stopScreenFX`, [anim]);
  266.  
  267.         //Clear server-sided timeout to end the effect if it hasn't been cleared.
  268.         clearTimeout(playerTimers[player]['endEffects1']);
  269.  
  270.         //Null related variables.
  271.         playerTimers[player]['endEffects1'] = null;
  272.         player.setVariable('drugEffectAnim', null);
  273.  
  274.     }else{ //No more drug advantage.
  275.  
  276.         //Remove HP bonus.
  277.         player.setVariable('extraHP', 0);
  278.        
  279.         //Clear server-sided timeout just in case.
  280.         clearTimeout(playerTimers[player]['endEffects2']);
  281.  
  282.         //Null related variable.
  283.         playerTimers[player]['endEffects2'] = null;
  284.  
  285.         if(type == 1)
  286.             player.outputChatBox("Your body returns back to normal, you no longer get bonuses from drugs.");
  287.     }
  288. }
Add Comment
Please, Sign In to add comment