Files
VnUtest/garrysmod/gamemodes/helix/gamemode/items/base/sh_ammo.lua
2026-03-31 10:27:04 +03:00

47 lines
1.2 KiB
Lua

ITEM.name = "Ammo Base"
ITEM.model = "models/Items/BoxSRounds.mdl"
ITEM.width = 1
ITEM.height = 1
ITEM.ammo = "pistol" -- type of the ammo
ITEM.ammoAmount = 30 -- amount of the ammo
ITEM.description = "A Box that contains %s of Pistol Ammo"
ITEM.category = "Ammunition"
ITEM.useSound = "items/ammo_pickup.wav"
function ITEM:GetDescription()
local rounds = self:GetData("rounds", self.ammoAmount)
return Format(self.description, rounds)
end
if (CLIENT) then
function ITEM:PaintOver(item, w, h)
draw.SimpleText(
item:GetData("rounds", item.ammoAmount), "DermaDefault", w - 5, h - 5,
color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM, 1, color_black
)
end
end
-- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item.
ITEM.functions.use = {
name = "Load",
tip = "useTip",
icon = "icon16/add.png",
OnRun = function(item)
local rounds = item:GetData("rounds", item.ammoAmount)
item.player:GiveAmmo(rounds, item.ammo)
item.player:EmitSound(item.useSound, 110)
return true
end,
}
-- Called after the item is registered into the item tables.
function ITEM:OnRegistered()
if (ix.ammo) then
ix.ammo.Register(self.ammo)
end
end