From e0d46d715cb38491c9aa8632bc13ba46d69b7884 Mon Sep 17 00:00:00 2001 From: saibotk Date: Mon, 16 Oct 2023 00:06:08 +0200 Subject: [PATCH] refactor: Switch to modern lang layout & use nw vars --- .../entities/items/item_ttt_silentstep.lua | 47 +++++-------------- lua/terrortown/lang/en/ttt_silentstep.lua | 7 +++ 2 files changed, 20 insertions(+), 34 deletions(-) create mode 100644 lua/terrortown/lang/en/ttt_silentstep.lua diff --git a/lua/terrortown/entities/items/item_ttt_silentstep.lua b/lua/terrortown/entities/items/item_ttt_silentstep.lua index a3b47b6..5dff7f0 100644 --- a/lua/terrortown/entities/items/item_ttt_silentstep.lua +++ b/lua/terrortown/entities/items/item_ttt_silentstep.lua @@ -3,55 +3,34 @@ if SERVER then resource.AddFile("materials/vgui/ttt/icon_silentstep.vmt") resource.AddFile("materials/vgui/ttt/perks/hud_silentstep.png") - - util.AddNetworkString("TTTSilentstepBought") end ITEM.hud = Material("vgui/ttt/perks/hud_silentstep.png") ITEM.EquipMenuData = { type = "item_passive", name = "item_silentstep_name", - desc = "item_silentstep_desc" + desc = "item_silentstep_desc", } ITEM.material = "vgui/ttt/icon_silentstep" -ITEM.CanBuy = {ROLE_TRAITOR, ROLE_DETECTIVE} +ITEM.CanBuy = { ROLE_TRAITOR, ROLE_DETECTIVE } if SERVER then - function ITEM:Bought(ply) - net.Start("TTTSilentstepBought") - net.WriteEntity(ply) - net.Broadcast() + --- + ---@param ply Player + function ITEM:Equip(ply) + ply:SetNWBool("ttt_silent_step", true) end -else - hook.Add("TTT2Initialize", "TTTItemSilentStepLang", function() - LANG.AddToLanguage("English", "item_silentstep_name", "Silent Step") - LANG.AddToLanguage("English", "item_silentstep_desc", "Silent Step Perk.\nLets you walk like a ninja without any steps!") - end) - net.Receive("TTTSilentstepBought", function() - local ply = net.ReadEntity() - - if ply == LocalPlayer() then return end - - if not ply:HasEquipmentItem("item_ttt_silentstep") then - ply.equipmentItems = ply.equipmentItems or {} - ply.equipmentItems[#ply.equipmentItems + 1] = "item_ttt_silentstep" - end - end) - - hook.Add("TTTEndRound", "TTTSilentStepCleanUp", function() - local lcply = LocalPlayer() - - for _, v in ipairs(player.GetAll()) do - if v ~= lcply then - v.equipmentItems = {} - end - end - end) + --- + ---@param ply Player + function ITEM:Reset(ply) + ply:SetNWBool("ttt_silent_step", false) + end end hook.Add("PlayerFootstep", "TTTSilentStepNoSound", function(ply) - if ply:HasEquipmentItem("item_ttt_silentstep") then + ---@cast ply Player + if ply:GetNWBool("ttt_silent_step", false) then return true end end) diff --git a/lua/terrortown/lang/en/ttt_silentstep.lua b/lua/terrortown/lang/en/ttt_silentstep.lua new file mode 100644 index 0000000..459b21c --- /dev/null +++ b/lua/terrortown/lang/en/ttt_silentstep.lua @@ -0,0 +1,7 @@ +local L = LANG.GetLanguageTableReference("en") + +L["item_silentstep_name"] = "Silent Step" +L["item_silentstep_desc"] = [[ + Silent Step Perk. + Lets you walk like a ninja without any steps! +]]