Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //items.js mimicks inventory checking.
- var Items = require('./items');
- //DatabaseHelper is used throughout the script in order to mimick loading/saving.
- var DatabaseHelper = require('./mockDatabase');
- //addiction.js contains all the functionality regarding overdose and addiction.
- var Addiction = require('./addiction');
- var ODP_THRESHOLD = 10; //At more than 10 overdose points, player overdoses.
- var ODP_TIME = 120000; //Each ten minutes, player loses 1 overdose point.
- var drugs = [
- /*
- Drug type:
- {
- name: string - Name of drug.
- FX_end: int (ms), - Visual effects duration time.
- HP_end: int (ms), - HP bonus duration time.
- HP: int - Amount of bonus HP.
- Anims: array - List of animations linked to drug.
- ODP: int - Amount of overdose points added.
- }
- */
- {
- name: "high quality cocaine",
- FX_end: 360000,
- HP_end: 1800000,
- HP: 50,
- Anims: ["DeadlineNeon"],
- ODP: 4,
- },
- {
- name: "high quality crack",
- FX_end: 300000,
- HP_end: 3600000,
- HP: 100,
- Anims: ["InchPurple"],
- ODP: 3,
- },
- {
- name: "low quality cocaine",
- FX_end: 240000,
- HP_end: 1200000,
- HP: 20,
- Anims: ["DrugsDrivingIn", "SwitchOpenNeutralFIB5"],
- ODP: 2,
- },
- {
- name: "low quality crack",
- FX_end: 480000,
- HP_end: 1200000,
- HP: 40,
- Anims: ["Dont_tazeme_bro", "PPPurple"],
- ODP: 1,
- },
- {
- name: "high quality weed",
- FX_end: 360000,
- HP_end: 3600000,
- HP: 30,
- Anims: ["MenuMGTournamentTint"],
- ODP: 0,
- },
- {
- name: "low quality weed",
- FX_end: 600000,
- HP_end: 1800000,
- HP: 10,
- Anims: ["ChopVision"],
- ODP: 0,
- },
- {
- name: "methadone",
- },
- ];
- module.exports = {
- //This could be also under "onItemUse" or similar functions in existing script.
- //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.
- attemptDrugUse: function(player, drugName){
- //Check if player has the drug he's attempting to use.
- if(Items.hasItem(player, drugName) == false)
- return false;
- var drugFoundFlag = false;
- drugs.forEach((element, index) => {
- if(element.name == drugName.toLowerCase()){
- drugFoundFlag = true;
- if(element.name != "methadone"){ //If the drug isn't methadone.
- if(this.experiencingEffects(player) == 1){ //Player is currently experiencing visual effects from a drug.
- player.outputChatBox("You have already recently used a drug.");
- }else if(player.getVariable('inOD') == true){
- player.outputChatBox("You are currently overdosed, you cannot do that.");
- }else{
- //Add overdose points based on drug used.
- Addiction.addODP(player, element.ODP);
- if(playerTimers[player]['ODPTimer'] == null){ //Do not restart the timer if it already exists by making sure it isn't already set.
- playerTimers[player]['ODPTimer'] = setInterval(() => {
- Addiction.removeODP(player, 1);
- }, ODP_TIME);
- player.setVariable('ODPTimerStart', new Date().getTime());
- }
- if(Addiction.getODP(player) > ODP_THRESHOLD){ //If player has more points than the threshold is set to.
- Addiction.OD(player); //Overdose the player.
- if(this.experiencingEffects(player) == 2) //Player currently has an HP buff from a previous drug.
- endEffects(player, 2); //Remove buffs without showing the "body returning to normal" message.
- }else{
- player.setVariable('drugTaken', {
- id: index,
- timeIngested: new Date().getTime(),
- });
- player.setVariable('extraHP', player.getVariable('extraHP') + element.HP);
- var randAnimIndex = Math.floor(Math.random()*element.Anims.length);
- player.call(`startScreenFX`, [element.Anims[randAnimIndex], element.FX_end]); //Calling remote function to start the screen effect for 6 minutes.
- if(player.health < 100 && element.name.substr(0, 3) != "low")
- player.health = 100;
- else{
- if(player.health < 100){
- if((player.health + element.HP) > 100){
- player.setVariable('extraHP', player.getVariable('extraHP') - (100 - player.health));
- player.health = 100;
- }else{
- player.setVariable('extraHP', null);
- player.health += element.HP;
- }
- }
- }
- this.saveDrugsData(player);
- //Timeout to end visual drug effects.
- playerTimers[player]['endEffects1'] = setTimeout(() => {
- endEffects(player, 0, element.Anims[randAnimIndex])
- }, element.FX_end);
- //Timeout to end bonus HP effect.
- playerTimers[player]['endEffects2'] = setTimeout(() => {
- endEffects(player, 1)
- }, element.HP_end);
- var displayHealth = player.health;
- if(player.getVariable('extraHP') != null)
- displayHealth += player.getVariable('extraHP');
- Items.removeItem(player, element.name, 1);
- player.outputChatBox(`The ${element.name} finds its way into your receptors, making you less susceptible to pain. You now have ${displayHealth} HP.`);
- }
- }
- }else{
- if(player.getVariable('inOD') == true){
- Addiction.unOD(player);
- Addiction.setODP(player, 10);
- }
- }
- }
- if(index == drugs.length-1 && drugFoundFlag == false){
- console.log('Invalid drug name.');
- return false;
- }
- });
- },
- experiencingEffects: function(player){
- if(playerTimers[player]['endEffects1'] != null) //If the timer is set so that visual effects have not yet been ended.
- return 1; //This means that the player has both, FX and HP effects.
- if(playerTimers[player]['endEffects2'] != null) //If the timer is set so that HP advantage has not yet been removed.
- return 2; //Player only has HP effects.
- return false;
- },
- saveDrugsData: function(player){
- //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".
- var drugsData = player.getVariable('drugTaken');
- DatabaseHelper.saveData({
- drug_id: drugsData.id,
- timestamp: drugsData.timeIngested
- }, "drugUsageData");
- DatabaseHelper.saveData({
- //Save if player is experiencing effects.
- experiencingEffects: this.experiencingEffects(player),
- //Save player's amount of extra HP.
- extraHP: player.getVariable('extraHP'),
- //Save amount of HP time left on trip (if any, otherwise save as NULL).
- timeleftOnTrip: (this.experiencingEffects(player) != false ? (drugs[drugsData.id].HP_end - (new Date().getTime() - drugsData.timeIngested)) : null)
- //Save the ID of the drug the player's on (if any, otherwise save as NULL).
- onDrug: (this.experiencingEffects(player) != false ? drugsData.id : null),
- }, "playerData");
- },
- loadDrugsData: function(player){
- var data = DatabaseHelper.loadData(['ODP_Timer', 'experiencingEffects', 'extraHP', 'timeleftOnTrip', 'onDrug']);
- var ODP_Timer = data[0];
- var experiencingEffects = data[1];
- var extraHP = data[2];
- var timeleftOnTrip = data[3];
- var onDrug = data[4];
- if(experiencingEffects != false && timeleftOnTrip > 0){
- if(extraHP > 0) //Player still has extraHP left in his extraHP bank.
- player.setVariable('extraHP', extraHP);
- if(timeleftOnTrip > (drugs[onDrug].HP_end - drugs[onDrug].FX_end)){ //Still has visual effect time remaining.
- //Calculate FX time remaining by subtracting total duration left from HP duration.
- var FXtimeleft = (drugs[onDrug].HP_end - timeleftOnTrip);
- var randAnimIndex = Math.floor(Math.random()*element.Anims.length);
- player.call(`startScreenFX`, [drugs[onDrug].Anims[randAnimIndex], FXtimeleft]); //Calling remote function to start the screen effect for 6 minutes.
- playerTimers[player]['endEffects1'] = setTimeout(() => {
- endEffects(player, 0, drugs[onDrug].Anims[randAnimIndex])
- }, FXtimeleft);
- }
- playerTimers[player]['endEffects2'] = setTimeout(() => {
- endEffects(player, 1)
- }, drugs[onDrug].HP_end);
- }
- //Creating a timer with the current time left, then setting an interval with the usual time once that time is over.
- playerTimers[player]['ODPTimer'] = setTimeout(() => {
- Addiction.removeODP(player, 1);
- clearTimeout(playerTimers[player]['ODPTimer']);
- playerTimers[player]['ODPTimer'] = setInterval(() => {
- Addiction.removeODP(player, 1);
- }, ODP_TIME);
- }, ODP_Timer);
- //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.
- player.setVariable('ODPTimerStart', new Date().getTime() - (ODP_TIME - ODP_Timer));
- }
- }
- //Change cocaine into crack using items. (TBD)
- function flipCocaine(player){
- }
- //Increase player skill in flipping cocaine into crack. (TBD)
- function increaseDrugSkill(player){
- }
- function endEffects(player, type, anim = null){
- if(type == 0){ //Visual effect ending.
- //End effect on client.
- player.call(`stopScreenFX`, [anim]);
- //Clear server-sided timeout to end the effect if it hasn't been cleared.
- clearTimeout(playerTimers[player]['endEffects1']);
- //Null related variables.
- playerTimers[player]['endEffects1'] = null;
- player.setVariable('drugEffectAnim', null);
- }else{ //No more drug advantage.
- //Remove HP bonus.
- player.setVariable('extraHP', 0);
- //Clear server-sided timeout just in case.
- clearTimeout(playerTimers[player]['endEffects2']);
- //Null related variable.
- playerTimers[player]['endEffects2'] = null;
- if(type == 1)
- player.outputChatBox("Your body returns back to normal, you no longer get bonuses from drugs.");
- }
- }
Add Comment
Please, Sign In to add comment