From 9e66e0c22780fd7fa3da5ba7a1c513b69650e11e Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Sun, 15 May 2022 22:28:01 -0500 Subject: [PATCH] Start working on logic for new items --- scripts/server/const.js | 5 +++-- scripts/server/item.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/scripts/server/const.js b/scripts/server/const.js index b4f5441f..3c28c9e2 100644 --- a/scripts/server/const.js +++ b/scripts/server/const.js @@ -209,8 +209,8 @@ const VRR_ITEM_USETYPE_ARMOUR = 28; // const VRR_ITEM_USETYPE_HEALTH = 29; // const VRR_ITEM_USETYPE_AED = 30; // const VRR_ITEM_USETYPE_WALKIETALKIE = 31; // -const VRR_ITEM_USETYPE_BOOMBOX = 32; // -const VRR_ITEM_USETYPE_EARBUDS = 33; // +const VRR_ITEM_USETYPE_AREARADIO = 32; // +const VRR_ITEM_USETYPE_PERSONALRADIO = 33; // const VRR_ITEM_USETYPE_BADGE = 34; // const VRR_ITEM_USETYPE_DRINK = 35; // Drinkable item. Action output shows "Player_Name drinks some (drink name)" const VRR_ITEM_USETYPE_EXTINGUISHER = 36; // Extinguisher item. Allows putting out fires @@ -231,6 +231,7 @@ const VRR_ITEM_USETYPE_PLANT = 50; // Plantable item. Pot plants, const VRR_ITEM_USETYPE_MEGAPHONE = 51; // Megaphone item. Allows shouting over greater distances. Also called a bullhorn const VRR_ITEM_USETYPE_INJECTDRUG = 52; // Injectable drug. Action output shows "Player_Name injects some (drug)" const VRR_ITEM_USETYPE_ALCOHOL = 53; // Alcohol. Applies an intoxication/drunkness effect +const VRR_ITEM_USETYPE_LOTTOTICKET = 54; // Lotto ticket. Allows a character to enter the lottery // Item Drop Types const VRR_ITEM_DROPTYPE_NONE = 0; // Can't be dropped diff --git a/scripts/server/item.js b/scripts/server/item.js index 248bab5e..f80b2de9 100644 --- a/scripts/server/item.js +++ b/scripts/server/item.js @@ -723,6 +723,12 @@ function playerUseItem(client, hotBarSlot) { return false; } + if(!getItemData(itemIndex)) { + submitBugReport(client, `[AUTOMATED REPORT] Tried to use invalid item (index ${itemIndex} in player slot ${hotBarSlot})`); + cachePlayerHotBarItems(client); + return false; + } + switch(getItemTypeData(getItemData(itemIndex).itemTypeIndex).useType) { case VRR_ITEM_USETYPE_SKIN: { getPlayerData(client).itemActionItem = itemIndex; @@ -1024,6 +1030,39 @@ function playerUseItem(client, hotBarSlot) { break; } + case VRR_ITEM_USETYPE_HEALTH: { + let closestPlayer = getClosestPlayer(getPlayerPosition(client), client); + + if(!getPlayerData(closestPlayer)) { + messagePlayerError(client, "There isn't anyone close enough to heal!"); + return false; + } + + if(getDistance(getPlayerPosition(closestPlayer), getPlayerPosition(client)) > getGlobalConfig().firstAidKitPlayerDistance) { + messagePlayerError(client, "There isn't anyone close enough to heal!"); + return false; + } + break; + } + + case VRR_ITEM_USETYPE_LOTTOTICKET: { + + break; + } + + case VRR_ITEM_USETYPE_AREARADIO: { + let state = getItemData(itemIndex) + meActionToNearbyPlayers(client, `turns ${getOnOffFromBool(state)} the boombox radio`); + messagePlayerAlert(client, `Use /radiostation to set the radio station and drop it on the ground to play`); + break; + } + + case VRR_ITEM_USETYPE_PERSONALRADIO: { + meActionToNearbyPlayers(client, `turns ${getOnOffFromBool(state)} the boombox radio`); + messagePlayerAlert(client, `Use /radiostation to set the radio station`); + break; + } + default: { messagePlayerError(client, `The ${getItemName(itemIndex)} doesn't do anything when you try to use it.`); break;