mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-18 22:23:46 +03:00
Upload
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
local glowMaterial = Material("sprites/glow04_noz")
|
||||
|
||||
local color_green = Color(0, 255, 0, 255)
|
||||
local color_red = Color(255, 0, 0, 255)
|
||||
local color_orange = Color(255, 125, 0, 255)
|
||||
|
||||
function ENT:Draw()
|
||||
self:DrawModel()
|
||||
|
||||
local position = self:GetPos()
|
||||
local angles = self:GetAngles()
|
||||
angles:RotateAroundAxis(angles:Up(), 90)
|
||||
angles:RotateAroundAxis(angles:Forward(), 90)
|
||||
|
||||
local f, r, u = self:GetForward(), self:GetRight(), self:GetUp()
|
||||
|
||||
local spacing = 0
|
||||
local labels = self:GetNetVar("labels")
|
||||
local prices = self:GetNetVar("prices")
|
||||
|
||||
if (!labels or !prices) then return end
|
||||
|
||||
cam.Start3D2D(position + f * 17.6 + r * -18 + u * 4.6, angles, 0.06)
|
||||
for i = 1, 8 do
|
||||
if (labels[i] != "" and labels[i] != " ") then
|
||||
draw.SimpleText("(" .. prices[i] .. ")" .. labels[i], "DebugFixedSmall", 90, spacing, color_white, TEXT_ALIGN_RIGHT)
|
||||
end
|
||||
|
||||
spacing = spacing + 34
|
||||
end
|
||||
cam.End3D2D()
|
||||
|
||||
render.SetMaterial(glowMaterial)
|
||||
|
||||
if (self.buttons) then
|
||||
local closest = self:GetNearestButton()
|
||||
local stocks = self:GetNetVar("stocks")
|
||||
local buttons = self:GetNetVar("buttons")
|
||||
|
||||
for k, v in pairs(self.buttons) do
|
||||
if (labels[k] == "" or labels[k] == " ") then
|
||||
continue
|
||||
end
|
||||
|
||||
local color = color_green
|
||||
|
||||
if (stocks and !stocks[k]) then
|
||||
color = color_red
|
||||
color.a = 200
|
||||
end
|
||||
|
||||
if (buttons and !buttons[k]) then
|
||||
color = color_orange
|
||||
color.a = 200
|
||||
end
|
||||
|
||||
if (closest != k) then
|
||||
color.a = color == color_red and 100 or 75
|
||||
else
|
||||
color.a = 230 + (math.sin(RealTime() * 7.5) * 25)
|
||||
end
|
||||
|
||||
if (LocalPlayer():KeyDown(IN_USE) and closest == k) then
|
||||
color = table.Copy(color)
|
||||
color.r = math.min(color.r + 100, 255)
|
||||
color.g = math.min(color.g + 100, 255)
|
||||
color.b = math.min(color.b + 100, 255)
|
||||
end
|
||||
|
||||
render.DrawSprite(v, 4, 4, color)
|
||||
end
|
||||
|
||||
if (!self:GetLocked()) then
|
||||
render.DrawSprite(position + f * 18.5 + r * -21 + u * 13, 7, 7, Color(50, 100, 255, 255))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,259 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
AddCSLuaFile("cl_init.lua")
|
||||
AddCSLuaFile("shared.lua")
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
function ENT:SpawnFunction(client, trace)
|
||||
if (!trace.Hit) then return end
|
||||
|
||||
local SpawnPosition = trace.HitPos + trace.HitNormal + Vector(0, 0, 45)
|
||||
local SpawnAngle = client:EyeAngles()
|
||||
SpawnAngle.p = 0
|
||||
SpawnAngle.y = SpawnAngle.y + 180
|
||||
|
||||
local entity = ents.Create("ix_customvendingmachine")
|
||||
entity:SetPos(SpawnPosition)
|
||||
entity:SetAngles(SpawnAngle)
|
||||
entity:Spawn()
|
||||
entity:Activate()
|
||||
|
||||
ix.inventory.New(0, "vendingMachine", function(inventory)
|
||||
if (!IsValid(entity)) then return end
|
||||
if (inventory) then
|
||||
inventory.vars.isBag = true
|
||||
inventory.vars.isVendingMachine = true
|
||||
|
||||
entity:SetID(inventory:GetID())
|
||||
|
||||
ix.item.Spawn("vendingmachinekey", client, nil, nil, {vendingMachineID = entity:GetID()})
|
||||
ix.item.Spawn("vendingmachinekey", client, nil, nil, {vendingMachineID = entity:GetID()})
|
||||
ix.item.Spawn("vendingmachinekey", client, nil, nil, {vendingMachineID = entity:GetID()})
|
||||
|
||||
ix.saveEnts:SaveEntity(entity)
|
||||
PLUGIN:SaveData()
|
||||
end
|
||||
end)
|
||||
|
||||
return entity
|
||||
end
|
||||
|
||||
function ENT:CheckHasID(character)
|
||||
local idCard = character:GetInventory():HasItem("id_card")
|
||||
|
||||
if (!idCard) then
|
||||
self:EmitSound("buttons/button2.wav")
|
||||
self.nextUse = CurTime() + 1
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function ENT.CheckIDCard(idCard, genericData, client, entity, collecting)
|
||||
if (idCard:GetData("active", false) == false) then
|
||||
ix.combineNotify:AddImportantNotification("WRN:// Inactive Identification Card #" .. idCard:GetData("cid", 00000) .. " usage attempt detected", nil, client, client:GetPos())
|
||||
entity:EmitSound("buttons/button2.wav")
|
||||
entity.nextUse = CurTime() + 1
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local isBOL = genericData.bol
|
||||
local isAC = genericData.anticitizen
|
||||
|
||||
if (isBOL or isAC) then
|
||||
local text = isBOL and "BOL Suspect" or "Anti-Citizen"
|
||||
|
||||
ix.combineNotify:AddImportantNotification("WRN:// " .. text .. " Identification Card activity detected", nil, client, client:GetPos())
|
||||
end
|
||||
|
||||
if (collecting) then
|
||||
idCard:GiveCredits(entity:GetNetVar("credits", 0), "Vending Machine", "Vending Machine (" .. entity:GetID() .. ") Credit Collection")
|
||||
entity:SetNetVar("credits", 0)
|
||||
ix.saveEnts:SaveEntity(entity)
|
||||
else
|
||||
entity:PostAuthorized(client, idCard)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT.CheckIDError(_, entity)
|
||||
entity:EmitSound("buttons/button2.wav")
|
||||
end
|
||||
|
||||
function ENT:Use(activator)
|
||||
if ((self.nextUse or 0) < CurTime()) then
|
||||
self.nextUse = CurTime() + 1
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
local button = self:GetNearestButton(activator)
|
||||
|
||||
if (button) then
|
||||
activator:EmitSound("buttons/lightswitch2.wav", 55, 125)
|
||||
|
||||
local character = activator:GetCharacter()
|
||||
|
||||
if (self:CheckHasID(character)) then
|
||||
local idCards = character:GetInventory():GetItemsByUniqueID("id_card")
|
||||
|
||||
if (#idCards == 1) then
|
||||
idCards[1]:LoadOwnerGenericData(self.CheckIDCard, self.CheckIDError, activator, self)
|
||||
else
|
||||
self.cidSelection = activator
|
||||
|
||||
net.Start("ixSelectVendingMachineCID")
|
||||
net.WriteEntity(self)
|
||||
net.Send(activator)
|
||||
|
||||
timer.Simple(30, function()
|
||||
if (IsValid(self)) then
|
||||
self.cidSelection = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
elseif (!self:GetLocked()) then
|
||||
activator.ixVendingMachineEdit = self
|
||||
activator:EmitSound("buttons/lightswitch2.wav", 55, 125)
|
||||
|
||||
self:EmitSound("buttons/button1.wav")
|
||||
|
||||
net.Start("ixVendingMachineManager")
|
||||
net.WriteEntity(self)
|
||||
net.Send(activator)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:PostAuthorized(activator, idCard)
|
||||
local button = self:GetNearestButton(activator)
|
||||
local prices = self:GetNetVar("prices")
|
||||
local labels = self:GetNetVar("labels")
|
||||
local buttons = self:GetNetVar("buttons")
|
||||
|
||||
if (!labels[button]) then
|
||||
return
|
||||
end
|
||||
|
||||
if (buttons[button]) then
|
||||
local item = self:FindItemInRow(button)
|
||||
|
||||
if (item) then
|
||||
local price = prices[button]
|
||||
|
||||
if (idCard:HasCredits(price)) then
|
||||
local position = self:GetPos()
|
||||
local f, r, u = self:GetForward(), self:GetRight(), self:GetUp()
|
||||
local inventory = ix.item.inventories[self:GetID()]
|
||||
|
||||
item.invID = 0
|
||||
inventory:Remove(item.id, false, true)
|
||||
|
||||
local query = mysql:Update("ix_items")
|
||||
query:Update("inventory_id", 0)
|
||||
query:Where("item_id", item.id)
|
||||
query:Execute()
|
||||
|
||||
inventory = ix.item.inventories[0]
|
||||
inventory[item:GetID()] = item
|
||||
|
||||
item:Spawn(position + f * 19 + r * 4 + u * -26)
|
||||
idCard:TakeCredits(price, "Vending Machine", "\"" .. item:GetName() .. "\" Vending Machine (" .. self:GetID() .. ") purchase.")
|
||||
|
||||
self:EmitSound("buttons/button4.wav")
|
||||
self:SetNetVar("credits", self:GetNetVar("credits", 0) + price)
|
||||
|
||||
activator:Notify("You have purchased a " .. labels[button] .. " for " .. price .. " Credits.")
|
||||
else
|
||||
self:EmitSound("buttons/button8.wav")
|
||||
|
||||
activator:Notify("You need a total of " .. price .. " Credits to purchase a " .. labels[button] .. "!")
|
||||
end
|
||||
|
||||
-- Check again to see if we ran out. If we did, change to red.
|
||||
self:UpdateStocks()
|
||||
ix.saveEnts:SaveEntity(self)
|
||||
else
|
||||
self:EmitSound("buttons/button2.wav")
|
||||
|
||||
self:UpdateStocks()
|
||||
end
|
||||
else
|
||||
self:EmitSound("buttons/combine_button_locked.wav")
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:CollectCredits(activator)
|
||||
local character = activator:GetCharacter()
|
||||
|
||||
if (!self:GetLocked() and self:CheckHasID(character)) then
|
||||
local idCards = character:GetInventory():GetItemsByUniqueID("id_card")
|
||||
|
||||
if (#idCards == 1) then
|
||||
idCards[1]:LoadOwnerGenericData(self.CheckIDCard, self.CheckIDError, activator, self, true)
|
||||
else
|
||||
self.cidSelection = activator
|
||||
activator.isCollecting = true
|
||||
|
||||
net.Start("ixSelectVendingMachineCID")
|
||||
net.WriteEntity(self)
|
||||
net.Send(activator)
|
||||
|
||||
timer.Simple(30, function()
|
||||
if (IsValid(self)) then
|
||||
self.cidSelection = nil
|
||||
end
|
||||
|
||||
if (IsValid(activator)) then
|
||||
activator.isCollecting = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:FindItemInRow(row)
|
||||
local inventory = ix.item.inventories[self:GetID()]
|
||||
|
||||
if (inventory) then
|
||||
for _, itemData in pairs(inventory:GetItems(true)) do
|
||||
if (itemData.gridY == row) then
|
||||
return itemData
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:SetData(dataType, slot, value)
|
||||
local data = self:GetNetVar(dataType, {})
|
||||
|
||||
if (data[slot] != value) then
|
||||
data[slot] = value
|
||||
|
||||
self:SetNetVar(dataType, data)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:UpdateStocks()
|
||||
for i = 1, 8 do
|
||||
if (self:FindItemInRow(i)) then
|
||||
self:SetData("stocks", i, true)
|
||||
else
|
||||
self:SetData("stocks", i, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,156 @@
|
||||
--[[
|
||||
| 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 = "Vending Machine"
|
||||
ENT.Category = "HL2 RP"
|
||||
ENT.Spawnable = true
|
||||
ENT.AdminOnly = true
|
||||
ENT.PhysgunDisable = true
|
||||
ENT.PhysgunAllowAdmin = true
|
||||
|
||||
function ENT:SetupDataTables()
|
||||
self:NetworkVar("Int", 0, "ID")
|
||||
self:NetworkVar("Bool", 1, "Locked")
|
||||
end
|
||||
|
||||
function ENT:Initialize()
|
||||
self.buttons = {}
|
||||
|
||||
local position = self:GetPos()
|
||||
local f, r, u = self:GetForward(), self:GetRight(), self:GetUp()
|
||||
|
||||
self.buttons[1] = position + f * 18 + r * -24.4 + u * 4.3
|
||||
self.buttons[2] = position + f * 18 + r * -24.4 + u * 2.25
|
||||
self.buttons[3] = position + f * 18 + r * -24.4 + u * 0.20
|
||||
self.buttons[4] = position + f * 18 + r * -24.4 + u * -1.85
|
||||
self.buttons[5] = position + f * 18 + r * -24.4 + u * -3.9
|
||||
self.buttons[6] = position + f * 18 + r * -24.4 + u * -5.95
|
||||
self.buttons[7] = position + f * 18 + r * -24.4 + u * -8
|
||||
self.buttons[8] = position + f * 18 + r * -24.4 + u * -10.05
|
||||
|
||||
if (SERVER) then
|
||||
self:SetModel("models/willardnetworks/misc/customvendingmachine.mdl")
|
||||
self:PhysicsInit(SOLID_VPHYSICS)
|
||||
self:SetSolid(SOLID_VPHYSICS)
|
||||
self:SetUseType(SIMPLE_USE)
|
||||
|
||||
self:SetLocked(true)
|
||||
|
||||
local labels = {}
|
||||
local buttons = {}
|
||||
local prices = {}
|
||||
local stocks = {}
|
||||
|
||||
for i = 1, 8 do
|
||||
labels[i] = ""
|
||||
buttons[i] = true
|
||||
prices[i] = 0
|
||||
stocks[i] = false
|
||||
end
|
||||
|
||||
self:SetNetVar("labels", labels)
|
||||
self:SetNetVar("buttons", buttons)
|
||||
self:SetNetVar("prices", prices)
|
||||
self:SetNetVar("stocks", stocks)
|
||||
|
||||
local physObj = self:GetPhysicsObject()
|
||||
|
||||
if (IsValid(physObj)) then
|
||||
physObj:EnableMotion(false)
|
||||
physObj:Sleep()
|
||||
end
|
||||
else
|
||||
local uniqueID = "VendingMachineAmbience" .. self:EntIndex()
|
||||
local time = 1
|
||||
|
||||
timer.Simple(1, function()
|
||||
timer.Adjust(uniqueID, 1.7461677789688)
|
||||
end)
|
||||
|
||||
timer.Create(uniqueID, time, 0, function()
|
||||
if (IsValid(self)) then
|
||||
self:EmitSound("vendingmachinehum_loop.wav", 65, 100, 0.15)
|
||||
else
|
||||
timer.Remove(uniqueID)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:GetNearestButton(client)
|
||||
client = client or (CLIENT and LocalPlayer())
|
||||
|
||||
if (self.buttons) then
|
||||
local position = self:GetPos()
|
||||
local f, r, u = self:GetForward(), self:GetRight(), self:GetUp()
|
||||
|
||||
self.buttons[1] = position + f * 18 + r * -24.4 + u * 4.3
|
||||
self.buttons[2] = position + f * 18 + r * -24.4 + u * 2.25
|
||||
self.buttons[3] = position + f * 18 + r * -24.4 + u * 0.20
|
||||
self.buttons[4] = position + f * 18 + r * -24.4 + u * -1.85
|
||||
self.buttons[5] = position + f * 18 + r * -24.4 + u * -3.9
|
||||
self.buttons[6] = position + f * 18 + r * -24.4 + u * -5.95
|
||||
self.buttons[7] = position + f * 18 + r * -24.4 + u * -8
|
||||
self.buttons[8] = position + f * 18 + r * -24.4 + u * -10.05
|
||||
|
||||
local data = {}
|
||||
data.start = client:GetShootPos()
|
||||
data.endpos = data.start + client:GetAimVector()*96
|
||||
data.filter = client
|
||||
local trace = util.TraceLine(data)
|
||||
local hitPos = trace.HitPos
|
||||
|
||||
if (hitPos) then
|
||||
for buttonNum, buttonPos in pairs(self.buttons) do
|
||||
if (buttonPos:Distance(hitPos) <= 2) then
|
||||
return buttonNum
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
if (SERVER) then
|
||||
if (!ix.shuttingDown) then
|
||||
local index = self:GetID()
|
||||
|
||||
if (!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
|
||||
else
|
||||
self:StopSound("vendingmachinehum_loop.wav")
|
||||
|
||||
timer.Simple(0.1, function()
|
||||
if (!IsValid(self)) then
|
||||
timer.Remove("VendingMachineAmbience" .. self:EntIndex())
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user