mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 21:53:46 +03:00
Upload
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
ENT.Type = "anim"
|
||||
ENT.PrintName = "Container"
|
||||
ENT.Category = "Helix"
|
||||
ENT.Spawnable = false
|
||||
ENT.bNoPersist = true
|
||||
|
||||
function ENT:SetupDataTables()
|
||||
self:NetworkVar("Int", 0, "ID")
|
||||
self:NetworkVar("Bool", 0, "Locked")
|
||||
self:NetworkVar("String", 0, "DisplayName")
|
||||
self:NetworkVar("String", 1, "Password")
|
||||
end
|
||||
|
||||
if (SERVER) then
|
||||
function ENT:Initialize()
|
||||
self:PhysicsInit(SOLID_VPHYSICS)
|
||||
self:SetSolid(SOLID_VPHYSICS)
|
||||
self:SetUseType(SIMPLE_USE)
|
||||
self.receivers = {}
|
||||
|
||||
local definition = ix.container.stored[self:GetModel():lower()]
|
||||
|
||||
if (definition) then
|
||||
self:SetDisplayName(definition.name)
|
||||
end
|
||||
|
||||
local physObj = self:GetPhysicsObject()
|
||||
|
||||
if (IsValid(physObj)) then
|
||||
physObj:EnableMotion(true)
|
||||
physObj:Wake()
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:SetInventory(inventory)
|
||||
if (inventory) then
|
||||
self:SetID(inventory:GetID())
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:SetMoney(amount)
|
||||
self.money = math.max(0, math.Round(tonumber(amount) or 0))
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(self)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:GetMoney()
|
||||
return self.money or 0
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
local index = self:GetID()
|
||||
|
||||
if (!ix.shuttingDown and !self.ixIsSafe and ix.entityDataLoaded and index) then
|
||||
local inventory = index != 0 and ix.item.inventories[index]
|
||||
|
||||
if (inventory) then
|
||||
ix.item.inventories[index] = nil
|
||||
|
||||
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()
|
||||
|
||||
hook.Run("ContainerRemoved", self, inventory)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:OpenInventory(activator)
|
||||
local inventory = self:GetInventory()
|
||||
|
||||
if (inventory) then
|
||||
local name = self:GetDisplayName()
|
||||
|
||||
ix.storage.Open(activator, inventory, {
|
||||
name = name,
|
||||
entity = self,
|
||||
bMultipleUsers = true,
|
||||
searchTime = ix.config.Get("containerOpenTime", 0.7),
|
||||
data = {money = self:GetMoney()},
|
||||
OnPlayerClose = function()
|
||||
ix.log.Add(activator, "closeContainer", name, inventory:GetID())
|
||||
end
|
||||
})
|
||||
|
||||
ix.log.Add(activator, "openContainer", name, inventory:GetID())
|
||||
|
||||
if (ix.plugin.list.willardcontainers and ix.config.Get("notifyOldcontainer") and self:GetClass() == "ix_container") then
|
||||
activator:ChatNotifyLocalized("containerUseOld")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:Use(activator)
|
||||
local inventory = self:GetInventory()
|
||||
|
||||
if (inventory and (activator.ixNextOpen or 0) < CurTime()) then
|
||||
local character = activator:GetCharacter()
|
||||
|
||||
if (character) then
|
||||
local def = ix.container.stored[self:GetModel():lower()]
|
||||
|
||||
if (self:GetLocked() and !self.Sessions[character:GetID()] and !self:GetNetVar("isOneWay", false)) then
|
||||
self:EmitSound(def.locksound or "doors/default_locked.wav")
|
||||
|
||||
if (!self.keypad) then
|
||||
net.Start("ixContainerPassword")
|
||||
net.WriteEntity(self)
|
||||
net.Send(activator)
|
||||
end
|
||||
else
|
||||
self:OpenInventory(activator)
|
||||
end
|
||||
end
|
||||
|
||||
activator.ixNextOpen = CurTime() + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
ENT.PopulateEntityInfo = true
|
||||
|
||||
local COLOR_LOCKED = Color(200, 38, 19, 200)
|
||||
local COLOR_UNLOCKED = Color(135, 211, 124, 200)
|
||||
|
||||
function ENT:OnPopulateEntityInfo(tooltip)
|
||||
local definition = ix.container.stored[self:GetModel():lower()]
|
||||
local bLocked = self:GetLocked()
|
||||
|
||||
surface.SetFont("ixIconsSmall")
|
||||
|
||||
local iconText = bLocked and "P" or "Q"
|
||||
local iconWidth, iconHeight = surface.GetTextSize(iconText)
|
||||
|
||||
-- minimal tooltips have centered text so we'll draw the icon above the name instead
|
||||
if (tooltip:IsMinimal()) then
|
||||
local icon = tooltip:AddRow("icon")
|
||||
icon:SetFont("ixIconsSmall")
|
||||
icon:SetTextColor(bLocked and COLOR_LOCKED or COLOR_UNLOCKED)
|
||||
icon:SetText(iconText)
|
||||
icon:SizeToContents()
|
||||
end
|
||||
|
||||
local title = tooltip:AddRow("name")
|
||||
title:SetImportant()
|
||||
title:SetText(self:GetDisplayName())
|
||||
title:SetBackgroundColor(ix.config.Get("color"))
|
||||
title:SetTextInset(iconWidth + 8, 0)
|
||||
title:SizeToContents()
|
||||
|
||||
if (!tooltip:IsMinimal()) then
|
||||
title.Paint = function(panel, width, height)
|
||||
panel:PaintBackground(width, height)
|
||||
|
||||
surface.SetFont("ixIconsSmall")
|
||||
surface.SetTextColor(bLocked and COLOR_LOCKED or COLOR_UNLOCKED)
|
||||
surface.SetTextPos(4, height * 0.5 - iconHeight * 0.5)
|
||||
surface.DrawText(iconText)
|
||||
end
|
||||
end
|
||||
|
||||
local description = tooltip:AddRow("description")
|
||||
description:SetText(definition.description)
|
||||
description:SizeToContents()
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:GetInventory()
|
||||
return ix.item.inventories[self:GetID()]
|
||||
end
|
||||
136
gamemodes/helix/plugins/containers/sh_definitions.lua
Normal file
136
gamemodes/helix/plugins/containers/sh_definitions.lua
Normal file
@@ -0,0 +1,136 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
ix.container.Register(model, {
|
||||
name = "Crate",
|
||||
description = "A simple wooden create.",
|
||||
width = 4,
|
||||
height = 4,
|
||||
locksound = "",
|
||||
opensound = ""
|
||||
})
|
||||
]]--
|
||||
|
||||
ix.container.Register("models/props_junk/wood_crate001a.mdl", {
|
||||
name = "Crate",
|
||||
description = "A simple wooden crate.",
|
||||
width = 4,
|
||||
height = 4,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_c17/lockers001a.mdl", {
|
||||
name = "Locker",
|
||||
description = "A white locker.",
|
||||
width = 3,
|
||||
height = 5,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_wasteland/controlroom_storagecloset001a.mdl", {
|
||||
name = "Metal Cabinet",
|
||||
description = "A green metal cabinet.",
|
||||
width = 4,
|
||||
height = 5,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_wasteland/controlroom_storagecloset001b.mdl", {
|
||||
name = "Metal Cabinet",
|
||||
description = "A green metal cabinet.",
|
||||
width = 4,
|
||||
height = 5,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_wasteland/controlroom_filecabinet001a.mdl", {
|
||||
name = "File Cabinet",
|
||||
description = "A metal filing cabinet.",
|
||||
width = 5,
|
||||
height = 3
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_wasteland/controlroom_filecabinet002a.mdl", {
|
||||
name = "File Cabinet",
|
||||
description = "A metal filing cabinet.",
|
||||
width = 3,
|
||||
height = 6,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_lab/filecabinet02.mdl", {
|
||||
name = "File Cabinet",
|
||||
description = "A metal filing cabinet.",
|
||||
width = 5,
|
||||
height = 3
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_c17/furniturefridge001a.mdl", {
|
||||
name = "Refrigerator",
|
||||
description = "A metal box for keeping food in.",
|
||||
width = 2,
|
||||
height = 3,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_wasteland/kitchen_fridge001a.mdl", {
|
||||
name = "Large Refrigerator",
|
||||
description = "A large metal box for storing even more food in.",
|
||||
width = 4,
|
||||
height = 5,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_junk/trashbin01a.mdl", {
|
||||
name = "Trash Bin",
|
||||
description = "What do you expect to find in here?",
|
||||
width = 2,
|
||||
height = 2,
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_junk/trashdumpster01a.mdl", {
|
||||
name = "Dumpster",
|
||||
description = "A dumpster meant to stow away trash. It emanates an unpleasant smell.",
|
||||
width = 6,
|
||||
height = 3
|
||||
})
|
||||
|
||||
ix.container.Register("models/items/ammocrate_smg1.mdl", {
|
||||
name = "Ammo Crate",
|
||||
description = "A heavy crate that stores ammo.",
|
||||
width = 5,
|
||||
height = 3,
|
||||
OnOpen = function(entity, activator)
|
||||
local closeSeq = entity:LookupSequence("Close")
|
||||
entity:ResetSequence(closeSeq)
|
||||
|
||||
timer.Simple(2, function()
|
||||
if (entity and IsValid(entity)) then
|
||||
local openSeq = entity:LookupSequence("Open")
|
||||
entity:ResetSequence(openSeq)
|
||||
end
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_forest/footlocker01_closed.mdl", {
|
||||
name = "Footlocker",
|
||||
description = "A small chest to store belongings in.",
|
||||
width = 5,
|
||||
height = 3
|
||||
})
|
||||
|
||||
ix.container.Register("models/Items/item_item_crate.mdl", {
|
||||
name = "Item Crate",
|
||||
description = "A crate to store some belongings in.",
|
||||
width = 5,
|
||||
height = 3
|
||||
})
|
||||
|
||||
ix.container.Register("models/props_c17/cashregister01a.mdl", {
|
||||
name = "Cash Register",
|
||||
description = "A register with some buttons and a drawer.",
|
||||
width = 2,
|
||||
height = 1
|
||||
})
|
||||
487
gamemodes/helix/plugins/containers/sh_plugin.lua
Normal file
487
gamemodes/helix/plugins/containers/sh_plugin.lua
Normal file
@@ -0,0 +1,487 @@
|
||||
--[[
|
||||
| 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
|
||||
|
||||
PLUGIN.name = "Containers"
|
||||
PLUGIN.author = "Chessnut"
|
||||
PLUGIN.description = "Provides the ability to store items."
|
||||
|
||||
ix.container = ix.container or {}
|
||||
ix.container.stored = ix.container.stored or {}
|
||||
|
||||
ix.config.Add("containerSave", true, "Whether or not containers will save after a server restart.", nil, {
|
||||
category = "Containers"
|
||||
})
|
||||
|
||||
ix.config.Add("containerOpenTime", 0.7, "How long it takes to open a container.", nil, {
|
||||
data = {min = 0, max = 50},
|
||||
category = "Containers"
|
||||
})
|
||||
|
||||
function ix.container.Register(model, data)
|
||||
ix.container.stored[model:lower()] = data
|
||||
end
|
||||
|
||||
ix.util.Include("sh_definitions.lua")
|
||||
|
||||
if (SERVER) then
|
||||
util.AddNetworkString("ixContainerPassword")
|
||||
|
||||
function PLUGIN:PlayerSpawnedProp(client, model, entity)
|
||||
model = tostring(model):lower()
|
||||
local data = ix.container.stored[model:lower()]
|
||||
|
||||
if (data) then
|
||||
if (hook.Run("CanPlayerSpawnContainer", client, model, entity) == false) then return end
|
||||
|
||||
local container = ents.Create("ix_container")
|
||||
container:SetPos(entity:GetPos())
|
||||
container:SetAngles(entity:GetAngles())
|
||||
container:SetModel(model)
|
||||
container:Spawn()
|
||||
|
||||
ix.inventory.New(0, "container:" .. model:lower(), function(inventory)
|
||||
-- we'll technically call this a bag since we don't want other bags to go inside
|
||||
inventory.vars.isBag = true
|
||||
inventory.vars.isContainer = true
|
||||
|
||||
if (IsValid(container)) then
|
||||
container:SetInventory(inventory)
|
||||
self:SaveContainer()
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(container)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
entity:Remove()
|
||||
|
||||
hook.Run("PlayerSpawnedContainer", client, container)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:RegisterSaveEnts()
|
||||
ix.saveEnts:RegisterEntity("ix_container", true, true, true, {
|
||||
OnSave = function(entity, data) --OnSave
|
||||
data.motion = false
|
||||
local inventory = entity:GetInventory()
|
||||
local lockentity = entity:GetChildren()[1]
|
||||
data.invID = inventory:GetID()
|
||||
data.model = entity:GetModel()
|
||||
data.pass = entity.password
|
||||
data.name = entity:GetDisplayName()
|
||||
data.money = entity:GetMoney()
|
||||
data.lockpos = lockentity and lockentity:GetPos()
|
||||
data.lockangs = lockentity and lockentity:GetAngles()
|
||||
data.lockowner = lockentity and lockentity:GetNetVar("owner")
|
||||
data.group = entity.group
|
||||
data.oneway = entity:GetNetVar("isOneWay", false)
|
||||
end,
|
||||
OnRestore = function(entity, data) --OnRestore
|
||||
local data2 = ix.container.stored[data.model:lower()] -- Model name
|
||||
if (data2) then
|
||||
local inventoryID = tonumber(data.invID) -- invID
|
||||
|
||||
if (!inventoryID or inventoryID < 1) then
|
||||
ErrorNoHalt(string.format(
|
||||
"[Helix] Attempted to restore container inventory with invalid inventory ID '%s' (%s, %s)\n",
|
||||
tostring(inventoryID), data.name or "no name", data.model or "no model"))
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
entity:SetModel(data.model) -- Model name
|
||||
entity:SetSolid(SOLID_VPHYSICS)
|
||||
entity:PhysicsInit(SOLID_VPHYSICS)
|
||||
|
||||
|
||||
|
||||
if (data.pass) then -- Password
|
||||
entity.password = data.pass
|
||||
entity:SetLocked(true)
|
||||
entity:SetPassword(data.pass)
|
||||
entity.Sessions = {}
|
||||
end
|
||||
|
||||
if (data.name) then -- Display name
|
||||
entity:SetDisplayName(data.name)
|
||||
end
|
||||
|
||||
if (data.money) then -- Money
|
||||
entity:SetMoney(data.money)
|
||||
end
|
||||
|
||||
if (data.lockpos) then -- Lock Pos
|
||||
local lockentity = ents.Create("ix_containerlock")
|
||||
lockentity:SetPos(data.lockpos) -- Lock Pos
|
||||
lockentity:SetAngles(data.lockangs) -- Lock Angles
|
||||
lockentity:SetParent(entity)
|
||||
lockentity:SetNetVar("owner", data.lockowner) -- Lock Owner
|
||||
lockentity:Spawn()
|
||||
end
|
||||
|
||||
if (data.group) then
|
||||
entity.group = data.group -- Group
|
||||
end
|
||||
|
||||
entity:SetNetVar("isOneWay", data.oneway)
|
||||
|
||||
ix.inventory.Restore(inventoryID, data2.width, data2.height, function(inventory)
|
||||
inventory.vars.isBag = true
|
||||
inventory.vars.isContainer = true
|
||||
|
||||
if (IsValid(entity)) then
|
||||
entity:SetInventory(inventory)
|
||||
end
|
||||
end)
|
||||
|
||||
local physObject = entity:GetPhysicsObject()
|
||||
if (IsValid(physObject)) then
|
||||
physObject:EnableMotion()
|
||||
end
|
||||
end
|
||||
end,
|
||||
ShouldSave = function(entity)
|
||||
local inventory = entity:GetInventory()
|
||||
return entity:GetModel() != "models/error.mdl" and inventory:GetID() != 0 //avoid bad save that somehow happened
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function PLUGIN:CanSaveContainer(entity, inventory)
|
||||
return ix.config.Get("containerSave", true)
|
||||
end
|
||||
|
||||
function PLUGIN:SaveContainer()
|
||||
local data = {}
|
||||
|
||||
for _, v in ipairs(ents.FindByClass("ix_container")) do
|
||||
if (hook.Run("CanSaveContainer", v, v:GetInventory()) != false) then
|
||||
local inventory = v:GetInventory()
|
||||
if (!inventory) then continue end
|
||||
|
||||
local lockentity = v:GetChildren()[1]
|
||||
|
||||
data[#data + 1] = {
|
||||
v:GetPos(),
|
||||
v:GetAngles(),
|
||||
inventory:GetID(),
|
||||
v:GetModel(),
|
||||
v.password,
|
||||
v:GetDisplayName(),
|
||||
v:GetMoney(),
|
||||
lockentity and lockentity:GetPos(),
|
||||
lockentity and lockentity:GetAngles(),
|
||||
lockentity and lockentity:GetNetVar("owner"),
|
||||
v.group,
|
||||
v:GetNetVar("isOneWay", false)
|
||||
}
|
||||
else
|
||||
local index = v:GetID()
|
||||
|
||||
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
|
||||
|
||||
self:SetData(data)
|
||||
end
|
||||
|
||||
function PLUGIN:SaveData()
|
||||
if (!ix.shuttingDown) then
|
||||
self:SaveContainer()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:ContainerRemoved(entity, inventory)
|
||||
self:SaveContainer()
|
||||
end
|
||||
|
||||
function PLUGIN:LoadData()
|
||||
if (ix.saveEnts and !ix.config.Get("SaveEntsOldLoadingEnabled")) then return end
|
||||
local data = self:GetData()
|
||||
|
||||
if (data) then
|
||||
for _, v in ipairs(data) do
|
||||
if (!v[4]) then continue end -- Model name
|
||||
|
||||
local data2 = ix.container.stored[v[4]:lower()] -- Model name
|
||||
|
||||
if (data2) then
|
||||
local inventoryID = tonumber(v[3]) -- invID
|
||||
|
||||
if (!inventoryID or inventoryID < 1) then
|
||||
ErrorNoHalt(string.format(
|
||||
"[Helix] Attempted to restore container inventory with invalid inventory ID '%s' (%s, %s)\n",
|
||||
tostring(inventoryID), v[6] or "no name", v[4] or "no model"))
|
||||
|
||||
continue
|
||||
end
|
||||
|
||||
local entity = ents.Create("ix_container")
|
||||
entity:SetPos(v[1]) -- Pos
|
||||
entity:SetAngles(v[2]) -- Angles
|
||||
entity:Spawn()
|
||||
entity:SetModel(v[4]) -- Model name
|
||||
entity:SetSolid(SOLID_VPHYSICS)
|
||||
entity:PhysicsInit(SOLID_VPHYSICS)
|
||||
|
||||
if (v[5]) then -- Password
|
||||
entity.password = v[5]
|
||||
entity:SetLocked(true)
|
||||
entity:SetPassword(v[5])
|
||||
entity.Sessions = {}
|
||||
end
|
||||
|
||||
if (v[6]) then -- Display name
|
||||
entity:SetDisplayName(v[6])
|
||||
end
|
||||
|
||||
if (v[7]) then -- Money
|
||||
entity:SetMoney(v[7])
|
||||
end
|
||||
|
||||
if (v[8]) then -- Lock Pos
|
||||
local lockentity = ents.Create("ix_containerlock")
|
||||
lockentity:SetPos(v[8]) -- Lock Pos
|
||||
lockentity:SetAngles(v[9]) -- Lock Angles
|
||||
lockentity:SetParent(entity)
|
||||
lockentity:SetNetVar("owner", v[10]) -- Lock Owner
|
||||
lockentity:Spawn()
|
||||
end
|
||||
|
||||
if (v[11]) then
|
||||
entity.group = v[11] -- Group
|
||||
end
|
||||
|
||||
entity:SetNetVar("isOneWay", v[12])
|
||||
|
||||
ix.inventory.Restore(inventoryID, data2.width, data2.height, function(inventory)
|
||||
inventory.vars.isBag = true
|
||||
inventory.vars.isContainer = true
|
||||
|
||||
if (IsValid(entity)) then
|
||||
entity:SetInventory(inventory)
|
||||
end
|
||||
end)
|
||||
|
||||
local physObject = entity:GetPhysicsObject()
|
||||
|
||||
if (IsValid(physObject)) then
|
||||
physObject:EnableMotion()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
net.Receive("ixContainerPassword", function(length, client)
|
||||
if ((client.ixNextContainerPassword or 0) > RealTime()) then
|
||||
return
|
||||
end
|
||||
|
||||
local entity = net.ReadEntity()
|
||||
local password = net.ReadString()
|
||||
local dist = entity:GetPos():DistToSqr(client:GetPos())
|
||||
|
||||
if (dist < 16384 and password) then
|
||||
if (entity.password and entity.password == password) then
|
||||
if (!entity:GetNetVar("isOneWay", false)) then
|
||||
entity:OpenInventory(client)
|
||||
end
|
||||
entity.Sessions[client:GetCharacter():GetID()] = true
|
||||
else
|
||||
client:NotifyLocalized("wrongPassword")
|
||||
end
|
||||
end
|
||||
|
||||
client.ixNextContainerPassword = RealTime() + 0.5
|
||||
end)
|
||||
|
||||
ix.log.AddType("containerPassword", function(client, ...)
|
||||
local arg = {...}
|
||||
return string.format("%s has %s the password for '%s'.", client:Name(), arg[3] and "set" or "removed", arg[1], arg[2])
|
||||
end)
|
||||
|
||||
ix.log.AddType("containerName", function(client, ...)
|
||||
local arg = {...}
|
||||
|
||||
if (arg[3]) then
|
||||
return string.format("%s has set container %d name to '%s'.", client:Name(), arg[2], arg[1])
|
||||
else
|
||||
return string.format("%s has removed container %d name.", client:Name(), arg[2])
|
||||
end
|
||||
end)
|
||||
|
||||
ix.log.AddType("openContainer", function(client, ...)
|
||||
local arg = {...}
|
||||
return string.format("%s opened the '%s' #%d container.", client:Name(), arg[1], arg[2])
|
||||
end, FLAG_NORMAL)
|
||||
|
||||
ix.log.AddType("closeContainer", function(client, ...)
|
||||
local name
|
||||
if !client or client and !IsValid(client) or IsValid(client) and !client.Name then
|
||||
name = "N/A"
|
||||
else
|
||||
name = client.Name and client:Name()
|
||||
end
|
||||
|
||||
local arg = {...}
|
||||
return string.format("%s closed the '%s' #%d container.", name, arg[1], arg[2])
|
||||
end, FLAG_NORMAL)
|
||||
else
|
||||
net.Receive("ixContainerPassword", function(length)
|
||||
local entity = net.ReadEntity()
|
||||
|
||||
Derma_StringRequest(
|
||||
L("containerPasswordWrite"),
|
||||
L("containerPasswordWrite"),
|
||||
"",
|
||||
function(val)
|
||||
net.Start("ixContainerPassword")
|
||||
net.WriteEntity(entity)
|
||||
net.WriteString(val)
|
||||
net.SendToServer()
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
function PLUGIN:InitializedPlugins()
|
||||
for k, v in pairs(ix.container.stored) do
|
||||
if (v.name and v.width and v.height) then
|
||||
ix.inventory.Register("container:" .. k:lower(), v.width, v.height)
|
||||
else
|
||||
ErrorNoHalt("[Helix] Container for '"..k.."' is missing all inventory information!\n")
|
||||
ix.container.stored[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- properties
|
||||
properties.Add("container_setpassword", {
|
||||
MenuLabel = "Set Password",
|
||||
Order = 400,
|
||||
MenuIcon = "icon16/lock_edit.png",
|
||||
|
||||
Filter = function(self, entity, client)
|
||||
if (entity:GetClass() != "ix_container") then return false end
|
||||
if (!gamemode.Call("CanProperty", client, "container_setpassword", entity)) then return false end
|
||||
|
||||
return true
|
||||
end,
|
||||
|
||||
Action = function(self, entity)
|
||||
Derma_StringRequest(L("containerPasswordWrite"), "", "", function(text)
|
||||
self:MsgStart()
|
||||
net.WriteEntity(entity)
|
||||
net.WriteString(text)
|
||||
self:MsgEnd()
|
||||
end)
|
||||
end,
|
||||
|
||||
Receive = function(self, length, client)
|
||||
local entity = net.ReadEntity()
|
||||
|
||||
if (!IsValid(entity)) then return end
|
||||
if (!self:Filter(entity, client)) then return end
|
||||
|
||||
local password = net.ReadString()
|
||||
|
||||
entity.Sessions = {}
|
||||
|
||||
if (password:len() != 0) then
|
||||
entity:SetLocked(true)
|
||||
entity:SetPassword(password)
|
||||
entity.password = password
|
||||
|
||||
client:NotifyLocalized("containerPassword", password)
|
||||
else
|
||||
entity:SetLocked(false)
|
||||
entity:SetPassword(nil)
|
||||
entity.password = nil
|
||||
|
||||
client:NotifyLocalized("containerPasswordRemove")
|
||||
end
|
||||
|
||||
local name = entity:GetDisplayName()
|
||||
local inventory = entity:GetInventory()
|
||||
|
||||
local definition = ix.container.stored[entity:GetModel():lower()]
|
||||
|
||||
if (definition) then
|
||||
entity:SetDisplayName(definition.name)
|
||||
end
|
||||
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(self)
|
||||
end
|
||||
|
||||
ix.log.Add(client, "containerPassword", name, inventory:GetID(), password:len() != 0)
|
||||
end
|
||||
})
|
||||
|
||||
properties.Add("container_setname", {
|
||||
MenuLabel = "Set Name",
|
||||
Order = 400,
|
||||
MenuIcon = "icon16/tag_blue_edit.png",
|
||||
|
||||
Filter = function(self, entity, client)
|
||||
if (entity:GetClass() != "ix_container") then return false end
|
||||
if (!gamemode.Call("CanProperty", client, "container_setname", entity)) then return false end
|
||||
|
||||
return true
|
||||
end,
|
||||
|
||||
Action = function(self, entity)
|
||||
Derma_StringRequest(L("containerNameWrite"), "", "", function(text)
|
||||
self:MsgStart()
|
||||
net.WriteEntity(entity)
|
||||
net.WriteString(text)
|
||||
self:MsgEnd()
|
||||
end)
|
||||
end,
|
||||
|
||||
Receive = function(self, length, client)
|
||||
local entity = net.ReadEntity()
|
||||
|
||||
if (!IsValid(entity)) then return end
|
||||
if (!self:Filter(entity, client)) then return end
|
||||
|
||||
local name = net.ReadString()
|
||||
|
||||
if (name:len() != 0) then
|
||||
entity:SetDisplayName(name)
|
||||
|
||||
client:NotifyLocalized("containerName", name)
|
||||
else
|
||||
local definition = ix.container.stored[entity:GetModel():lower()]
|
||||
|
||||
entity:SetDisplayName(definition.name)
|
||||
|
||||
client:NotifyLocalized("containerNameRemove")
|
||||
end
|
||||
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(self)
|
||||
end
|
||||
|
||||
local inventory = entity:GetInventory()
|
||||
|
||||
ix.log.Add(client, "containerName", name, inventory:GetID(), name:len() != 0)
|
||||
end
|
||||
})
|
||||
Reference in New Issue
Block a user