mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
local path = "willardnetworks/tabmenu/inventory/equipslots/icon-"
|
||||
local partPaintsDefault = {
|
||||
[1] = {icon = ix.util.GetMaterial(path.."head.png"), category = "Head"},
|
||||
[2] = {icon = ix.util.GetMaterial(path.."glasses.png"), category = "Glasses"},
|
||||
[3] = {icon = ix.util.GetMaterial(path.."face.png"), category = "Face"},
|
||||
[4] = {icon = ix.util.GetMaterial(path.."torso.png"), category = "Torso"},
|
||||
[5] = {icon = ix.util.GetMaterial(path.."hands.png"), category = "Hands"},
|
||||
[6] = {icon = ix.util.GetMaterial(path.."legs.png"), category = "Legs"},
|
||||
[7] = {icon = ix.util.GetMaterial(path.."shoes.png"), category = "Shoes"},
|
||||
[8] = {icon = ix.util.GetMaterial(path.."bagsmall.png"), category = "Satchel"},
|
||||
[9] = {icon = ix.util.GetMaterial(path.."baglarge.png"), category = "Bag"},
|
||||
[10] = {icon = ix.util.GetMaterial(path.."outfit.png"), category = "model"},
|
||||
}
|
||||
|
||||
|
||||
|
||||
function PANEL:PaintParts()
|
||||
local parent = self:GetParent()
|
||||
local openedStorage = (!ix.gui.openedStorage or ix.gui.openedStorage and !IsValid(ix.gui.openedStorage)) or false
|
||||
|
||||
for k, v in pairs(self:GetChildren()) do
|
||||
local partPaints = hook.Run("GetEquipSlotsPartPaints", self, openedStorage) or partPaintsDefault
|
||||
if !partPaints[k] then continue end
|
||||
if !partPaints[k].icon then continue end
|
||||
if !partPaints[k].category then continue end
|
||||
|
||||
v.Paint = function(this, w, h)
|
||||
local char = LocalPlayer():GetCharacter()
|
||||
local faction = char and char.GetFaction and char:GetFaction()
|
||||
local noEquipFactions = PLUGIN.noEquipFactions
|
||||
local isNoEquipFaction = !openedStorage and self.isNoEquipFaction or faction and noEquipFactions and noEquipFactions[faction]
|
||||
|
||||
local bNoEquip = hook.Run("CanEquipSlot", self, openedStorage, k) == false
|
||||
|
||||
local color = (isNoEquipFaction or bNoEquip) and Color(80, 80, 80, 150) or Color(35, 35, 35, 85)
|
||||
surface.SetDrawColor(color)
|
||||
surface.DrawRect(1, 1, w - SScaleMin(2 / 3), h - SScaleMin(2 / 3))
|
||||
|
||||
local iconSize2 = SScaleMin(45 / 3)
|
||||
|
||||
if (isNoEquipFaction or bNoEquip) then
|
||||
surface.SetDrawColor(Color(150, 150, 150, 255))
|
||||
surface.DrawLine( 1, 1, w - SScaleMin(2 / 3), h - SScaleMin(2 / 3) )
|
||||
surface.DrawLine( 1, w - SScaleMin(2 / 3), h - SScaleMin(2 / 3), 1 )
|
||||
end
|
||||
|
||||
surface.SetDrawColor(80, 80, 80, 255)
|
||||
surface.DrawOutlinedRect(1, 1, w - SScaleMin(2 / 3), h - SScaleMin(2 / 3))
|
||||
|
||||
local squareSize = SScaleMin(90 / 3)
|
||||
local halfSquare = squareSize * 0.5
|
||||
local halfIcon = iconSize2 * 0.5
|
||||
|
||||
surface.SetDrawColor(color_white)
|
||||
surface.SetMaterial(partPaints[k] and partPaints[k].icon or partPaintsDefault[k].icon)
|
||||
surface.DrawTexturedRect(halfSquare - halfIcon, halfSquare - halfIcon, iconSize2, iconSize2)
|
||||
end
|
||||
|
||||
v.clothingCategory = partPaints[k].category
|
||||
if k > 5 then
|
||||
local cX, cY = v:GetPos()
|
||||
v:SetPos(cX + (SScaleMin(90 / 3) * 4), cY - (SScaleMin(90 / 3) * 5))
|
||||
end
|
||||
end
|
||||
|
||||
local invSize = (SScaleMin(90 / 3) * 5)
|
||||
self:SetSize(invSize, invSize)
|
||||
|
||||
local imgBackground = parent:GetChildren()[1]
|
||||
if imgBackground and IsValid(imgBackground) then
|
||||
local imgBackgroundW, imgBackgroundH = parent:GetWide() * 0.65, parent:GetTall()
|
||||
|
||||
self:SetPos(imgBackgroundW * 0.5 - self:GetWide() * 0.5, imgBackgroundH * 0.5 - self:GetTall() * 0.5)
|
||||
end
|
||||
end
|
||||
|
||||
vgui.Register("ixEquipSlots", PANEL, "ixInventory")
|
||||
137
gamemodes/helix/plugins/inventoryslots/sh_overrides.lua
Normal file
137
gamemodes/helix/plugins/inventoryslots/sh_overrides.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
--luacheck: ignore global GAMEMODE
|
||||
function GAMEMODE:CanPlayerEquipItem(client, item)
|
||||
return PLUGIN:CanEquipOrUnequip(client, item, true)
|
||||
end
|
||||
|
||||
function GAMEMODE:CanPlayerUnequipItem(client, item)
|
||||
return PLUGIN:CanEquipOrUnequip(client, item, false)
|
||||
end
|
||||
|
||||
local playerMeta = FindMetaTable("Player")
|
||||
|
||||
function playerMeta:GetItems()
|
||||
local char = self:GetCharacter()
|
||||
|
||||
if (char) then
|
||||
local inv = char:GetInventory()
|
||||
local eqInv = char:GetEquipInventory()
|
||||
if !eqInv or eqInv == 0 then return inv:GetItems() end
|
||||
local equipInv = ix.item.inventories[eqInv]
|
||||
|
||||
local invItems = inv:GetItems()
|
||||
local eqInvItems = equipInv:GetItems()
|
||||
|
||||
if (inv and equipInv) then
|
||||
local mergedInv = table.Merge(eqInvItems, invItems)
|
||||
return mergedInv
|
||||
end
|
||||
|
||||
if (inv) then
|
||||
return inv:GetItems()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local invMeta = ix.meta.inventory or ix.middleclass("ix_inventory")
|
||||
|
||||
function invMeta:GetItems(onlyMain, onlyWithin)
|
||||
local items = {}
|
||||
|
||||
for _, v in pairs(self.slots) do
|
||||
for _, v2 in pairs(v) do
|
||||
if (istable(v2) and !items[v2.id]) then
|
||||
items[v2.id] = v2
|
||||
|
||||
v2.data = v2.data or {}
|
||||
local isBag = v2.data.id
|
||||
if (isBag and isBag != self:GetID() and onlyMain != true) then
|
||||
local bagInv = ix.item.inventories[isBag]
|
||||
|
||||
if (bagInv) then
|
||||
local bagItems = bagInv:GetItems()
|
||||
|
||||
table.Merge(items, bagItems)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if !onlyWithin then
|
||||
local invOwner = self.GetOwner and IsValid(self:GetOwner()) and self:GetOwner()
|
||||
if invOwner then
|
||||
local ownerChar = invOwner.GetCharacter and invOwner:GetCharacter()
|
||||
if self == ownerChar:GetInventory() then
|
||||
local equipInventory = ownerChar.GetEquipInventory and ownerChar:GetEquipInventory()
|
||||
|
||||
if equipInventory and equipInventory != 0 then
|
||||
local equipInv = ix.item.inventories[equipInventory]
|
||||
if equipInv and equipInv.GetItems and equipInventory != self:GetID() then
|
||||
local equipSlotsInvItems = equipInv:GetItems(false, true)
|
||||
local mergedInv = table.Merge(equipSlotsInvItems, items)
|
||||
|
||||
return mergedInv
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return items
|
||||
end
|
||||
|
||||
function invMeta:GetBags()
|
||||
local invs = {}
|
||||
for _, v in pairs(self.slots) do
|
||||
for _, v2 in pairs(v) do
|
||||
if (istable(v2) and v2.data) then
|
||||
local isBag = (((v2.base == "base_bags") or v2.isBag) and v2.data.id)
|
||||
|
||||
if (!table.HasValue(invs, isBag)) then
|
||||
if (isBag and isBag != self:GetID()) then
|
||||
invs[#invs + 1] = isBag
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local invOwner = self.GetOwner and IsValid(self:GetOwner()) and self:GetOwner()
|
||||
if invOwner then
|
||||
local ownerChar = invOwner.GetCharacter and invOwner:GetCharacter()
|
||||
if self == ownerChar:GetInventory() then
|
||||
local equipInventory = ownerChar.GetEquipInventory and ownerChar:GetEquipInventory()
|
||||
|
||||
if equipInventory then
|
||||
local equipInv = ix.item.inventories[equipInventory]
|
||||
for _, v3 in pairs(equipInv.slots) do
|
||||
for _, v4 in pairs(v3) do
|
||||
if (istable(v4) and v4.data) then
|
||||
local isBag = (((v4.base == "base_bags") or v4.isBag) and v4.data.id)
|
||||
|
||||
if (!table.HasValue(invs, isBag)) then
|
||||
if (isBag and isBag != self:GetID()) then
|
||||
invs[#invs + 1] = isBag
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return invs
|
||||
end
|
||||
294
gamemodes/helix/plugins/inventoryslots/sh_plugin.lua
Normal file
294
gamemodes/helix/plugins/inventoryslots/sh_plugin.lua
Normal file
@@ -0,0 +1,294 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
ix.util.Include("sh_overrides.lua")
|
||||
|
||||
PLUGIN.name = "Emplacements d'inventaire"
|
||||
PLUGIN.author = "Fruity"
|
||||
PLUGIN.description = "Equip shit here."
|
||||
|
||||
PLUGIN.slotsW, PLUGIN.slotsH = 1, 10
|
||||
PLUGIN.slots = {
|
||||
["Head"] = 1,
|
||||
["Glasses"] = 2,
|
||||
["Face"] = 3,
|
||||
["Torso"] = 4,
|
||||
["Hands"] = 5,
|
||||
["Legs"] = 6,
|
||||
["Shoes"] = 7,
|
||||
["Satchel"] = 8,
|
||||
["Bag"] = 9,
|
||||
["model"] = 10,
|
||||
}
|
||||
|
||||
PLUGIN.noEquipFactions = PLUGIN.noEquipFactions or {}
|
||||
|
||||
ix.inventory.Register("equipInventory", PLUGIN.slotsW, PLUGIN.slotsH, true)
|
||||
|
||||
ix.char.RegisterVar("equipInventory", {
|
||||
field = "equipInventory",
|
||||
fieldType = ix.type.number,
|
||||
default = 0,
|
||||
bNoDisplay = true
|
||||
})
|
||||
|
||||
function PLUGIN:IsSameOwner(oldInv, newInv)
|
||||
-- need to check for owner because it might be world
|
||||
local oldOwner = oldInv and oldInv.GetOwner and oldInv:GetOwner() or false
|
||||
local newOwner = newInv and newInv.GetOwner and newInv:GetOwner() or false
|
||||
|
||||
if (oldOwner and newOwner) and (oldOwner == newOwner) then
|
||||
return oldInv:GetOwner()
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function PLUGIN:CanTransferBGClothes(oldInv, newInv)
|
||||
local owner = self:IsSameOwner(oldInv, newInv)
|
||||
local oldInvOwner = oldInv and oldInv.GetOwner and oldInv:GetOwner()
|
||||
local newInvOwner = newInv and newInv.GetOwner and newInv:GetOwner()
|
||||
|
||||
if !owner and !oldInvOwner and !newInvOwner then return false end
|
||||
if !owner and IsValid(newInvOwner) then owner = newInvOwner end
|
||||
if !owner and IsValid(oldInvOwner) then owner = oldInvOwner end
|
||||
|
||||
return owner or false
|
||||
end
|
||||
|
||||
function PLUGIN:CanEquipOrUnequip(client, item, bEquip)
|
||||
if !item.outfitCategory then
|
||||
return item.invID == client:GetCharacter():GetInventory():GetID()
|
||||
end
|
||||
|
||||
if (CLIENT) then return false end -- no more right clicking shit
|
||||
|
||||
local player = item.GetOwner and item:GetOwner() or item.player or client
|
||||
local char = IsValid(player) and player.GetCharacter and player:GetCharacter()
|
||||
|
||||
if !char then return false end
|
||||
|
||||
local inv = char:GetInventory()
|
||||
if !inv then return false end
|
||||
|
||||
local inventoryID = inv:GetID()
|
||||
if !inventoryID then return false end
|
||||
|
||||
local equipID = char:GetEquipInventory()
|
||||
if !equipID then return item.invID == inventoryID end
|
||||
if (item.invID != equipID and bEquip) then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function PLUGIN:CanTransferItem(itemTable, oldInv, inventory, x, y)
|
||||
return self:CanTransferToEquipSlots(itemTable, inventory, x, y, oldInv)
|
||||
end
|
||||
|
||||
function PLUGIN:CanMoveItemSameInv(itemTable, inventory, x, y)
|
||||
return self:CanTransferToEquipSlots(itemTable, inventory, x, y)
|
||||
end
|
||||
|
||||
function PLUGIN:Notify(client, text)
|
||||
if !client or client and !IsValid(client) then return end
|
||||
|
||||
if (!client.nextEqSlotsNotify or client.nextEqSlotsNotify < CurTime()) then
|
||||
if client.Notify then client:Notify(text) end
|
||||
|
||||
client.nextEqSlotsNotify = CurTime() + 2
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:CanTransferToEquipSlots(itemTable, inventory, x, y, oldInv)
|
||||
local owner = self:IsSameOwner(oldInv, inventory)
|
||||
local oldInvOwner = oldInv and oldInv.GetOwner and oldInv:GetOwner()
|
||||
local newInvOwner = inventory and inventory.GetOwner and inventory:GetOwner()
|
||||
|
||||
if (!inventory or inventory and inventory.GetID and inventory:GetID() == 0) and oldInv and oldInv.vars and !oldInv.vars.equipSlots then return end
|
||||
if !itemTable.outfitCategory and inventory.vars and inventory.vars.equipSlots then return false end
|
||||
if !owner and !oldInvOwner and !newInvOwner then return end
|
||||
if !owner and IsValid(newInvOwner) then owner = newInvOwner end
|
||||
if !owner and IsValid(oldInvOwner) then owner = oldInvOwner end
|
||||
|
||||
if !inventory or inventory and !inventory.vars or inventory.vars and !inventory.vars.equipSlots then
|
||||
local bSuccess, reason = hook.Run("CheckCanTransferToEquipSlots", itemTable, oldInv, inventory)
|
||||
if (bSuccess == false) then
|
||||
if (reason) then self:Notify(reason) end
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if !x or !y then return false end
|
||||
|
||||
local category = itemTable.outfitCategory
|
||||
if !category then return false end
|
||||
|
||||
if x != 1 then return false end -- inv w: 1, h: 10
|
||||
if (y != self.slots[itemTable.outfitCategory]) then return false end
|
||||
|
||||
if owner and IsValid(owner) then
|
||||
local char = owner:GetCharacter()
|
||||
local charFaction = char and char:GetFaction() or 0
|
||||
|
||||
if itemTable.outfitCategory == "model" then
|
||||
local found = false
|
||||
for _, v in pairs(inventory:GetItems()) do
|
||||
if v:GetData("equip") and v.outfitCategory != "model" and v.base != "base_maskcp" then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if found and oldInv and oldInv.vars and !oldInv.vars.equipSlots then
|
||||
self:Notify(owner, "Il faut tout déséquiper avant de pouvoir porter cette tenue !")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if self.noEquipFactions and self.noEquipFactions[charFaction] then
|
||||
self:Notify(owner, "Votre faction / la cible ne peut rien équiper !")
|
||||
return false
|
||||
end
|
||||
|
||||
if (itemTable.isGasmask and owner.HasGasmask and owner:HasGasmask() and oldInv and oldInv.vars and !oldInv.vars.equipSlots) then
|
||||
self:Notify(owner, "Vous / la cible porte déjà un masque à gaz !")
|
||||
return false
|
||||
end
|
||||
|
||||
if (itemTable.isCombineMask) then
|
||||
local character = owner:GetCharacter()
|
||||
if (!character) then return false end
|
||||
|
||||
local suit = ix.item.instances[character:GetCombineSuit()]
|
||||
if (!suit) then
|
||||
self:Notify(owner, "Vous / la cible ne portez pas de combinaison !")
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local factionList = itemTable.factionList and istable(itemTable.factionList) and itemTable.factionList or false
|
||||
if factionList and !table.HasValue(factionList, charFaction) then
|
||||
if !itemTable.isBag then
|
||||
self:Notify(owner, "Ce vêtement n'est pas destiné à votre faction / cible !")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local bSuccess, reason = hook.Run("PostCanTransferToEquipSlots", owner, itemTable, oldInv, inventory)
|
||||
if (bSuccess == false) then
|
||||
if (reason) then self:Notify(reason) end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
properties.Add("ixViewEquipInventory", {
|
||||
MenuLabel = "#View Equip Inventory",
|
||||
Order = 11,
|
||||
MenuIcon = "icon16/eye.png",
|
||||
PrependSpacer = true,
|
||||
|
||||
Filter = function(self, target, client)
|
||||
client = client or LocalPlayer()
|
||||
return target:IsPlayer()
|
||||
and CAMI.PlayerHasAccess(client, "Helix - View Inventory")
|
||||
and hook.Run("CanProperty", client, "ixViewInventory", target) != false
|
||||
end,
|
||||
|
||||
Action = function(self, target)
|
||||
self:MsgStart()
|
||||
net.WriteEntity(target)
|
||||
self:MsgEnd()
|
||||
end,
|
||||
|
||||
Receive = function(self, length, client)
|
||||
local target = net.ReadEntity()
|
||||
|
||||
if (!IsValid(target)) then return end
|
||||
if (!self:Filter(target, client)) then return end
|
||||
|
||||
PLUGIN:OpenInventory(client, target)
|
||||
end
|
||||
})
|
||||
|
||||
if (CLIENT) then -- if (CLIENT) then
|
||||
net.Receive("ixSlotsSyncPlayerToItem", function()
|
||||
local id = net.ReadUInt(32)
|
||||
if ix.item.instances[id] then
|
||||
ix.item.instances[id].player = LocalPlayer()
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("ixSyncBagSlots", function()
|
||||
if !ix.gui.inv1 or ix.gui.inv1 and !IsValid(ix.gui.inv1) then return end
|
||||
if !ix.gui.inv1.UpdateNoSlots then return end
|
||||
ix.gui.inv1:UpdateNoSlots()
|
||||
end)
|
||||
|
||||
net.Receive("ixOnBagItemTransferred", function()
|
||||
local itemID = net.ReadUInt(32)
|
||||
local inventoryID = net.ReadUInt(32)
|
||||
|
||||
local item = ix.item.instances[itemID]
|
||||
if !item then return end
|
||||
|
||||
local inventory = ix.item.inventories[inventoryID]
|
||||
if !inventory then return end
|
||||
|
||||
PLUGIN:OnBagItemTransferred(item, false, inventory)
|
||||
end)
|
||||
|
||||
function PLUGIN:OnBagItemTransferred(item, _, inventory)
|
||||
if !inventory.vars then return end
|
||||
if !ix.gui.inv1 or ix.gui.inv1 and !IsValid(ix.gui.inv1) then return false end
|
||||
if ix.gui.openedStorage and IsValid(ix.gui.openedStorage) then return false end
|
||||
|
||||
if inventory.vars.equipSlots then
|
||||
local itemFunctions = item.functions
|
||||
if !itemFunctions or itemFunctions and !itemFunctions.View then return end
|
||||
|
||||
if itemFunctions.View then
|
||||
local itemEnt = IsValid(item.entity)
|
||||
local id = item:GetData("id")
|
||||
local alreadyOpen = IsValid(ix.gui["inv" .. id])
|
||||
if id and !alreadyOpen and !itemEnt then
|
||||
itemFunctions.View.OnClick(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("PostCharInfoFrameOpened", "ixEquipInventoryOpen", function(charFrame)
|
||||
if !IsValid(charFrame) then return end
|
||||
local char = LocalPlayer():GetCharacter()
|
||||
if !char then return end
|
||||
|
||||
local equipInvID = char:GetEquipInventory()
|
||||
if !equipInvID then return end
|
||||
|
||||
local inventory = ix.item.inventories[equipInvID]
|
||||
if !inventory then return end
|
||||
|
||||
ix.gui.equipSlots = charFrame:Add("ixEquipSlots")
|
||||
ix.gui.equipSlots:SetInventory(inventory)
|
||||
ix.gui.equipSlots:PaintParts()
|
||||
|
||||
ix.gui["inv" .. equipInvID] = ix.gui.equipSlots
|
||||
end)
|
||||
end
|
||||
278
gamemodes/helix/plugins/inventoryslots/sv_plugin.lua
Normal file
278
gamemodes/helix/plugins/inventoryslots/sv_plugin.lua
Normal file
@@ -0,0 +1,278 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
util.AddNetworkString("ixOnBagItemTransferred")
|
||||
util.AddNetworkString("ixSlotsSyncPlayerToItem")
|
||||
util.AddNetworkString("ixSyncBagSlots")
|
||||
util.AddNetworkString("ixSwitchPlayerInv")
|
||||
|
||||
function PLUGIN:OpenInventory(client, target, bShouldNotLog)
|
||||
if (!IsValid(client) or !IsValid(target)) then return end
|
||||
if (!target:IsPlayer()) then return end
|
||||
|
||||
local character = target:GetCharacter()
|
||||
if (!character) then return end
|
||||
|
||||
local equipInvID = character.GetEquipInventory and character:GetEquipInventory()
|
||||
local equipInv = ix.item.inventories[equipInvID] or false
|
||||
|
||||
local localChar = client.GetCharacter and client:GetCharacter()
|
||||
local localPlayer = localChar.GetPlayer and localChar:GetPlayer()
|
||||
|
||||
if (equipInv) then
|
||||
local name = target:Name().." : équiper l'inventaire"
|
||||
|
||||
ix.storage.Open(client, equipInv, {
|
||||
entity = target,
|
||||
name = name,
|
||||
OnPlayerClose = function()
|
||||
if (!bShouldNotLog) then
|
||||
ix.log.Add(client, "bastionInvClose", name)
|
||||
else
|
||||
if (localChar) then
|
||||
if equipInv.owner and equipInv.owner == localChar:GetID() then
|
||||
if localPlayer and IsValid(localPlayer) then
|
||||
equipInv:AddReceiver(localPlayer)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
if (localChar) then
|
||||
localChar:GetInventory():AddReceiver(client)
|
||||
end
|
||||
|
||||
if (!bShouldNotLog) then
|
||||
ix.log.Add(client, "bastionInvSearch", name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:CharacterReceiveEqInv(client, character)
|
||||
local equipInvID = character:GetEquipInventory()
|
||||
local equipInv = ix.item.inventories[equipInvID]
|
||||
if !equipInv then return end
|
||||
|
||||
assert(IsValid(client) and client:IsPlayer(), "expected valid player")
|
||||
assert(type(equipInv) == "table" and equipInv:IsInstanceOf(ix.meta.inventory), "expected valid inventory")
|
||||
|
||||
equipInv:AddReceiver(client)
|
||||
equipInv:Sync(client)
|
||||
end
|
||||
|
||||
function PLUGIN:CharacterLoaded(character)
|
||||
local client = character:GetPlayer()
|
||||
if (character:GetEquipInventory() == 0) then
|
||||
ix.inventory.New(character:GetID(), "equipInventory", function(inventory)
|
||||
inventory.vars.isEquipSlots = true
|
||||
inventory.vars.equipSlots = self.slots
|
||||
|
||||
inventory:SetOwner(character:GetID())
|
||||
character:SetEquipInventory(inventory:GetID())
|
||||
|
||||
self:CharacterReceiveEqInv(client, character)
|
||||
end)
|
||||
else
|
||||
self:CharacterReceiveEqInv(client, character)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerLoadedCharacter(client, character)
|
||||
local equipInv = character.GetEquipInventory and character:GetEquipInventory()
|
||||
local invItems = character:GetInventory():GetItems()
|
||||
|
||||
if !equipInv then return end
|
||||
if !isnumber(equipInv) then return end
|
||||
if equipInv <= 0 then return end
|
||||
|
||||
if (character:GetData("equipBgClothes")) then
|
||||
character:SetData("equipBgClothes", nil)
|
||||
|
||||
for i = 1, 2 do
|
||||
for _, itemTable in pairs(invItems) do
|
||||
if !itemTable.outfitCategory then continue end
|
||||
if itemTable.isBag then continue end
|
||||
if itemTable.base == "base_maskcp" and i == 1 then continue end
|
||||
if itemTable.base != "base_maskcp" and i == 2 then continue end
|
||||
|
||||
if ix.item.inventories[equipInv] then
|
||||
local bSuccess, _ = itemTable:Transfer(equipInv, 1, self.slots[itemTable.outfitCategory])
|
||||
if (bSuccess) then
|
||||
itemTable.functions.Equip.OnRun(itemTable, client)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:ShouldRestoreInventory(charID, invID, invType)
|
||||
if invType != "equipInventory" then return end
|
||||
if !invID then return end
|
||||
invID = tonumber(invID)
|
||||
|
||||
ix.inventory.Restore(invID, self.slotsW, self.slotsH, function(inventory)
|
||||
inventory.vars.isEquipSlots = true
|
||||
inventory.vars.equipSlots = self.slots
|
||||
|
||||
inventory:SetOwner(charID)
|
||||
end)
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function PLUGIN:SyncAlreadyEquipped(owner)
|
||||
if !owner or owner and !IsValid(owner) then return end
|
||||
|
||||
local character = owner.GetCharacter and owner:GetCharacter()
|
||||
if !character then return end
|
||||
|
||||
local inventory = character.GetInventory and character:GetInventory()
|
||||
if !inventory then return end
|
||||
|
||||
for _, v in pairs (inventory:GetItems()) do
|
||||
if v.outfitCategory and v:GetData("equip", false) then
|
||||
local eqInv = v.invID and ix.item.inventories[v.invID]
|
||||
if eqInv and eqInv.vars and eqInv.vars.isEquipSlots then
|
||||
local itemFunctions = v.functions
|
||||
if !itemFunctions or itemFunctions and !itemFunctions.Equip then return end
|
||||
|
||||
itemFunctions.Equip.OnRun(v, owner)
|
||||
|
||||
if v.postHooks.Equip then
|
||||
v.postHooks.Equip(v, owner)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:InventoryItemAdded(oldInv, inventory, newItem)
|
||||
local owner = self:IsSameOwner(oldInv, inventory)
|
||||
local oldInvOwner = oldInv and oldInv.GetOwner and oldInv:GetOwner()
|
||||
local newInvOwner = inventory and inventory.GetOwner and inventory:GetOwner()
|
||||
|
||||
if !owner and !oldInvOwner and !newInvOwner then return end
|
||||
|
||||
if !inventory.vars then return end
|
||||
if !inventory.vars.equipSlots then
|
||||
if oldInv and oldInv.vars and oldInv.vars.equipSlots then
|
||||
local itemFunctions = newItem.functions
|
||||
if !itemFunctions or itemFunctions and !itemFunctions.EquipUn then return end
|
||||
|
||||
if !owner and IsValid(oldInvOwner) then owner = oldInvOwner end
|
||||
if !owner then return end
|
||||
|
||||
if itemFunctions.EquipUn.OnCanRun and itemFunctions.EquipUn.OnCanRun(newItem, owner) then
|
||||
itemFunctions.EquipUn.OnRun(newItem, owner)
|
||||
|
||||
if newItem.postHooks.EquipUn then
|
||||
newItem.postHooks.EquipUn(newItem, owner)
|
||||
end
|
||||
|
||||
if newItem.outfitCategory == "model" then
|
||||
self:SyncAlreadyEquipped(owner)
|
||||
end
|
||||
|
||||
if (inventory) then
|
||||
inventory:Sync(owner)
|
||||
end
|
||||
|
||||
net.Start("ixSyncBagSlots")
|
||||
net.Send(owner)
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if !owner and IsValid(newInvOwner) then owner = newInvOwner end
|
||||
if !owner then return end
|
||||
|
||||
local itemFunctions = newItem.functions
|
||||
if !itemFunctions or itemFunctions and !itemFunctions.Equip then return end
|
||||
|
||||
if itemFunctions.Equip.OnCanRun and itemFunctions.Equip.OnCanRun(newItem, owner) then
|
||||
itemFunctions.Equip.OnRun(newItem, owner)
|
||||
if oldInvOwner and IsValid(oldInvOwner) then
|
||||
inventory:Sync(oldInvOwner)
|
||||
end
|
||||
|
||||
if newItem.postHooks.Equip then
|
||||
newItem.postHooks.Equip(newItem, owner)
|
||||
end
|
||||
|
||||
net.Start("ixSyncBagSlots")
|
||||
net.Send(owner)
|
||||
end
|
||||
|
||||
net.Start("ixSlotsSyncPlayerToItem")
|
||||
net.WriteUInt(newItem.id, 32)
|
||||
net.Send(owner)
|
||||
end
|
||||
|
||||
function PLUGIN:OnBagItemTransferred(item, curInv, inventory)
|
||||
local owner = self:IsSameOwner(curInv, inventory)
|
||||
if !owner then return end
|
||||
|
||||
net.Start("ixOnBagItemTransferred")
|
||||
net.WriteUInt(tonumber(item.id), 32)
|
||||
net.WriteUInt(tonumber(inventory.id), 32)
|
||||
net.Send(owner)
|
||||
|
||||
net.Start("ixSyncBagSlots")
|
||||
net.Send(owner)
|
||||
end
|
||||
|
||||
function PLUGIN:OnStorageReceiverRemoved(client, inventory)
|
||||
if !client or client and !IsValid(client) then return end
|
||||
|
||||
local switchingInv = client.switchingPlayerInv
|
||||
if !switchingInv then return end
|
||||
|
||||
local owner = switchingInv and tonumber(switchingInv.owner)
|
||||
if !owner then return end
|
||||
|
||||
local char = ix.char.loaded[owner]
|
||||
if !char then return end
|
||||
|
||||
local faction = char.GetFaction and char:GetFaction()
|
||||
|
||||
if faction and self.noEquipFactions and self.noEquipFactions[char:GetFaction()] then
|
||||
client:Notify("Ce personnage n'a pas d'emplacements d'équipement !")
|
||||
return false
|
||||
end
|
||||
|
||||
local target = char.GetPlayer and char:GetPlayer()
|
||||
if !target or target and !IsValid(target) then return end
|
||||
|
||||
if !switchingInv.eqSlots then
|
||||
self:OpenInventory(client, target, true)
|
||||
else
|
||||
Schema:SearchPlayer(client, target)
|
||||
end
|
||||
|
||||
client.switchingPlayerInv = nil
|
||||
end
|
||||
|
||||
net.Receive("ixSwitchPlayerInv", function(length, client)
|
||||
local inventory = client.ixOpenStorage
|
||||
if !inventory then return end
|
||||
|
||||
local isEquipSlots = inventory.vars and inventory.vars.isEquipSlots or false
|
||||
client.switchingPlayerInv = {eqSlots = isEquipSlots, owner = inventory.owner}
|
||||
|
||||
ix.storage.RemoveReceiver(client, inventory)
|
||||
end)
|
||||
Reference in New Issue
Block a user