add sborka
This commit is contained in:
46
garrysmod/gamemodes/helix/gamemode/items/base/sh_ammo.lua
Normal file
46
garrysmod/gamemodes/helix/gamemode/items/base/sh_ammo.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
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
|
||||
248
garrysmod/gamemodes/helix/gamemode/items/base/sh_bags.lua
Normal file
248
garrysmod/gamemodes/helix/gamemode/items/base/sh_bags.lua
Normal file
@@ -0,0 +1,248 @@
|
||||
|
||||
if (SERVER) then
|
||||
util.AddNetworkString("ixBagDrop")
|
||||
end
|
||||
|
||||
ITEM.name = "Bag"
|
||||
ITEM.description = "A bag to hold items."
|
||||
ITEM.model = "models/props_c17/suitcase001a.mdl"
|
||||
ITEM.category = "Storage"
|
||||
ITEM.width = 2
|
||||
ITEM.height = 2
|
||||
ITEM.invWidth = 4
|
||||
ITEM.invHeight = 2
|
||||
ITEM.isBag = true
|
||||
ITEM.functions.View = {
|
||||
icon = "icon16/briefcase.png",
|
||||
OnClick = function(item)
|
||||
local index = item:GetData("id", "")
|
||||
|
||||
if (index) then
|
||||
local panel = ix.gui["inv"..index]
|
||||
local inventory = ix.item.inventories[index]
|
||||
local parent = IsValid(ix.gui.menuInventoryContainer) and ix.gui.menuInventoryContainer or ix.gui.openedStorage
|
||||
|
||||
if (IsValid(panel)) then
|
||||
panel:Remove()
|
||||
end
|
||||
|
||||
if (inventory and inventory.slots) then
|
||||
panel = vgui.Create("ixInventory", IsValid(parent) and parent or nil)
|
||||
panel:SetInventory(inventory)
|
||||
panel:ShowCloseButton(true)
|
||||
panel:SetTitle(item.GetName and item:GetName() or L(item.name))
|
||||
|
||||
if (parent != ix.gui.menuInventoryContainer) then
|
||||
panel:Center()
|
||||
|
||||
if (parent == ix.gui.openedStorage) then
|
||||
panel:MakePopup()
|
||||
end
|
||||
else
|
||||
panel:MoveToFront()
|
||||
end
|
||||
|
||||
ix.gui["inv"..index] = panel
|
||||
else
|
||||
ErrorNoHalt("[Helix] Attempt to view an uninitialized inventory '"..index.."'\n")
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
return !IsValid(item.entity) and item:GetData("id") and !IsValid(ix.gui["inv" .. item:GetData("id", "")])
|
||||
end
|
||||
}
|
||||
ITEM.functions.combine = {
|
||||
OnRun = function(item, data)
|
||||
ix.item.instances[data[1]]:Transfer(item:GetData("id"), nil, nil, item.player)
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item, data)
|
||||
local index = item:GetData("id", "")
|
||||
|
||||
if (index) then
|
||||
local inventory = ix.item.inventories[index]
|
||||
|
||||
if (inventory) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
}
|
||||
|
||||
if (CLIENT) then
|
||||
function ITEM:PaintOver(item, width, height)
|
||||
local panel = ix.gui["inv" .. item:GetData("id", "")]
|
||||
|
||||
if (!IsValid(panel)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (vgui.GetHoveredPanel() == self) then
|
||||
panel:SetHighlighted(true)
|
||||
else
|
||||
panel:SetHighlighted(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Called when a new instance of this item has been made.
|
||||
function ITEM:OnInstanced(invID, x, y)
|
||||
local inventory = ix.item.inventories[invID]
|
||||
|
||||
ix.inventory.New(inventory and inventory.owner or 0, self.uniqueID, function(inv)
|
||||
local client = inv:GetOwner()
|
||||
|
||||
inv.vars.isBag = self.uniqueID
|
||||
self:SetData("id", inv:GetID())
|
||||
|
||||
if (IsValid(client)) then
|
||||
inv:AddReceiver(client)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function ITEM:GetInventory()
|
||||
local index = self:GetData("id")
|
||||
|
||||
if (index) then
|
||||
return ix.item.inventories[index]
|
||||
end
|
||||
end
|
||||
|
||||
ITEM.GetInv = ITEM.GetInventory
|
||||
|
||||
-- Called when the item first appears for a client.
|
||||
function ITEM:OnSendData()
|
||||
local index = self:GetData("id")
|
||||
|
||||
if (index) then
|
||||
local inventory = ix.item.inventories[index]
|
||||
|
||||
if (inventory) then
|
||||
inventory.vars.isBag = self.uniqueID
|
||||
inventory:Sync(self.player)
|
||||
inventory:AddReceiver(self.player)
|
||||
else
|
||||
local owner = self.player:GetCharacter():GetID()
|
||||
|
||||
ix.inventory.Restore(self:GetData("id"), self.invWidth, self.invHeight, function(inv)
|
||||
inv.vars.isBag = self.uniqueID
|
||||
inv:SetOwner(owner, true)
|
||||
|
||||
if (!inv.owner) then
|
||||
return
|
||||
end
|
||||
|
||||
for client, character in ix.util.GetCharacters() do
|
||||
if (character:GetID() == inv.owner) then
|
||||
inv:AddReceiver(client)
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
else
|
||||
ix.inventory.New(self.player:GetCharacter():GetID(), self.uniqueID, function(inv)
|
||||
self:SetData("id", inv:GetID())
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
ITEM.postHooks.drop = function(item, result)
|
||||
local index = item:GetData("id")
|
||||
|
||||
local query = mysql:Update("ix_inventories")
|
||||
query:Update("character_id", 0)
|
||||
query:Where("inventory_id", index)
|
||||
query:Execute()
|
||||
|
||||
net.Start("ixBagDrop")
|
||||
net.WriteUInt(index, 32)
|
||||
net.Send(item.player)
|
||||
end
|
||||
|
||||
if (CLIENT) then
|
||||
net.Receive("ixBagDrop", function()
|
||||
local index = net.ReadUInt(32)
|
||||
local panel = ix.gui["inv"..index]
|
||||
|
||||
if (panel and panel:IsVisible()) then
|
||||
panel:Close()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Called before the item is permanently deleted.
|
||||
function ITEM:OnRemoved()
|
||||
local index = self:GetData("id")
|
||||
|
||||
if (index) then
|
||||
local query = mysql:Delete("ix_items")
|
||||
query:Where("inventory_id", index)
|
||||
query:Execute()
|
||||
|
||||
query = mysql:Delete("ix_inventories")
|
||||
query:Where("inventory_id", index)
|
||||
query:Execute()
|
||||
end
|
||||
end
|
||||
|
||||
-- Called when the item should tell whether or not it can be transfered between inventories.
|
||||
function ITEM:CanTransfer(oldInventory, newInventory)
|
||||
local index = self:GetData("id")
|
||||
|
||||
if (newInventory) then
|
||||
if (newInventory.vars and newInventory.vars.isBag) then
|
||||
return false
|
||||
end
|
||||
|
||||
local index2 = newInventory:GetID()
|
||||
|
||||
if (index == index2) then
|
||||
return false
|
||||
end
|
||||
|
||||
for k, _ in self:GetInventory():Iter() do
|
||||
if (k:GetData("id") == index2) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return !newInventory or newInventory:GetID() != oldInventory:GetID() or newInventory.vars.isBag
|
||||
end
|
||||
|
||||
function ITEM:OnTransferred(curInv, inventory)
|
||||
local bagInventory = self:GetInventory()
|
||||
|
||||
if (isfunction(curInv.GetOwner)) then
|
||||
local owner = curInv:GetOwner()
|
||||
|
||||
if (IsValid(owner)) then
|
||||
bagInventory:RemoveReceiver(owner)
|
||||
end
|
||||
end
|
||||
|
||||
if (isfunction(inventory.GetOwner)) then
|
||||
local owner = inventory:GetOwner()
|
||||
|
||||
if (IsValid(owner)) then
|
||||
bagInventory:AddReceiver(owner)
|
||||
bagInventory:SetOwner(owner)
|
||||
end
|
||||
else
|
||||
-- it's not in a valid inventory so nobody owns this bag
|
||||
bagInventory:SetOwner(nil)
|
||||
end
|
||||
end
|
||||
|
||||
-- Called after the item is registered into the item tables.
|
||||
function ITEM:OnRegistered()
|
||||
ix.inventory.Register(self.uniqueID, self.invWidth, self.invHeight, true)
|
||||
end
|
||||
322
garrysmod/gamemodes/helix/gamemode/items/base/sh_outfit.lua
Normal file
322
garrysmod/gamemodes/helix/gamemode/items/base/sh_outfit.lua
Normal file
@@ -0,0 +1,322 @@
|
||||
|
||||
ITEM.name = "Outfit"
|
||||
ITEM.description = "A Outfit Base."
|
||||
ITEM.category = "Outfit"
|
||||
ITEM.model = "models/Gibs/HGIBS.mdl"
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.outfitCategory = "model"
|
||||
ITEM.pacData = {}
|
||||
|
||||
--[[
|
||||
-- This will change a player's skin after changing the model. Keep in mind it starts at 0.
|
||||
ITEM.newSkin = 1
|
||||
-- This will change a certain part of the model.
|
||||
ITEM.replacements = {"group01", "group02"}
|
||||
-- This will change the player's model completely.
|
||||
ITEM.replacements = "models/manhack.mdl"
|
||||
-- This will have multiple replacements.
|
||||
ITEM.replacements = {
|
||||
{"male", "female"},
|
||||
{"group01", "group02"}
|
||||
}
|
||||
|
||||
-- This will apply body groups.
|
||||
ITEM.bodyGroups = {
|
||||
["blade"] = 1,
|
||||
["bladeblur"] = 1
|
||||
}
|
||||
]]--
|
||||
|
||||
-- Inventory drawing
|
||||
if (CLIENT) then
|
||||
function ITEM:PaintOver(item, w, h)
|
||||
if (item:GetData("equip")) then
|
||||
surface.SetDrawColor(110, 255, 110, 100)
|
||||
surface.DrawRect(w - 14, h - 14, 8, 8)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:AddOutfit(client)
|
||||
local character = client:GetCharacter()
|
||||
|
||||
self:SetData("equip", true)
|
||||
|
||||
local groups = character:GetData("groups", {})
|
||||
|
||||
-- remove original bodygroups
|
||||
if (!table.IsEmpty(groups)) then
|
||||
character:SetData("oldGroups" .. self.outfitCategory, groups)
|
||||
character:SetData("groups", {})
|
||||
|
||||
client:ResetBodygroups()
|
||||
end
|
||||
|
||||
if (isfunction(self.OnGetReplacement)) then
|
||||
character:SetData("oldModel" .. self.outfitCategory,
|
||||
character:GetData("oldModel" .. self.outfitCategory, self.player:GetModel()))
|
||||
character:SetModel(self:OnGetReplacement())
|
||||
elseif (self.replacement or self.replacements) then
|
||||
character:SetData("oldModel" .. self.outfitCategory,
|
||||
character:GetData("oldModel" .. self.outfitCategory, self.player:GetModel()))
|
||||
|
||||
if (istable(self.replacements)) then
|
||||
if (#self.replacements == 2 and isstring(self.replacements[1])) then
|
||||
character:SetModel(self.player:GetModel():gsub(self.replacements[1], self.replacements[2]))
|
||||
else
|
||||
for _, v in ipairs(self.replacements) do
|
||||
character:SetModel(self.player:GetModel():gsub(v[1], v[2]))
|
||||
end
|
||||
end
|
||||
else
|
||||
character:SetModel(self.replacement or self.replacements)
|
||||
end
|
||||
end
|
||||
|
||||
if (self.newSkin) then
|
||||
character:SetData("oldSkin" .. self.outfitCategory, self.player:GetSkin())
|
||||
self.player:SetSkin(self.newSkin)
|
||||
end
|
||||
|
||||
-- get outfit saved bodygroups
|
||||
groups = self:GetData("groups", {})
|
||||
|
||||
-- restore bodygroups saved to the item
|
||||
if (!table.IsEmpty(groups) and self:ShouldRestoreBodygroups()) then
|
||||
for k, v in pairs(groups) do
|
||||
client:SetBodygroup(k, v)
|
||||
end
|
||||
-- apply default item bodygroups if none are saved
|
||||
elseif (istable(self.bodyGroups)) then
|
||||
for k, v in pairs(self.bodyGroups) do
|
||||
local index = client:FindBodygroupByName(k)
|
||||
|
||||
if (index > -1) then
|
||||
client:SetBodygroup(index, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local materials = self:GetData("submaterial", {})
|
||||
|
||||
if (!table.IsEmpty(materials) and self:ShouldRestoreSubMaterials()) then
|
||||
for k, v in pairs(materials) do
|
||||
if (!isnumber(k) or !isstring(v)) then
|
||||
continue
|
||||
end
|
||||
|
||||
client:SetSubMaterial(k - 1, v)
|
||||
end
|
||||
end
|
||||
|
||||
if (istable(self.attribBoosts)) then
|
||||
for k, v in pairs(self.attribBoosts) do
|
||||
character:AddBoost(self.uniqueID, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
self:GetOwner():SetupHands()
|
||||
self:OnEquipped()
|
||||
end
|
||||
|
||||
local function ResetSubMaterials(client)
|
||||
for k, _ in ipairs(client:GetMaterials()) do
|
||||
if (client:GetSubMaterial(k - 1) != "") then
|
||||
client:SetSubMaterial(k - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:RemoveOutfit(client)
|
||||
local character = client:GetCharacter()
|
||||
|
||||
self:SetData("equip", false)
|
||||
|
||||
local materials = {}
|
||||
|
||||
for k, _ in ipairs(client:GetMaterials()) do
|
||||
if (client:GetSubMaterial(k - 1) != "") then
|
||||
materials[k] = client:GetSubMaterial(k - 1)
|
||||
end
|
||||
end
|
||||
|
||||
-- save outfit submaterials
|
||||
if (!table.IsEmpty(materials)) then
|
||||
self:SetData("submaterial", materials)
|
||||
end
|
||||
|
||||
-- remove outfit submaterials
|
||||
ResetSubMaterials(client)
|
||||
|
||||
local groups = {}
|
||||
|
||||
for i = 0, (client:GetNumBodyGroups() - 1) do
|
||||
local bodygroup = client:GetBodygroup(i)
|
||||
|
||||
if (bodygroup > 0) then
|
||||
groups[i] = bodygroup
|
||||
end
|
||||
end
|
||||
|
||||
-- save outfit bodygroups
|
||||
if (!table.IsEmpty(groups)) then
|
||||
self:SetData("groups", groups)
|
||||
end
|
||||
|
||||
-- remove outfit bodygroups
|
||||
client:ResetBodygroups()
|
||||
|
||||
-- restore the original player model
|
||||
if (character:GetData("oldModel" .. self.outfitCategory)) then
|
||||
character:SetModel(character:GetData("oldModel" .. self.outfitCategory))
|
||||
character:SetData("oldModel" .. self.outfitCategory, nil)
|
||||
end
|
||||
|
||||
-- restore the original player model skin
|
||||
if (self.newSkin) then
|
||||
if (character:GetData("oldSkin" .. self.outfitCategory)) then
|
||||
client:SetSkin(character:GetData("oldSkin" .. self.outfitCategory))
|
||||
character:SetData("oldSkin" .. self.outfitCategory, nil)
|
||||
else
|
||||
client:SetSkin(0)
|
||||
end
|
||||
end
|
||||
|
||||
-- get character original bodygroups
|
||||
groups = character:GetData("oldGroups" .. self.outfitCategory, {})
|
||||
|
||||
-- restore original bodygroups
|
||||
if (!table.IsEmpty(groups)) then
|
||||
for k, v in pairs(groups) do
|
||||
client:SetBodygroup(k, v)
|
||||
end
|
||||
|
||||
character:SetData("groups", character:GetData("oldGroups" .. self.outfitCategory, {}))
|
||||
character:SetData("oldGroups" .. self.outfitCategory, nil)
|
||||
end
|
||||
|
||||
if (istable(self.attribBoosts)) then
|
||||
for k, _ in pairs(self.attribBoosts) do
|
||||
character:RemoveBoost(self.uniqueID, k)
|
||||
end
|
||||
end
|
||||
|
||||
for k, _ in pairs(self:GetData("outfitAttachments", {})) do
|
||||
self:RemoveAttachment(k, client)
|
||||
end
|
||||
|
||||
self:GetOwner():SetupHands()
|
||||
self:OnUnequipped()
|
||||
end
|
||||
|
||||
-- makes another outfit depend on this outfit in terms of requiring this item to be equipped in order to equip the attachment
|
||||
-- also unequips the attachment if this item is dropped
|
||||
function ITEM:AddAttachment(id)
|
||||
local attachments = self:GetData("outfitAttachments", {})
|
||||
attachments[id] = true
|
||||
|
||||
self:SetData("outfitAttachments", attachments)
|
||||
end
|
||||
|
||||
function ITEM:RemoveAttachment(id, client)
|
||||
local item = ix.item.instances[id]
|
||||
local attachments = self:GetData("outfitAttachments", {})
|
||||
|
||||
if (item and attachments[id]) then
|
||||
item:OnDetached(client)
|
||||
end
|
||||
|
||||
attachments[id] = nil
|
||||
self:SetData("outfitAttachments", attachments)
|
||||
end
|
||||
|
||||
ITEM:Hook("drop", function(item)
|
||||
if (item:GetData("equip")) then
|
||||
local character = ix.char.loaded[item.owner]
|
||||
local client = character and character:GetPlayer() or item:GetOwner()
|
||||
|
||||
item.player = client
|
||||
item:RemoveOutfit(item:GetOwner())
|
||||
end
|
||||
end)
|
||||
|
||||
ITEM.functions.EquipUn = { -- sorry, for name order.
|
||||
name = "unequip",
|
||||
tip = "unequipTip",
|
||||
icon = "icon16/cross.png",
|
||||
OnRun = function(item)
|
||||
item:RemoveOutfit(item.player)
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") == true and
|
||||
hook.Run("CanPlayerUnequipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
ITEM.functions.Equip = {
|
||||
name = "equip",
|
||||
tip = "equipTip",
|
||||
icon = "icon16/tick.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local char = client:GetCharacter()
|
||||
|
||||
for k, _ in char:GetInventory():Iter() do
|
||||
if (k.id != item.id) then
|
||||
local itemTable = ix.item.instances[k.id]
|
||||
|
||||
if (itemTable.pacData and k.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
|
||||
client:NotifyLocalized(item.equippedNotify or "outfitAlreadyEquipped")
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
item:AddOutfit(item.player)
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") != true and item:CanEquipOutfit() and
|
||||
hook.Run("CanPlayerEquipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
function ITEM:CanTransfer(oldInventory, newInventory)
|
||||
if (newInventory and self:GetData("equip")) then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function ITEM:OnRemoved()
|
||||
if (self.invID != 0 and self:GetData("equip")) then
|
||||
self.player = self:GetOwner()
|
||||
self:RemoveOutfit(self.player)
|
||||
self.player = nil
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:OnEquipped()
|
||||
end
|
||||
|
||||
function ITEM:OnUnequipped()
|
||||
end
|
||||
|
||||
function ITEM:CanEquipOutfit()
|
||||
return true
|
||||
end
|
||||
|
||||
function ITEM:ShouldRestoreBodygroups()
|
||||
return true
|
||||
end
|
||||
|
||||
function ITEM:ShouldRestoreSubMaterials()
|
||||
return true
|
||||
end
|
||||
171
garrysmod/gamemodes/helix/gamemode/items/base/sh_pacoutfit.lua
Normal file
171
garrysmod/gamemodes/helix/gamemode/items/base/sh_pacoutfit.lua
Normal file
@@ -0,0 +1,171 @@
|
||||
|
||||
ITEM.name = "PAC Outfit"
|
||||
ITEM.description = "A PAC Outfit Base."
|
||||
ITEM.category = "Outfit"
|
||||
ITEM.model = "models/Gibs/HGIBS.mdl"
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.outfitCategory = "hat"
|
||||
ITEM.pacData = {}
|
||||
|
||||
--[[
|
||||
ITEM.pacData = {
|
||||
[1] = {
|
||||
["children"] = {
|
||||
[1] = {
|
||||
["children"] = {
|
||||
},
|
||||
["self"] = {
|
||||
["Angles"] = Angle(12.919322967529, 6.5696062847564e-006, -1.0949343050015e-005),
|
||||
["Position"] = Vector(-2.099609375, 0.019973754882813, 1.0180969238281),
|
||||
["UniqueID"] = "4249811628",
|
||||
["Size"] = 1.25,
|
||||
["Bone"] = "eyes",
|
||||
["Model"] = "models/Gibs/HGIBS.mdl",
|
||||
["ClassName"] = "model",
|
||||
},
|
||||
},
|
||||
},
|
||||
["self"] = {
|
||||
["ClassName"] = "group",
|
||||
["UniqueID"] = "907159817",
|
||||
["EditorExpand"] = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- This will change a player's skin after changing the model. Keep in mind it starts at 0.
|
||||
ITEM.newSkin = 1
|
||||
-- This will change a certain part of the model.
|
||||
ITEM.replacements = {"group01", "group02"}
|
||||
-- This will change the player's model completely.
|
||||
ITEM.replacements = "models/manhack.mdl"
|
||||
-- This will have multiple replacements.
|
||||
ITEM.replacements = {
|
||||
{"male", "female"},
|
||||
{"group01", "group02"}
|
||||
}
|
||||
|
||||
-- This will apply body groups.
|
||||
ITEM.bodyGroups = {
|
||||
["blade"] = 1,
|
||||
["bladeblur"] = 1
|
||||
}
|
||||
|
||||
--]]
|
||||
|
||||
-- Inventory drawing
|
||||
if (CLIENT) then
|
||||
-- Draw camo if it is available.
|
||||
function ITEM:PaintOver(item, w, h)
|
||||
if (item:GetData("equip")) then
|
||||
surface.SetDrawColor(110, 255, 110, 100)
|
||||
surface.DrawRect(w - 14, h - 14, 8, 8)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:RemovePart(client)
|
||||
local char = client:GetCharacter()
|
||||
|
||||
self:SetData("equip", false)
|
||||
client:RemovePart(self.uniqueID)
|
||||
|
||||
if (self.attribBoosts) then
|
||||
for k, _ in pairs(self.attribBoosts) do
|
||||
char:RemoveBoost(self.uniqueID, k)
|
||||
end
|
||||
end
|
||||
|
||||
self:OnUnequipped()
|
||||
end
|
||||
|
||||
-- On item is dropped, Remove a weapon from the player and keep the ammo in the item.
|
||||
ITEM:Hook("drop", function(item)
|
||||
if (item:GetData("equip")) then
|
||||
item:RemovePart(item:GetOwner())
|
||||
end
|
||||
end)
|
||||
|
||||
-- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item.
|
||||
ITEM.functions.EquipUn = { -- sorry, for name order.
|
||||
name = "unequip",
|
||||
tip = "unequipTip",
|
||||
icon = "icon16/cross.png",
|
||||
OnRun = function(item)
|
||||
item:RemovePart(item.player)
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") == true and
|
||||
hook.Run("CanPlayerUnequipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
-- On player eqipped the item, Gives a weapon to player and load the ammo data from the item.
|
||||
ITEM.functions.Equip = {
|
||||
name = "equip",
|
||||
tip = "equipTip",
|
||||
icon = "icon16/tick.png",
|
||||
OnRun = function(item)
|
||||
local char = item.player:GetCharacter()
|
||||
|
||||
for k, _ in char:GetInventory():Iter() do
|
||||
if (k.id != item.id) then
|
||||
local itemTable = ix.item.instances[k.id]
|
||||
|
||||
if (itemTable.pacData and k.outfitCategory == item.outfitCategory and itemTable:GetData("equip")) then
|
||||
item.player:NotifyLocalized(item.equippedNotify or "outfitAlreadyEquipped")
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
item:SetData("equip", true)
|
||||
item.player:AddPart(item.uniqueID, item)
|
||||
|
||||
if (item.attribBoosts) then
|
||||
for k, v in pairs(item.attribBoosts) do
|
||||
char:AddBoost(item.uniqueID, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
item:OnEquipped()
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") != true and
|
||||
hook.Run("CanPlayerEquipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
function ITEM:CanTransfer(oldInventory, newInventory)
|
||||
if (newInventory and self:GetData("equip")) then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function ITEM:OnRemoved()
|
||||
local inventory = ix.item.inventories[self.invID]
|
||||
local owner = inventory.GetOwner and inventory:GetOwner()
|
||||
|
||||
if (IsValid(owner) and owner:IsPlayer()) then
|
||||
if (self:GetData("equip")) then
|
||||
self:RemovePart(owner)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:OnEquipped()
|
||||
end
|
||||
|
||||
function ITEM:OnUnequipped()
|
||||
end
|
||||
316
garrysmod/gamemodes/helix/gamemode/items/base/sh_weapons.lua
Normal file
316
garrysmod/gamemodes/helix/gamemode/items/base/sh_weapons.lua
Normal file
@@ -0,0 +1,316 @@
|
||||
|
||||
ITEM.name = "Weapon"
|
||||
ITEM.description = "A Weapon."
|
||||
ITEM.category = "Weapons"
|
||||
ITEM.model = "models/weapons/w_pistol.mdl"
|
||||
ITEM.class = "weapon_pistol"
|
||||
ITEM.width = 2
|
||||
ITEM.height = 2
|
||||
ITEM.isWeapon = true
|
||||
ITEM.isGrenade = false
|
||||
ITEM.weaponCategory = "sidearm"
|
||||
ITEM.useSound = "items/ammo_pickup.wav"
|
||||
|
||||
-- Inventory drawing
|
||||
if (CLIENT) then
|
||||
function ITEM:PaintOver(item, w, h)
|
||||
if (item:GetData("equip")) then
|
||||
surface.SetDrawColor(110, 255, 110, 100)
|
||||
surface.DrawRect(w - 14, h - 14, 8, 8)
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:PopulateTooltip(tooltip)
|
||||
if (self:GetData("equip")) then
|
||||
local name = tooltip:GetRow("name")
|
||||
name:SetBackgroundColor(derma.GetColor("Success", tooltip))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- On item is dropped, Remove a weapon from the player and keep the ammo in the item.
|
||||
ITEM:Hook("drop", function(item)
|
||||
local inventory = ix.item.inventories[item.invID]
|
||||
|
||||
if (!inventory) then
|
||||
return
|
||||
end
|
||||
|
||||
-- the item could have been dropped by someone else (i.e someone searching this player), so we find the real owner
|
||||
local owner
|
||||
|
||||
for client, character in ix.util.GetCharacters() do
|
||||
if (character:GetID() == inventory.owner) then
|
||||
owner = client
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if (!IsValid(owner)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (item:GetData("equip")) then
|
||||
item:SetData("equip", nil)
|
||||
|
||||
owner.carryWeapons = owner.carryWeapons or {}
|
||||
|
||||
local weapon = owner.carryWeapons[item.weaponCategory]
|
||||
|
||||
if (!IsValid(weapon)) then
|
||||
weapon = owner:GetWeapon(item.class)
|
||||
end
|
||||
|
||||
if (IsValid(weapon)) then
|
||||
item:SetData("ammo", weapon:Clip1())
|
||||
|
||||
owner:StripWeapon(item.class)
|
||||
owner.carryWeapons[item.weaponCategory] = nil
|
||||
owner:EmitSound(item.useSound, 80)
|
||||
end
|
||||
|
||||
item:RemovePAC(owner)
|
||||
end
|
||||
end)
|
||||
|
||||
-- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item.
|
||||
ITEM.functions.EquipUn = { -- sorry, for name order.
|
||||
name = "unequip",
|
||||
tip = "unequipTip",
|
||||
icon = "icon16/cross.png",
|
||||
OnRun = function(item)
|
||||
item:Unequip(item.player, true)
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") == true and
|
||||
hook.Run("CanPlayerUnequipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
-- On player eqipped the item, Gives a weapon to player and load the ammo data from the item.
|
||||
ITEM.functions.Equip = {
|
||||
name = "equip",
|
||||
tip = "equipTip",
|
||||
icon = "icon16/tick.png",
|
||||
OnRun = function(item)
|
||||
item:Equip(item.player)
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return !IsValid(item.entity) and IsValid(client) and item:GetData("equip") != true and
|
||||
hook.Run("CanPlayerEquipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
function ITEM:WearPAC(client)
|
||||
if (ix.pac and self.pacData) then
|
||||
client:AddPart(self.uniqueID, self)
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:RemovePAC(client)
|
||||
if (ix.pac and self.pacData) then
|
||||
client:RemovePart(self.uniqueID)
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:Equip(client, bNoSelect, bNoSound)
|
||||
client.carryWeapons = client.carryWeapons or {}
|
||||
|
||||
for k, _ in client:GetCharacter():GetInventory():Iter() do
|
||||
if (k.id != self.id) then
|
||||
local itemTable = ix.item.instances[k.id]
|
||||
|
||||
if (!itemTable) then
|
||||
client:NotifyLocalized("tellAdmin", "wid!xt")
|
||||
|
||||
return false
|
||||
else
|
||||
if (itemTable.isWeapon and client.carryWeapons[self.weaponCategory] and itemTable:GetData("equip")) then
|
||||
client:NotifyLocalized("weaponSlotFilled", self.weaponCategory)
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (client:HasWeapon(self.class)) then
|
||||
client:StripWeapon(self.class)
|
||||
end
|
||||
|
||||
local weapon = client:Give(self.class, !self.isGrenade)
|
||||
|
||||
if (IsValid(weapon)) then
|
||||
local ammoType = weapon:GetPrimaryAmmoType()
|
||||
|
||||
client.carryWeapons[self.weaponCategory] = weapon
|
||||
|
||||
if (!bNoSelect) then
|
||||
client:SelectWeapon(weapon:GetClass())
|
||||
end
|
||||
|
||||
if (!bNoSound) then
|
||||
client:EmitSound(self.useSound, 80)
|
||||
end
|
||||
|
||||
-- Remove default given ammo.
|
||||
if (client:GetAmmoCount(ammoType) == weapon:Clip1() and self:GetData("ammo", 0) == 0) then
|
||||
client:RemoveAmmo(weapon:Clip1(), ammoType)
|
||||
end
|
||||
|
||||
-- assume that a weapon with -1 clip1 and clip2 would be a throwable (i.e hl2 grenade)
|
||||
-- TODO: figure out if this interferes with any other weapons
|
||||
if (weapon:GetMaxClip1() == -1 and weapon:GetMaxClip2() == -1 and client:GetAmmoCount(ammoType) == 0) then
|
||||
client:SetAmmo(1, ammoType)
|
||||
end
|
||||
|
||||
self:SetData("equip", true)
|
||||
|
||||
if (self.isGrenade) then
|
||||
weapon:SetClip1(1)
|
||||
client:SetAmmo(0, ammoType)
|
||||
else
|
||||
weapon:SetClip1(self:GetData("ammo", 0))
|
||||
end
|
||||
|
||||
weapon.ixItem = self
|
||||
|
||||
if (self.OnEquipWeapon) then
|
||||
self:OnEquipWeapon(client, weapon)
|
||||
end
|
||||
else
|
||||
print(Format("[Helix] Cannot equip weapon - %s does not exist!", self.class))
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:Unequip(client, bPlaySound, bRemoveItem)
|
||||
client.carryWeapons = client.carryWeapons or {}
|
||||
|
||||
local weapon = client.carryWeapons[self.weaponCategory]
|
||||
|
||||
if (!IsValid(weapon)) then
|
||||
weapon = client:GetWeapon(self.class)
|
||||
end
|
||||
|
||||
if (IsValid(weapon)) then
|
||||
weapon.ixItem = nil
|
||||
|
||||
self:SetData("ammo", weapon:Clip1())
|
||||
client:StripWeapon(self.class)
|
||||
else
|
||||
print(Format("[Helix] Cannot unequip weapon - %s does not exist!", self.class))
|
||||
end
|
||||
|
||||
if (bPlaySound) then
|
||||
client:EmitSound(self.useSound, 80)
|
||||
end
|
||||
|
||||
client.carryWeapons[self.weaponCategory] = nil
|
||||
self:SetData("equip", nil)
|
||||
self:RemovePAC(client)
|
||||
|
||||
if (self.OnUnequipWeapon) then
|
||||
self:OnUnequipWeapon(client, weapon)
|
||||
end
|
||||
|
||||
if (bRemoveItem) then
|
||||
self:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:CanTransfer(oldInventory, newInventory)
|
||||
if (newInventory and self:GetData("equip")) then
|
||||
local owner = self:GetOwner()
|
||||
|
||||
if (IsValid(owner)) then
|
||||
owner:NotifyLocalized("equippedWeapon")
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function ITEM:OnLoadout()
|
||||
if (self:GetData("equip")) then
|
||||
local client = self.player
|
||||
client.carryWeapons = client.carryWeapons or {}
|
||||
|
||||
local weapon = client:Give(self.class, true)
|
||||
|
||||
if (IsValid(weapon)) then
|
||||
client:RemoveAmmo(weapon:Clip1(), weapon:GetPrimaryAmmoType())
|
||||
client.carryWeapons[self.weaponCategory] = weapon
|
||||
|
||||
weapon.ixItem = self
|
||||
weapon:SetClip1(self:GetData("ammo", 0))
|
||||
|
||||
if (self.OnEquipWeapon) then
|
||||
self:OnEquipWeapon(client, weapon)
|
||||
end
|
||||
else
|
||||
print(Format("[Helix] Cannot give weapon - %s does not exist!", self.class))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:OnSave()
|
||||
local weapon = self.player:GetWeapon(self.class)
|
||||
|
||||
if (IsValid(weapon) and weapon.ixItem == self and self:GetData("equip")) then
|
||||
self:SetData("ammo", weapon:Clip1())
|
||||
end
|
||||
end
|
||||
|
||||
function ITEM:OnRemoved()
|
||||
local inventory = ix.item.inventories[self.invID]
|
||||
local owner = inventory.GetOwner and inventory:GetOwner()
|
||||
|
||||
if (IsValid(owner) and owner:IsPlayer()) then
|
||||
local weapon = owner:GetWeapon(self.class)
|
||||
|
||||
if (IsValid(weapon)) then
|
||||
weapon:Remove()
|
||||
end
|
||||
|
||||
self:RemovePAC(owner)
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("PlayerDeath", "ixStripClip", function(client)
|
||||
client.carryWeapons = {}
|
||||
|
||||
for k, _ in client:GetCharacter():GetInventory():Iter() do
|
||||
if (k.isWeapon and k:GetData("equip")) then
|
||||
k:SetData("ammo", nil)
|
||||
k:SetData("equip", nil)
|
||||
|
||||
if (k.pacData) then
|
||||
k:RemovePAC(client)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
hook.Add("EntityRemoved", "ixRemoveGrenade", function(entity)
|
||||
-- hack to remove hl2 grenades after they've all been thrown
|
||||
if (entity:GetClass() == "weapon_frag") then
|
||||
local client = entity:GetOwner()
|
||||
|
||||
if (IsValid(client) and client:IsPlayer() and client:GetCharacter()) then
|
||||
local ammoName = game.GetAmmoName(entity:GetPrimaryAmmoType())
|
||||
|
||||
if (isstring(ammoName) and ammoName:lower() == "grenade" and client:GetAmmoCount(ammoName) < 1
|
||||
and entity.ixItem and entity.ixItem.Unequip) then
|
||||
entity.ixItem:Unequip(client, false, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user