This commit is contained in:
lifestorm
2024-08-04 23:54:45 +03:00
parent 0e770b2b49
commit df294d03aa
7526 changed files with 4011945 additions and 15 deletions

View File

@@ -0,0 +1,83 @@
--[[
| 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
ENT.Type = "anim"
ENT.PrintName = "Stash"
ENT.Category = "Helix"
ENT.Spawnable = false
ENT.bNoPersist = true
function ENT:SetupDataTables()
self:NetworkVar("String", 0, "DisplayName")
end
if (SERVER) then
function ENT:Initialize()
self:PhysicsInit(SOLID_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
self.receivers = {}
local physObj = self:GetPhysicsObject()
if (IsValid(physObj)) then
physObj:EnableMotion()
physObj:Sleep()
end
end
function ENT:Use(activator)
local character = activator:GetCharacter()
if (!character) then
return
end
local invID = activator:GetCharacter():GetStashInventory()
if (invID == 0) then
return
end
local inventory = ix.item.inventories[invID]
if (inventory and (activator.ixNextOpen or 0) < CurTime()) then
local stashName = character:GetStashName()
if (stashName != "" and string.utf8lower(stashName) != string.utf8lower(self:GetDisplayName()) and (inventory:GetFilledSlotCount() != 0 or character:GetStashMoney() != 0)) then
activator:NotifyLocalized("stashesOtherInUse")
return
end
character:SetStashName(self:GetDisplayName())
PLUGIN:OpenInventory(activator, character, self, inventory)
activator.ixNextOpen = CurTime() + 1
end
end
else
ENT.PopulateEntityInfo = true
function ENT:OnPopulateEntityInfo(tooltip)
local title = tooltip:AddRow("name")
title:SetImportant()
title:SetText(self:GetDisplayName())
title:SetBackgroundColor(ix.config.Get("color"))
title:SizeToContents()
local desc = tooltip:AddRowAfter("name", "description")
local currStash = LocalPlayer():GetCharacter():GetStashName()
if (currStash == "") then
desc:SetText(L("stashStartUsing"))
elseif (currStash != self:GetDisplayName()) then
desc:SetText(L("stashOtherInUse", currStash))
else
desc:SetText(L("stashHasItems"))
end
desc:SizeToContents()
end
end

View File

@@ -0,0 +1,223 @@
--[[
| 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 = "Personal Stashes"
PLUGIN.author = "Gr4Ss"
PLUGIN.description = "Adds a new container entities with a personal inventory for every player."
--If you decrease the below, items in the removed slots will disappear
--Preferably do not decrease this without wiping stashes
PLUGIN.STASH_WIDTH = 4
PLUGIN.STASH_HEIGHT = 4
ix.inventory.Register("personalStash", PLUGIN.STASH_WIDTH, PLUGIN.STASH_HEIGHT, true)
ix.util.Include("sv_hooks.lua")
ix.util.Include("sv_plugin.lua")
ix.char.RegisterVar("stashInventory", {
field = "stash",
fieldType = ix.type.number,
default = 0,
bNoDisplay = true,
bNoNetworking = true
})
ix.char.RegisterVar("stashName", {
field = "stash_name",
fieldType = ix.type.string,
default = "",
bNoDisplay = true,
isLocal = true,
OnSet = function(character, value)
local oldVar = character.vars["stashName"]
character.vars["stashName"] = string.utf8lower(value)
net.Start("ixCharacterVarChanged")
net.WriteUInt(character:GetID(), 32)
net.WriteString("stashName")
net.WriteType(value)
net.Send(character.player)
hook.Run("CharacterVarChanged", character, "stashName", oldVar, value)
end
})
ix.char.RegisterVar("stashMoney", {
field = "stash_money",
fieldType = ix.type.number,
default = 0,
bNoDisplay = true,
bNoNetworking = true
})
CAMI.RegisterPrivilege({
Name = "Helix - Manage Stashes",
MinAccess = "superadmin"
})
ix.lang.AddTable("english", {
stashesOtherInUse = "Zaten başka bir saklama alanını kullanıyorsunuz.",
stashStartUsing = "Bu saklama alanını kullanmaya başlayabilirsiniz.",
stashOtherInUse = "Zaten '%s'yi kullanıyorsunuz.",
stashHasItems = "Bu saklama alanında eşyalarınız/chipleriniz var."
})
ix.lang.AddTable("spanish", {
stashOtherInUse = "Ya tienes el '%s' en uso.",
stashStartUsing = "Puedes empezar a usar este alijo.",
stashesOtherInUse = "Ya tienes otro alijo en uso.",
stashHasItems = "Tienes objetos/fichas en este alijo."
})
if (CLIENT) then
local function stashESP(client, entity, x, y, factor)
ix.util.DrawText("Stash - "..entity:GetDisplayName(), x, y - math.max(10, 32 * factor), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, nil, factor)
end
ix.observer:RegisterESPType("ix_stash", stashESP, "stash")
end
properties.Add("ixStashSetName", {
MenuLabel = "Set Name",
Order = 400,
MenuIcon = "icon16/tag_blue_edit.png",
Filter = function(self, entity, client)
if (entity:GetClass() != "ix_stash") then return false end
if (!gamemode.Call("CanProperty", client or LocalPlayer(), "ixStashSetName", entity)) then return false end
return CAMI.PlayerHasAccess(client or LocalPlayer(), "Helix - Manage Stashes")
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
local oldName = entity:GetDisplayName()
if (oldName == name) then return end
entity:SetDisplayName(name)
client:NotifyLocalized("containerName", name)
for _, v in ipairs(player.GetAll()) do
if (v:GetCharacter() and v:GetCharacter():GetStashName() == oldName) then
v:GetCharacter():SetStashName(name)
end
end
else
return
end
ix.log.Add(client, "stashName", name)
ix.saveEnts:SaveEntity(entity)
PLUGIN:SaveData()
end
})
properties.Add("ixCreateStash", {
MenuLabel = "Make Stash",
Order = 401,
MenuIcon = "icon16/tag_blue_edit.png",
Filter = function(self, entity, client)
if (entity:GetClass() != "prop_physics") then return false end
if (!gamemode.Call("CanProperty", client or LocalPlayer(), "ixCreateStash", entity)) then return false end
return CAMI.PlayerHasAccess(client or LocalPlayer(), "Helix - Manage Stashes")
end,
Action = function(self, entity)
self:MsgStart()
net.WriteEntity(entity)
self:MsgEnd()
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 container = ents.Create("ix_stash")
container:SetPos(entity:GetPos())
container:SetAngles(entity:GetAngles())
container:SetModel(entity:GetModel())
container:Spawn()
container:SetDisplayName("Personal Stash "..container:EntIndex())
ix.log.Add(client, "stashCreate", entity:GetModel())
entity:Remove()
ix.saveEnts:SaveEntity(container)
PLUGIN:SaveData()
end
})
properties.Add("ixViewStash", {
MenuLabel = "#View Stash",
Order = 11,
MenuIcon = "icon16/eye.png",
Filter = function(self, target, client)
return target:IsPlayer()
and CAMI.PlayerHasAccess(client or LocalPlayer(), "Helix - View Inventory")
and hook.Run("CanProperty", client or LocalPlayer(), "ixViewStash", 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
if (CAMI.PlayerHasAccess(client, "Helix - View Inventory")) then
local character = target:GetCharacter()
if (!character) then
return
end
local invID = target:GetCharacter():GetStashInventory()
if (invID == 0) then
return
end
local inventory = ix.item.inventories[invID]
if (!inventory) then
return
end
PLUGIN:OpenInventory(client, target:GetCharacter(), target, inventory, true)
end
end
})

View File

@@ -0,0 +1,57 @@
function PLUGIN:CharacterLoaded(character)
if (character:GetStashInventory() == 0) then
ix.inventory.New(character:GetID(), "personalStash", function(inventory)
inventory.vars.isBag = true
inventory.vars.isContainer = true
inventory.vars.isStash = true
character:SetStashInventory(inventory:GetID())
end)
end
end
function PLUGIN:PlayerLoadedCharacter(client, character)
local stashName = character:GetStashName()
if (stashName == "") then return end
-- check if character's stash still exists
for _, v in ipairs(self.stashes) do
if (string.utf8lower(v[4]) == stashName) then
return
end
end
character:SetStashName("")
ix.log.Add(client, "stashLocationReset", stashName)
end
function PLUGIN:ShouldRestoreInventory(charID, invID, invType)
if (invType == "personalStash") then
ix.inventory.Restore(tonumber(invID), self.STASH_WIDTH, self.STASH_HEIGHT, function(inventory)
inventory.vars.isBag = true
inventory.vars.isContainer = true
inventory.vars.isStash = true
inventory:SetOwner(charID)
end)
return false
end
end
function PLUGIN:OnItemTransferred(item, oldInv, newInv)
if (!newInv.owner or !newInv.vars.isStash) then
return
end
local character = ix.char.loaded[newInv.owner]
ix.log.Add(character:GetPlayer(), "inventoryRemove", character:GetName(), item:GetName(), item:GetID())
end
function PLUGIN:PlayerPushedPlayer(pusher, victim)
local victimStash = victim:GetCharacter():GetStashInventory()
if (ix.item.inventories[victimStash]) then
ix.storage.Close(ix.item.inventories[victimStash])
end
end

View File

@@ -0,0 +1,166 @@
--[[
| 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.stashes = PLUGIN.stashes or {}
ix.log.AddType("stashMoneyTake", function(client, name, amount, total)
return string.format("%s has taken %d %s from their '%s' stash (%d %s left).",
client:GetName(), amount, ix.currency.plural, name, total, ix.currency.plural)
end)
ix.log.AddType("stashMoneyGive", function(client, name, amount, total)
return string.format("%s has given %d %s to their '%s' stash (%d %s stored now).",
client:GetName(), amount, ix.currency.plural, name, total, ix.currency.plural)
end)
function PLUGIN:OpenInventory(activator, targetChar, entity, inventory, bIsAdmin)
local name = entity:GetClass() == "ix_stash" and entity:GetDisplayName() or entity:Name()
ix.storage.Open(activator, inventory, {
name = name,
entity = entity,
bMultipleUsers = false,
searchTime = bIsAdmin and 0 or ix.config.Get("containerOpenTime", 0.7),
data = {money = targetChar:GetStashMoney()},
OnPlayerClose = function()
if (inventory:GetFilledSlotCount() == 0 and targetChar:GetStashMoney() == 0) then
targetChar:SetStashName("")
end
ix.log.Add(activator, "stashClose", name)
end,
OnMoneyGive = function(client, inv, amount)
amount = math.Clamp(math.Round(tonumber(amount) or 0), 0, targetChar:GetMoney())
if (amount == 0) then
return
end
targetChar:SetMoney(targetChar:GetMoney() - amount)
local total = targetChar:GetStashMoney() + amount
targetChar:SetStashMoney(total)
ix.log.Add(client, "stashMoneyGive", name, amount, total)
return amount, total
end,
OnMoneyTake = function(client, inv, amount)
amount = math.Clamp(math.Round(tonumber(amount) or 0), 0, targetChar:GetStashMoney())
if (amount == 0) then
return
end
targetChar:SetMoney(targetChar:GetMoney() + amount)
local total = targetChar:GetStashMoney() - amount
targetChar:SetStashMoney(total)
ix.log.Add(client, "stashMoneyTake", name, amount, total)
return amount, total
end
})
ix.log.Add(activator, "stashOpen", name, bIsAdmin)
end
ix.log.AddType("stashOpen", function(client, stashName, bIsAdmin)
return string.format("%s %s the '%s' stash.", client:Name(), bIsAdmin and "admin-viewed" or "opened", stashName)
end, FLAG_NORMAL)
ix.log.AddType("stashClose", function(client, stashName)
return string.format("%s closed the '%s' stash.", client:Name(), stashName)
end, FLAG_NORMAL)
ix.log.AddType("stashLocationReset", function(client, stashName)
return string.format("%s their '%s' stash no longer exists, location reset.", client:Name(), stashName)
end, FLAG_NORMAL)
ix.log.AddType("stashName", function(client, name)
return string.format("%s has set a stash name to '%s'.", client:Name(), name)
end)
ix.log.AddType("stashCreate", function(client, stashModel)
return string.format("%s created a stash (%s).", client:Name(), stashModel)
end, FLAG_NORMAL)
function PLUGIN:RegisterSaveEnts()
ix.saveEnts:RegisterEntity("ix_stash", true, true, true, {
OnSave = function(entity, data) --OnSave
data.motion = false
data.model = entity:GetModel()
data.name = entity:GetDisplayName()
end,
OnRestore = function(entity, data) --OnRestore
entity:SetModel(data.model)
entity:SetSolid(SOLID_VPHYSICS)
entity:PhysicsInit(SOLID_VPHYSICS)
if (data.name) then
entity:SetDisplayName(data.name)
end
local physObj = entity:GetPhysicsObject()
if (IsValid(physObj)) then
physObj:EnableMotion()
physObj:Sleep()
end
end,
})
end
function PLUGIN:SaveStashes()
local data = {}
for _, v in ipairs(ents.FindByClass("ix_stash")) do
data[#data + 1] = {
v:GetPos(),
v:GetAngles(),
v:GetModel(),
v:GetDisplayName(),
}
end
self:SetData(data)
self.stashes = data
end
function PLUGIN:SaveData()
if (!ix.shuttingDown) then
self:SaveStashes()
end
end
function PLUGIN:LoadData()
if (!ix.config.Get("SaveEntsOldLoadingEnabled")) then return end
local data = self:GetData()
if (data) then
for _, v in ipairs(data) do
local entity = ents.Create("ix_stash")
entity:SetPos(v[1])
entity:SetAngles(v[2])
entity:Spawn()
entity:SetModel(v[3])
entity:SetSolid(SOLID_VPHYSICS)
entity:PhysicsInit(SOLID_VPHYSICS)
if (v[4]) then
entity:SetDisplayName(v[4])
end
local physObject = entity:GetPhysicsObject()
if (IsValid(physObject)) then
physObject:EnableMotion()
end
end
self.stashes = data
end
end