This commit is contained in:
lifestorm
2024-08-04 22:55:00 +03:00
parent 0e770b2b49
commit 94063e4369
7342 changed files with 1718932 additions and 14 deletions

View File

@@ -0,0 +1,100 @@
--[[
| 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
AddCSLuaFile()
ENT.Base = "base_entity"
ENT.Type = "anim"
ENT.PrintName = "Caisse de livraison"
ENT.Category = "HL2 RP"
ENT.Spawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.bNoPersist = true
ENT.AdminOnly = true
function ENT:SetupDataTables()
self:NetworkVar("String", 0, "DisplayName")
self:NetworkVar("String", 1, "LocationId")
end
if (SERVER) then
function ENT:Initialize()
self:SetModel("models/items/item_item_crate.mdl")
self:SetSolid(SOLID_VPHYSICS)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local physObj = self:GetPhysicsObject()
if (IsValid(physObj)) then
physObj:EnableMotion(false)
physObj:Sleep()
end
self.uniqueID = ""
end
function ENT:Use(activator, caller)
if (self.uniqueID == "") then return end
if (IsValid(caller) and caller:IsPlayer() and caller:GetCharacter()) then
local pickupItems = caller:GetCharacter():GetSmugglingPickupItems()
if (pickupItems["__invalid_cache"]) then
pickupItems[self.uniqueID] = pickupItems[self.uniqueID] or {}
for k, v in pairs(pickupItems["__invalid_cache"]) do
pickupItems[self.uniqueID][k] = (pickupItems[self.uniqueID][k] or 0) + v
end
pickupItems["__invalid_cache"] = nil
caller:GetCharacter().vars.smugglingPickupItems = pickupItems
end
if (pickupItems[self.uniqueID]) then
caller.ixPickupCache = self
netstream.Start(caller, "ixSmugglingPickupItems", pickupItems[self.uniqueID])
else
caller:NotifyLocalized("smugglerNoPickupItems")
end
end
end
function ENT:SetNewModel(model)
self:SetModel(model)
self:PhysicsInit(SOLID_BBOX)
self:SetSolid(SOLID_BBOX)
end
function ENT:UpdateUniqueID(uniqueID)
uniqueID = string.gsub(string.Trim(string.utf8lower(uniqueID)), "%s", "_")
if (uniqueID == self.uniqueID) then return end
local oldID = self.uniqueID
self.uniqueID = uniqueID
PLUGIN:UpdateCacheID(self, uniqueID, oldID)
end
else
function ENT:Draw()
self:DrawModel()
end
ENT.PopulateEntityInfo = true
function ENT:OnPopulateEntityInfo(container)
local name = container:AddRow("name")
name:SetImportant()
name:SetText(self:GetDisplayName())
name:SizeToContents()
end
end

View File

@@ -0,0 +1,351 @@
--[[
| 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/
--]]
-- luacheck: read globals SMUGGLER_BUY SMUGGLER_SELL SMUGGLER_BOTH SMUGGLER_WELCOME SMUGGLER_LEAVE SMUGGLER_NOTRADE SMUGGLER_PRICE
-- luacheck: read globals SMUGGLER_STOCK SMUGGLER_MODE SMUGGLER_MAXSTOCK SMUGGLER_SELLANDBUY SMUGGLER_SELLONLY SMUGGLER_BUYONLY SMUGGLER_TEXT
local PLUGIN = PLUGIN
ENT.Type = "anim"
ENT.PrintName = "Smuggler"
ENT.Category = "HL2 RP"
ENT.Spawnable = true
ENT.AdminOnly = true
ENT.isSmuggler = true
ENT.bNoPersist = true
function ENT:SetupDataTables()
self:NetworkVar("String", 0, "DisplayName")
self:NetworkVar("String", 1, "Description")
end
function ENT:Initialize()
self:SetModel("models/mossman.mdl")
self:SetMoveType(MOVETYPE_NONE)
self:DrawShadow(true)
if (SERVER) then
self:SetUseType(SIMPLE_USE)
self:SetSolid(SOLID_OBB)
self:PhysicsInit(SOLID_OBB)
local physObj = self:GetPhysicsObject()
if (IsValid(physObj)) then
physObj:EnableMotion(false)
physObj:Sleep()
end
self:SetDisplayName("John Doe")
self:SetDescription("")
self.items = {}
self.messages = {}
self.receivers = {}
self.stashList = {}
self.maxStock = 30
self:SetInactive()
end
timer.Simple(1, function()
if (IsValid(self)) then
self:SetAnim()
end
end)
end
function ENT:CanAccess(client)
if (client:HasActiveCombineSuit()) then
return false
end
if (ix.faction.Get(client:Team()).noSmuggler) then
return false
end
return true
end
function ENT:GetStock(uniqueID)
local maxStock = PLUGIN.itemList[uniqueID].maxStock or self.maxStock
if (self.items[uniqueID]) then
return self.items[uniqueID][SMUGGLER_STOCK] or 0, maxStock
end
return 0, maxStock
end
function ENT:GetTotalStock()
local stock = 0
for _, v in pairs(self.items) do
stock = stock + (v[SMUGGLER_STOCK] or 0)
end
return stock
end
function ENT:GetPrice(uniqueID, bClientIsSelling)
local price = 0
if (ix.item.list[uniqueID] and self.items[uniqueID]) then
local info = PLUGIN.itemList[uniqueID]
if (bClientIsSelling) then
-- info.buy = price of smuggler buying from player = player selling to smuggler
price = info.buy or 0
else
-- info.sell = price of smuggler selling to player = player buying from smuggler
price = info.sell or 0
end
end
return price
end
function ENT:HasMoney(amount)
-- Smuggler not using money system so they can always afford it.
if (!self.money) then
return true
end
return self.money >= amount
end
function ENT:SetAnim()
for k, v in ipairs(self:GetSequenceList()) do
if (v:lower():find("idle") and v != "idlenoise") then
return self:ResetSequence(k)
end
end
if (self:GetSequenceCount() > 1) then
self:ResetSequence(4)
end
end
if (SERVER) then
function ENT:SpawnFunction(client, trace)
local angles = (trace.HitPos - client:GetPos()):Angle()
angles.r = 0
angles.p = 0
angles.y = angles.y + 180
local entity = ents.Create("ix_smuggler")
entity:SetPos(trace.HitPos)
entity:SetAngles(angles)
entity:Spawn()
ix.saveEnts:SaveEntity(entity)
PLUGIN:SaveData()
return entity
end
function ENT:SetInactive()
self.ixIsActiveSmuggler = nil
self.ixSmugglerPrepRotation = nil
self:SetCollisionGroup(COLLISION_GROUP_WORLD)
self:SetNoDraw(true)
for _, v in pairs(self.items) do
if (v[SMUGGLER_STOCK]) then
v[SMUGGLER_STOCK] = 0
end
end
self:SetMoney(0)
self.pickupCache = nil
end
function ENT:SetActive()
self.ixIsActiveSmuggler = true
self.ixSmugglerDeliveryOffset = math.Rand(0.9, 1.2)
self:SetCollisionGroup(COLLISION_GROUP_NONE)
self:SetNoDraw(false)
self:ResetSmuggler()
end
function ENT:ResetSmuggler()
if (!self.ixIsActiveSmuggler) then return end
self.ixSmugglerPrepRotation = nil
self.ixSmugglerDeliveryOffset = math.Rand(0.9, 1.2)
for _, v in pairs(self.items) do
if (v[SMUGGLER_STOCK]) then
v[SMUGGLER_STOCK] = 0
end
end
-- limit money to player count between 10 and 50
local playerCount = math.Clamp(#player.GetAll(), 10, 50)
-- remap money: 0 players theoretically gives no money, but we always have a minimum player count of 10
-- 50 players gives max money
self:SetMoney(math.Remap(playerCount, 0, 50, 0, ix.config.Get("SmugglerDefaultMoney")))
local stashList = {}
for k, v in pairs(self.stashList) do
stashList[v] = true
end
local caches = {}
for k, v in pairs(PLUGIN.cacheIDList) do
if (stashList[v.locationId]) then
table.insert(caches, k)
end
end
if (#caches > 0) then
self.pickupCache = Entity(table.Random(caches))
end
end
function ENT:Use(activator)
if (!self.ixIsActiveSmuggler) then
return
end
if (self.ixSmugglerPrepRotation) then
activator:NotifyLocalized("smugglerPrepMove")
return
end
local character = activator:GetCharacter()
if (!self:CanAccess(activator) or hook.Run("CanPlayerUseSmuggler", activator) == false) then
if (self.messages[SMUGGLER_NOTRADE]) then
activator:ChatPrint(self:GetDisplayName()..": "..self.messages[SMUGGLER_NOTRADE])
else
activator:NotifyLocalized("smugglerNoTrade")
end
return
end
local items = {}
-- Only send what is needed.
for k, v in pairs(self.items) do
if (!table.IsEmpty(v) and (CAMI.PlayerHasAccess(activator, "Helix - Manage Smugglers", nil) or v[SMUGGLER_MODE])) then
if (!activator:GetCharacter():CanDoAction("recipe_smuggling_"..k)) then continue end
items[k] = v
end
end
if (table.IsEmpty(items)) then
activator:NotifyLocalized("smugglerNoItems")
return
end
self.receivers[#self.receivers + 1] = activator
if (self.messages[SMUGGLER_WELCOME]) then
activator:ChatPrint(self:GetDisplayName()..": "..self.messages[SMUGGLER_WELCOME])
end
activator.ixSmuggler = self
activator.ixSmugglerDelivery = nil
-- force sync to prevent outdated inventories while buying/selling
if (character) then
character:GetInventory():Sync(activator, true)
end
net.Start("ixSmugglerOpen")
net.WriteEntity(self)
net.WriteUInt(self.money or 0, 16)
net.WriteUInt(self.maxStock or 0, 16)
net.WriteString(IsValid(self.pickupCache) and self.pickupCache:GetDisplayName() or "")
net.WriteTable(items)
net.WriteTable(self.stashList)
net.Send(activator)
ix.log.Add(activator, "smugglerUse", self:GetDisplayName())
end
function ENT:SetMoney(value)
self.money = value
net.Start("ixSmugglerMoney")
net.WriteUInt(value and value or -1, 16)
net.Send(self.receivers)
end
function ENT:GiveMoney(value)
if (self.money) then
self:SetMoney(self:GetMoney() + value)
end
end
function ENT:TakeMoney(value)
if (self.money) then
self:GiveMoney(-value)
end
end
function ENT:SetStock(uniqueID, value)
self.items[uniqueID] = self.items[uniqueID] or {}
self.items[uniqueID][SMUGGLER_STOCK] = math.Clamp(value, 0, PLUGIN.itemList[uniqueID].maxStock or self.maxStock)
net.Start("ixSmugglerStock")
net.WriteString(uniqueID)
net.WriteUInt(self.items[uniqueID][SMUGGLER_STOCK], 16)
net.Send(self.receivers)
end
function ENT:AddStock(uniqueID, value)
self:SetStock(uniqueID, self:GetStock(uniqueID) + (value or 1))
end
function ENT:TakeStock(uniqueID, value)
self:AddStock(uniqueID, -(value or 1))
end
else
function ENT:Draw()
self:DrawModel()
end
function ENT:Think()
if ((self.nextAnimCheck or 0) < CurTime()) then
self:SetAnim()
self.nextAnimCheck = CurTime() + 60
end
self:SetNextClientThink(CurTime() + 0.25)
return true
end
ENT.PopulateEntityInfo = true
function ENT:OnPopulateEntityInfo(container)
if (self:GetNoDraw()) then return end
local name = container:AddRow("name")
name:SetImportant()
name:SetText(self:GetDisplayName())
name:SizeToContents()
local descriptionText = self:GetDescription()
if (descriptionText != "") then
local description = container:AddRow("description")
description:SetText(self:GetDescription())
description:SizeToContents()
end
end
end
function ENT:GetMoney()
return self.money
end