mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 13:53:45 +03:00
Upload
This commit is contained in:
197
gamemodes/ixhl2rp/plugins/container_placement/cl_plugin.lua
Normal file
197
gamemodes/ixhl2rp/plugins/container_placement/cl_plugin.lua
Normal file
@@ -0,0 +1,197 @@
|
||||
--[[
|
||||
| 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 actionsFont = "LargerTitlesFont"
|
||||
local colorYellow = Color(255, 205, 0)
|
||||
local colorRedT = Color(255, 0, 0, 230)
|
||||
local colorGreenT = Color(0, 255, 0, 230)
|
||||
local arrowBinds = {
|
||||
["+left"] = true,
|
||||
["+right"] = true,
|
||||
["+lookup"] = true,
|
||||
["+lookdown"] = true
|
||||
}
|
||||
|
||||
function PLUGIN:PlayerButtonDown(client, button)
|
||||
local containerInfo = client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (containerInfo and IsValid(client.ixContainerCP)) then
|
||||
if (button == MOUSE_LEFT) then
|
||||
if (!client.ixContainerCP.bInSolidEnviromentOrFloating) then
|
||||
net.Start("ixPlaceContainer")
|
||||
net.WriteBool(true)
|
||||
net.WriteVector(client.ixContainerCP:GetPos())
|
||||
net.WriteAngle(client.ixContainerCP:GetAngles())
|
||||
net.SendToServer()
|
||||
else
|
||||
client:EmitSound("buttons/button10.wav")
|
||||
end
|
||||
elseif (button == MOUSE_RIGHT) then
|
||||
net.Start("ixPlaceContainer")
|
||||
net.WriteBool(false)
|
||||
net.SendToServer()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PostDrawTranslucentRenderables()
|
||||
local client = LocalPlayer()
|
||||
local containerInfo = client and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (containerInfo) then
|
||||
local traceData = {}
|
||||
traceData.start = client:GetShootPos()
|
||||
traceData.endpos = traceData.start + client:GetAimVector() * 96
|
||||
traceData.filter = client
|
||||
local traceResult = util.TraceLine(traceData)
|
||||
|
||||
if (!IsValid(client.ixContainerCP)) then
|
||||
client.ixContainerCP = ents.CreateClientProp(containerInfo.model)
|
||||
|
||||
client.ixContainerCP:Spawn()
|
||||
client.ixContainerCP:Activate()
|
||||
end
|
||||
|
||||
local containerMaxs = client.ixContainerCP:OBBMaxs()
|
||||
local containerPos = traceResult.HitPos
|
||||
containerPos:Add(Vector(0, 0, containerMaxs.z + 1))
|
||||
client.ixContainerCP:SetPos(containerPos)
|
||||
|
||||
local yFacePlayer = math.NormalizeAngle(EyeAngles().y + 180)
|
||||
local containerAngles = Angle(0, yFacePlayer, 0)
|
||||
|
||||
if (client.ixContainerRotationAngles) then
|
||||
containerAngles:Add(client.ixContainerRotationAngles)
|
||||
end
|
||||
|
||||
client.ixContainerCP:SetAngles(containerAngles)
|
||||
|
||||
if (client.ixContainerCP:IsInSolidEnviromentOrFloating()) then
|
||||
client.ixContainerCP.bInSolidEnviromentOrFloating = true
|
||||
|
||||
client.ixContainerCP:SetColor(colorRedT)
|
||||
else
|
||||
client.ixContainerCP.bInSolidEnviromentOrFloating = false
|
||||
|
||||
client.ixContainerCP:SetColor(colorGreenT)
|
||||
end
|
||||
|
||||
client.ixContainerCP:SetRenderMode(RENDERMODE_TRANSCOLOR)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:Think()
|
||||
local client = LocalPlayer()
|
||||
local containerInfo = client and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (!containerInfo and IsValid(client.ixContainerCP)) then
|
||||
client.ixContainerCP:Remove()
|
||||
|
||||
client.ixContainerCP = nil
|
||||
client.ixContainerRotationAngles = nil
|
||||
elseif (containerInfo) then
|
||||
client.ixContainerRotationAngles = client.ixContainerRotationAngles or Angle(0, 0, 0)
|
||||
|
||||
-- reset angles
|
||||
if (input.IsKeyDown(KEY_R)) then
|
||||
client.ixContainerRotationAngles:Zero()
|
||||
end
|
||||
|
||||
-- horizontally
|
||||
if (input.IsKeyDown(KEY_LEFT)) then
|
||||
client.ixContainerRotationAngles:Add(Angle(0, -1, 0))
|
||||
end
|
||||
if (input.IsKeyDown(KEY_RIGHT)) then
|
||||
client.ixContainerRotationAngles:Add(Angle(0, 1, 0))
|
||||
end
|
||||
|
||||
-- vertically
|
||||
if (input.IsKeyDown(KEY_UP)) then
|
||||
client.ixContainerRotationAngles:Add(Angle(0, 0, 1))
|
||||
end
|
||||
if (input.IsKeyDown(KEY_DOWN)) then
|
||||
client.ixContainerRotationAngles:Add(Angle(0, 0, -1))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerBindPress(client, bind)
|
||||
local containerInfo = client and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (containerInfo and IsValid(client.ixContainerCP) and arrowBinds[bind]) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:HUDPaint()
|
||||
local client = LocalPlayer()
|
||||
local containerInfo = client and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (containerInfo) then
|
||||
local scrW, scrH = ScrW(), ScrH()
|
||||
local halfW = scrW * 0.5
|
||||
|
||||
draw.TextShadow({
|
||||
text = string.format("CONTAINER \"%s\" PLACEMENT UI", containerInfo.name),
|
||||
font = "HUDFontLarge",
|
||||
pos = {halfW, scrH * 0.18},
|
||||
xalign = TEXT_ALIGN_CENTER,
|
||||
yalign = TEXT_ALIGN_CENTER,
|
||||
color = colorYellow
|
||||
}, 1)
|
||||
|
||||
surface.SetFont(actionsFont)
|
||||
local actionMaxW, actionH = surface.GetTextSize("L/R ARROWS - ROTATE HORIZONTALLY")
|
||||
local actionX = halfW - actionMaxW * 0.5
|
||||
local actionsY = scrH * 0.88
|
||||
|
||||
-- I could've used loop here, but that would mean creating 2 of them
|
||||
draw.TextShadow({
|
||||
text = "LMB - PLACE",
|
||||
font = actionsFont,
|
||||
pos = {actionX, actionsY},
|
||||
xalign = TEXT_ALIGN_LEFT,
|
||||
yalign = TEXT_ALIGN_CENTER
|
||||
}, 1)
|
||||
|
||||
draw.TextShadow({
|
||||
text = "RMB - CANCEL",
|
||||
font = actionsFont,
|
||||
pos = {actionX, actionsY + actionH},
|
||||
xalign = TEXT_ALIGN_LEFT,
|
||||
yalign = TEXT_ALIGN_CENTER
|
||||
}, 1)
|
||||
|
||||
draw.TextShadow({
|
||||
text = "R - RESET ANGLES",
|
||||
font = actionsFont,
|
||||
pos = {actionX, actionsY + actionH * 2},
|
||||
xalign = TEXT_ALIGN_LEFT,
|
||||
yalign = TEXT_ALIGN_CENTER
|
||||
}, 1)
|
||||
|
||||
draw.TextShadow({
|
||||
text = "L/R ARROWS - ROTATE HORIZONTALLY",
|
||||
font = actionsFont,
|
||||
pos = {actionX, actionsY + actionH * 3},
|
||||
xalign = TEXT_ALIGN_LEFT,
|
||||
yalign = TEXT_ALIGN_CENTER
|
||||
}, 1)
|
||||
|
||||
draw.TextShadow({
|
||||
text = "U/D ARROWS - ROTATE VERTICALLY",
|
||||
font = actionsFont,
|
||||
pos = {actionX, actionsY + actionH * 4},
|
||||
xalign = TEXT_ALIGN_LEFT,
|
||||
yalign = TEXT_ALIGN_CENTER
|
||||
}, 1)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,113 @@
|
||||
--[[
|
||||
| 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
|
||||
|
||||
ITEM.name = "Container"
|
||||
ITEM.description = "Container."
|
||||
ITEM.category = "Containers"
|
||||
ITEM.model = "models/props_junk/wood_crate001a.mdl"
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
|
||||
ITEM.colorAppendix = {["red"] = "Contact an admin to convert this into a container. Requires a group of minimum 5 members.", ["blue"] = "We have a limit of 2 small OR 1 medium personal container per player.\nGroups may also get 3 large containers."}
|
||||
ITEM.maxStackSize = 1
|
||||
|
||||
if (CLIENT) then
|
||||
function ITEM:PaintOver(item, width, height)
|
||||
local client = LocalPlayer()
|
||||
local info = client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (info and info.itemID == item.id) then
|
||||
surface.SetDrawColor(110, 255, 110, 100)
|
||||
surface.DrawRect(width - 14, height - 14, 8, 8)
|
||||
end
|
||||
end
|
||||
else
|
||||
function ITEM:OnTransferred(oldInv, newInv)
|
||||
local oldOwner = oldInv.GetOwner and oldInv:GetOwner() or nil
|
||||
local oldOwnerInfo = IsValid(oldOwner) and oldOwner:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (oldOwnerInfo and oldOwnerInfo.itemID == self.id) then
|
||||
oldOwner:SetLocalVar("containerToPlaceInfo", nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ITEM:Hook("drop", function(item)
|
||||
local client = item.player
|
||||
local info = IsValid(client) and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (info and info.itemID == item.id) then
|
||||
client:SetLocalVar("containerToPlaceInfo", nil)
|
||||
end
|
||||
end)
|
||||
|
||||
ITEM.functions.Place = {
|
||||
name = "Place",
|
||||
tip = "placeTip",
|
||||
icon = "icon16/arrow_down.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local entity = item.entity
|
||||
|
||||
if (IsValid(entity)) then
|
||||
local clientPos = client:GetPos()
|
||||
local entityPos = entity:GetPos()
|
||||
|
||||
if (clientPos:DistToSqr(entityPos) <= 100 * 100) then
|
||||
PLUGIN:CreateContainer(client, entity:GetPos(), entity:GetAngles(), item.model, item.name, item.invType)
|
||||
|
||||
return
|
||||
else
|
||||
client:Notify("Сontainer item is too far!")
|
||||
end
|
||||
else
|
||||
local info = {}
|
||||
info.itemID = item.id
|
||||
info.name = item.name
|
||||
info.model = item.model
|
||||
|
||||
client:SetLocalVar("containerToPlaceInfo", info)
|
||||
client:SelectWeapon("ix_keys")
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
return isstring(item.model) and isstring(item.invType) and
|
||||
IsValid(client) and !client:GetLocalVar("containerToPlaceInfo") and
|
||||
hook.Run("CanPlayerEquipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
|
||||
ITEM.functions.PlaceCancel = {
|
||||
name = "Cancel Place",
|
||||
tip = "placeCancelTip",
|
||||
icon = "icon16/arrow_up.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
client:SetLocalVar("containerToPlaceInfo", nil)
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
local info = IsValid(client) and client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
return isstring(item.model) and isstring(item.invType) and
|
||||
!IsValid(item.entity) and info != nil and info.itemID == item.id and
|
||||
hook.Run("CanPlayerUnequipItem", client, item) != false
|
||||
end
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
--[[
|
||||
| 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 entityMeta = FindMetaTable("Entity")
|
||||
|
||||
function entityMeta:IsInSolidEnviromentOrFloating()
|
||||
local pos = self:GetPos()
|
||||
local mins, maxs = self:GetRotatedAABB(self:OBBMins(), self:OBBMaxs())
|
||||
|
||||
-- check if entity is inside something
|
||||
local traceHull = util.TraceHull({
|
||||
start = pos,
|
||||
endpos = pos,
|
||||
maxs = maxs,
|
||||
mins = mins
|
||||
})
|
||||
|
||||
if (traceHull.StartSolid) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- then check if it's not floating around
|
||||
local traceHull2 = util.TraceHull({
|
||||
start = pos,
|
||||
endpos = pos + Vector(0, 0, -2),
|
||||
maxs = Vector(0, 0, maxs.z),
|
||||
mins = Vector(0, 0, mins.z),
|
||||
filter = self
|
||||
})
|
||||
|
||||
if (!traceHull2.Hit) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
32
gamemodes/ixhl2rp/plugins/container_placement/sh_hooks.lua
Normal file
32
gamemodes/ixhl2rp/plugins/container_placement/sh_hooks.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
function PLUGIN:InitializedPlugins()
|
||||
for model, data in pairs(ix.container.stored) do
|
||||
model = model:lower()
|
||||
local invType = "container:" .. model
|
||||
|
||||
if (ix.item.inventoryTypes[invType]) then
|
||||
local uniqueID = string.Replace(data.name:lower(), " ", "_")
|
||||
ix.item.Register(uniqueID, "base_containers", false, nil, true)
|
||||
|
||||
if (ix.item.list[uniqueID]) then
|
||||
ix.item.list[uniqueID].name = data.name
|
||||
ix.item.list[uniqueID].description = data.description
|
||||
ix.item.list[uniqueID].model = Model(model)
|
||||
ix.item.list[uniqueID].width = math.max(1, math.floor(data.width * 0.5))
|
||||
ix.item.list[uniqueID].height = math.max(1, math.floor(data.height * 0.5))
|
||||
|
||||
ix.item.list[uniqueID].invType = invType
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
gamemodes/ixhl2rp/plugins/container_placement/sh_plugin.lua
Normal file
20
gamemodes/ixhl2rp/plugins/container_placement/sh_plugin.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
PLUGIN.name = "Container Placement"
|
||||
PLUGIN.author = "LegAz"
|
||||
PLUGIN.description = "Allow players to place containers down on their own."
|
||||
|
||||
ix.util.Include("meta/sh_entity.lua")
|
||||
|
||||
ix.util.Include("cl_plugin.lua")
|
||||
ix.util.Include("sh_hooks.lua")
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
100
gamemodes/ixhl2rp/plugins/container_placement/sv_plugin.lua
Normal file
100
gamemodes/ixhl2rp/plugins/container_placement/sv_plugin.lua
Normal 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
|
||||
|
||||
util.AddNetworkString("ixPlaceContainer")
|
||||
|
||||
net.Receive("ixPlaceContainer", function(_, client)
|
||||
local realTime = RealTime()
|
||||
|
||||
if ((client.ixNextContainerPlacement or 0) <= realTime) then
|
||||
local containerInfo = client:GetLocalVar("containerToPlaceInfo")
|
||||
|
||||
if (containerInfo) then
|
||||
local bResponse = net.ReadBool()
|
||||
|
||||
if (bResponse) then
|
||||
local pos = net.ReadVector()
|
||||
local angles = net.ReadAngle()
|
||||
|
||||
-- i honestly haven't found any other way to check pos and angles receiven from client
|
||||
local dummy = ents.Create("prop_dynamic_override")
|
||||
dummy:SetMoveType(MOVETYPE_NONE)
|
||||
dummy:SetModel(containerInfo.model)
|
||||
dummy:SetPos(pos)
|
||||
dummy:SetAngles(angles)
|
||||
dummy:AddEFlags(EF_NODRAW)
|
||||
dummy:Spawn()
|
||||
dummy:Activate()
|
||||
|
||||
if (!dummy:IsInSolidEnviromentOrFloating()) then
|
||||
PLUGIN:CreateContainer(client, pos, angles, containerInfo.model, containerInfo.name, "container:" .. containerInfo.model)
|
||||
|
||||
ix.item.instances[containerInfo.itemID]:Remove()
|
||||
end
|
||||
|
||||
dummy:Remove()
|
||||
end
|
||||
|
||||
client:SetLocalVar("containerToPlaceInfo", nil)
|
||||
end
|
||||
|
||||
-- probably should be higher
|
||||
client.ixNextContainerPlacement = realTime + 2
|
||||
end
|
||||
end)
|
||||
|
||||
-- function (almost) identical to the one in containers plugin
|
||||
function PLUGIN:CreateContainer(client, pos, angles, model, name, invType)
|
||||
local container = ents.Create("ix_wncontainer")
|
||||
container:SetPos(pos)
|
||||
container:SetAngles(angles)
|
||||
container:SetModel(model)
|
||||
container:Spawn()
|
||||
container:DropToFloor()
|
||||
|
||||
-- we don't want our newely created container to be moved around
|
||||
local physObj = container:GetPhysicsObject()
|
||||
|
||||
if (IsValid(physObj)) then
|
||||
physObj:EnableMotion(false)
|
||||
physObj:Sleep()
|
||||
end
|
||||
|
||||
ix.inventory.New(0, invType, function(inventory)
|
||||
inventory.vars.isBag = true
|
||||
inventory.vars.isContainer = true
|
||||
inventory.vars.entity = container
|
||||
|
||||
if (IsValid(container)) then
|
||||
container:SetInventory(inventory)
|
||||
|
||||
if (ix.saveEnts) then
|
||||
ix.saveEnts:SaveEntity(container)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
ix.log.Add(client, "containerSpawned", name)
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerSwitchWeapon(client, _, newWeapon)
|
||||
if (client:GetLocalVar("containerToPlaceInfo") and newWeapon:GetClass() != "ix_keys") then
|
||||
client:SetLocalVar("containerToPlaceInfo", nil)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnPlayerRestricted(client)
|
||||
if (client:GetLocalVar("containerToPlaceInfo")) then
|
||||
client:SetLocalVar("containerToPlaceInfo", nil)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user