mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-18 06:03:47 +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
|
||||
Reference in New Issue
Block a user