Skip to content

Commit

Permalink
Entity Bringdown volume 2 (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll authored Jan 8, 2024
1 parent 19b2be1 commit 706a93d
Show file tree
Hide file tree
Showing 31 changed files with 1,157 additions and 180 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel

### Added

- Added some missing vanilla TTT entities into TTT2
- Added debug.print(message)
- This puts quotation marks around print statements
- Can handle single values or a sequential table to be printed
Expand All @@ -20,7 +21,9 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel

### Fixed

- targetid wasn't showing named corpse's role, information which was already present on the scoreboard (by @EntranceJew)
- Fixed targetID hints for old addons now correctly working for all entities
- Fixed visualizer having pickup hint even though player is unable to pick up
- Targetid wasn't showing named corpse's role, information which was already present on the scoreboard (by @EntranceJew)
- Damage Scaling now has a help description
- Fixed the database module setting a global variable called `callback` which breaks addons such as PointShop2
- Fixed voicechat keybinds being shown even if voice is disabled
Expand Down
76 changes: 76 additions & 0 deletions gamemodes/terrortown/entities/entities/info_manipulate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
-- @class ENT
-- @desc Dummy entity to convert ZM info_manipulate traps to TTT ones
-- @section InfoManipulate

ENT.Type = "point"
ENT.Base = "base_point"

---
-- @realm server
function ENT:Think()
if not self.Replaced then
self:CreateReplacement()

self:Remove()
end
end

---
-- Sets Hammer key values on an entity.
-- @param string key The internal key name
-- @param string value The value to set
-- @realm server
function ENT:KeyValue(key, value)
if key == "OnPressed" then
-- store raw, will be feeding this into the replacement's StoreOutput()
self.RawOutputs = self.RawOutputs or {}

self.RawOutputs[#self.RawOutputs + 1] = value
elseif key == "Cost" then
self[key] = tonumber(value)
elseif key == "Active" or key == "RemoveOnTrigger" then
self[key] = tobool(value)
elseif key == "Description" then
self[key] = tostring(value)
end
end

---
-- @realm server
function ENT:CreateReplacement()
local tgt = ents.Create("ttt_traitor_button")

if not IsValid(tgt) then return end

self.Replaced = true

-- feed in our properties into replacement as keyvals
tgt:SetPos(self:GetPos())
tgt:SetKeyValue("targetname", self:GetName())

if not self.Active then
-- start locked
tgt:SetKeyValue("spawnflags", tostring(2048))
end

if self.Description and self.Description ~= "" then
tgt:SetKeyValue("description", self.Description)
end

if self.Cost then
tgt:SetKeyValue("wait", tostring(self.Cost))
end

if self.RemoveOnTrigger then
tgt:SetKeyValue("RemoveOnPress", tostring(true))
end

if self.RawOutputs then
for k, v in pairs(self.RawOutputs) do
tgt:SetKeyValue("OnPressed", tostring(v))
end
end

tgt:Spawn()
end
11 changes: 0 additions & 11 deletions gamemodes/terrortown/entities/entities/ttt_c4/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ if CLIENT then
-- this entity can be DNA-sampled so we need some display info
ENT.Icon = "vgui/ttt/icon_c4"
ENT.PrintName = "C4"

local GetPTranslation = LANG.GetParamTranslation
local hint_params = {usekey = Key("+use", "USE")}

ENT.TargetIDHint = {
name = "C4",
hint = "c4_hint",
fmt = function(ent, txt)
return GetPTranslation(txt, hint_params)
end
}
end

C4_WIRE_COUNT = 6
Expand Down
47 changes: 47 additions & 0 deletions gamemodes/terrortown/entities/entities/ttt_credit_adjust.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
-- @class ENT
-- @desc Handles player credit interactions with the map
-- @section CreditAdjust

ENT.Type = "point"
ENT.Base = "base_point"

ENT.Credits = 0

---
-- Sets Hammer key values on an entity.
-- @param string key The internal key name
-- @param string value The value to set
-- @realm server
function ENT:KeyValue(key, value)
if key == "OnSuccess" or key == "OnFail" then
self:StoreOutput(key, value)
elseif key == "credits" then
self.Credits = tonumber(value) or 0

if not tonumber(value) then
ErrorNoHalt(tostring(self) .. " has bad 'credits' setting.\n")
end
end
end

---
-- Called when another entity fires an event to this entity.
-- @param string name The name of the input that was triggered
-- @param Entity activator The initial cause for the input getting triggered; e.g. the player who pushed a button
-- @realm server
function ENT:AcceptInput(name, activator)
if name ~= "TakeCredits" then return end

if IsValid(activator) and activator:IsPlayer() then
if activator:GetCredits() >= self.Credits then
activator:SubtractCredits(self.Credits)

self:TriggerOutput("OnSuccess", activator)
else
self:TriggerOutput("OnFail", activator)
end
end

return true
end
Loading

0 comments on commit 706a93d

Please sign in to comment.