Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EquipmentEditor: Set clip on buy #1499

Merged
merged 13 commits into from
May 11, 2024
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.SetClipOnBuy` and `SWEP.ClipOnBuy` to set the weapon's clip on buy via the equipment editor (by @TimGoll)

### Changed

Expand Down
6 changes: 6 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.SetClipOnBuy = false

-- The defult clip on buy if `SWEP.SetClipOnBuy` is set to true
TimGoll marked this conversation as resolved.
Show resolved Hide resolved
SWEP.ClipOnBuy = 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
6 changes: 6 additions & 0 deletions gamemodes/terrortown/gamemode/client/cl_equip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,12 @@ local function ReceiveBoughtItem()
end
net.Receive("TTT_BoughtItem", ReceiveBoughtItem)

net.Receive("TTT2SetClipOnBuy", function()
local wep = net.ReadEntity()

wep.Primary.ClipSize = net.ReadUInt(8)
end)

--
-- HOOKS / GAMEMODE RELATED STUFF:
--
Expand Down
1 change: 1 addition & 0 deletions gamemodes/terrortown/gamemode/server/sv_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ util.AddNetworkString("TTT2OrderEquipment")
util.AddNetworkString("TTT2RoleGlobalVoice")
util.AddNetworkString("TTT2MuteTeam")
util.AddNetworkString("TTT2UpdateHoldAimConvar")
util.AddNetworkString("TTT2SetClipOnBuy")

-- provide menu files by loading them from here:
fileloader.LoadFolder("terrortown/menus/score/", false, CLIENT_FILE)
Expand Down
11 changes: 11 additions & 0 deletions gamemodes/terrortown/gamemode/shared/sh_shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ function shop.BuyEquipment(ply, equipmentName)
end
else
ply:GiveEquipmentWeapon(equipmentName, function(_ply, _equipmentName, _weapon)
if _weapon.SetClipOnBuy then
_weapon.Primary.ClipSize = _weapon.ClipOnBuy

_weapon:SetClip1(_weapon.ClipOnBuy)

net.Start("TTT2SetClipOnBuy")
net.WriteEntity(_weapon)
net.WriteUInt(_weapon.ClipOnBuy, 8)
net.Send(ply)
end

if isfunction(_weapon.WasBought) then
-- some weapons give extra ammo after being bought, etc
_weapon:WasBought(_ply)
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,
},
ClipOnBuy = {
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 @@ -2220,3 +2220,8 @@ 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_clip_on_buy = [[The clip size on buy defines the amount of uses the weapon has after it was bought.

Note: This setting is only available for those weapons where its author implemented the handling of it.]]
TimGoll marked this conversation as resolved.
Show resolved Hide resolved
L.label_equipmenteditor_clip_on_buy = "Clip size on buy"
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.SetClipOnBuy then
form2:MakeHelp({
label = "help_equipmenteditor_clip_on_buy",
})

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

local equipmentClass = WEPS.GetClass(equipment)
Expand Down