Skip to content

Commit

Permalink
EquipmentEditor: Set clip on buy (#1499)
Browse files Browse the repository at this point in the history
Added `SWEP.SetClipOnBuy` and `SWEP.ClipOnBuy` to set the weapon's clip
on buy via the equipment editor. I did not want to just use the latter
variable to set a clip on buy to all weapons as most "one time use
weapons" instantly remove the weapon on use which makes this slider
pointless. It is therefore something swep makers have to integrate into
their weapon, which is pretty simple.

I also reordered some elements in the equipment menu because they were
out of place. It now looks like this:


![image](https://github.com/TTT-2/TTT2/assets/13639408/3c0a6722-1ee1-4c23-b1a5-a29cdd2264fb)

---------

Co-authored-by: Histalek <16392835+Histalek@users.noreply.github.com>
Co-authored-by: ZenBre4ker <72046466+ZenBre4ker@users.noreply.github.com>
  • Loading branch information
3 people committed May 11, 2024
1 parent 297be1b commit 45872ff
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added `TTT2CanTakeCredits` hook for overriding whether a player is allowed to take credits from a given corpse. (by @Spanospy)
- Disabled locational voice during the preparing phase by default
- Added a ConVar `ttt_locational_voice_prep` to reenable it
- Added `SWEP.EnableConfigurableClip` and `SWEP.ConfigurableClip` to set the weapon's clip on buy via the equipment editor (by @TimGoll)
- Added Text / Nickname length limiting (by @TimGoll)
- Added `ttt_locational_voice_range` to set a cut-off radius for the locational voice chat range
- Added a convar `ttt2_inspect_credits_always_visible` to control whether credits are visible to players that do not have a shop
Expand Down
12 changes: 12 additions & 0 deletions gamemodes/terrortown/entities/weapons/weapon_tttbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ SWEP.silentPickup = false
-- Can be useful if you have multiple instances, that rely on global variables stored via weapons.GetStored()
SWEP.HotReloadableKeys = {}

-- Set this to true if the weapon should have a custom clip size on buy that can be set in the equipment editor
SWEP.EnableConfigurableClip = false

-- The default clip on buy if `SWEP.EnableConfigurableClip` is set to true
SWEP.ConfigurableClip = 1

-- If this weapon should be given to players upon spawning, set a table of the
-- roles this should happen for here
-- SWEP.InLoadoutFor = {ROLE_TRAITOR, ROLE_DETECTIVE, ROLE_INNOCENT}
Expand Down Expand Up @@ -1484,6 +1490,12 @@ function SWEP:Initialize()
self:InitializeCustomModels()
end

if self.EnableConfigurableClip then
self.Primary.ClipSize = self.ConfigurableClip or self.Primary.DefaultClip

self:SetClip1(self.ConfigurableClip or self.Primary.DefaultClip)
end

if CLIENT and self:Clip1() == -1 then
self:SetClip1(self.Primary.DefaultClip)
elseif SERVER then
Expand Down
5 changes: 5 additions & 0 deletions gamemodes/terrortown/gamemode/shared/sh_shopeditor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ ShopEditor.savingKeys = {
bits = 8,
default = 1,
},
ConfigurableClip = {
typ = "number",
bits = 8,
default = 1,
},
AllowDrop = {
typ = "bool",
default = true,
Expand Down
5 changes: 5 additions & 0 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,11 @@ L.help_locational_voice_prep = [[By default the proximity chat is disabled in th
Note: Proximity chat is always disabled during the post round phase.]]
L.help_voice_duck_spectator = "Ducking spectators makes other spectators quieter in comparison to living players. This can be useful if one wants to listen closely to the discussions of the living players."

L.help_equipmenteditor_configurable_clip = [[The configurable size defines the amount of uses the weapon has when bought in the shop or spawned in the world.
Note: This setting is only available for weapons that enable this feature.]]
L.label_equipmenteditor_configurable_clip = "Configurable clip size"

-- 2024-04-06
L.help_locational_voice_range = [[This convar constrains the maximum range at which players can hear each other. It does not change how the volume decreases with distance but rather sets a hard cut-off point.
Expand Down
66 changes: 40 additions & 26 deletions lua/terrortown/menus/gamemode/equipment/base_equipment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,41 @@ function CLGAMEMODESUBMENU:Populate(parent)
master = master,
})

form:MakeSlider({
label = "equipmenteditor_name_min_players",
min = 0,
max = 63,
decimal = 0,
database = DatabaseElement(accessName, itemName, "minPlayers"),
master = master,
})

form:MakeSlider({
label = "equipmenteditor_name_credits",
min = 0,
max = 20,
decimal = 0,
database = DatabaseElement(accessName, itemName, "credits"),
master = master,
})

if not self.isItem then
form:MakeHelp({
local form2 = vgui.CreateTTT2Form(parent, "header_equipment_value_setup")

form2:MakeHelp({
label = "equipmenteditor_desc_allow_drop",
})

form:MakeCheckBox({
form2:MakeCheckBox({
label = "equipmenteditor_name_allow_drop",
database = DatabaseElement(accessName, itemName, "AllowDrop"),
})

form:MakeHelp({
form2:MakeHelp({
label = "equipmenteditor_desc_drop_on_death_type",
})

form:MakeComboBox({
form2:MakeComboBox({
label = "equipmenteditor_name_drop_on_death_type",
database = DatabaseElement(accessName, itemName, "overrideDropOnDeath"),
choices = {
Expand All @@ -151,38 +171,32 @@ function CLGAMEMODESUBMENU:Populate(parent)
{ title = TryT("drop_on_death_type_deny"), value = DROP_ON_DEATH_TYPE_DENY },
},
})
end

form = vgui.CreateTTT2Form(parent, "header_equipment_value_setup")

form:MakeSlider({
label = "equipmenteditor_name_min_players",
min = 0,
max = 63,
decimal = 0,
database = DatabaseElement(accessName, itemName, "minPlayers"),
})

form:MakeSlider({
label = "equipmenteditor_name_credits",
min = 0,
max = 20,
decimal = 0,
database = DatabaseElement(accessName, itemName, "credits"),
})

if not self.isItem then
form:MakeHelp({
form2:MakeHelp({
label = "equipmenteditor_desc_damage_scaling",
})

form:MakeSlider({
form2:MakeSlider({
label = "equipmenteditor_name_damage_scaling",
min = 0,
max = 8,
decimal = 2,
database = DatabaseElement(accessName, itemName, "damageScaling"),
})

if equipment.EnableConfigurableClip then
form2:MakeHelp({
label = "help_equipmenteditor_configurable_clip",
})

form2:MakeSlider({
label = "label_equipmenteditor_configurable_clip",
min = 1,
max = 20,
decimal = 0,
database = DatabaseElement(accessName, itemName, "ConfigurableClip"),
})
end
end

local equipmentClass = WEPS.GetClass(equipment)
Expand Down

0 comments on commit 45872ff

Please sign in to comment.