mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 21:53:46 +03:00
Upload
This commit is contained in:
105
gamemodes/ixhl2rp/plugins/wn_holditems/meta/sh_item.lua
Normal file
105
gamemodes/ixhl2rp/plugins/wn_holditems/meta/sh_item.lua
Normal file
@@ -0,0 +1,105 @@
|
||||
--[[
|
||||
| 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 ITEM = ix.meta.item
|
||||
|
||||
function ITEM:IsHoldable()
|
||||
return ix.holdItems:CanHold(self.uniqueID) or self.holdData
|
||||
end
|
||||
|
||||
function ITEM:InitializeHoldable()
|
||||
if self:IsHoldable() then
|
||||
self.functions.hold = {
|
||||
name = "Take this item in your hand",
|
||||
tip = "You can visually display this item.",
|
||||
icon = "icon16/bullet_green.png",
|
||||
--[[isMulti = true,
|
||||
multiOptions = function(item, player)
|
||||
if !item.useAllHoldTypes then
|
||||
return {
|
||||
{
|
||||
name = ix.holdItems.holdTypes["rhand"].name,
|
||||
data = ix.holdItems.holdTypes["rhand"]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
local holdTypes = {}
|
||||
for hID, hType in pairs(ix.holdItems.holdTypes) do
|
||||
holdTypes[#holdTypes + 1] = {
|
||||
name = hType.name,
|
||||
data = hType
|
||||
}
|
||||
end
|
||||
|
||||
return holdTypes
|
||||
end,--]]
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local entity = item.entity
|
||||
|
||||
local holdTypeData = item.holdType or ix.holdItems.holdTypes["rhand"]
|
||||
|
||||
if (!IsValid(client) or IsValid(entity) or !client:Alive()) then return false end
|
||||
|
||||
if ix.holdItems.forbiddenFactions[client:Team()] then
|
||||
client:NotifyLocalized("Your faction can't hold items.")
|
||||
return
|
||||
end
|
||||
|
||||
if client:GetActiveWeapon():GetClass() != "ix_hands" then
|
||||
client:NotifyLocalized("You holding something in hands already.")
|
||||
return false
|
||||
end
|
||||
|
||||
if client.ixHoldingItemEnt and IsValid(client.ixHoldingItemEnt) then
|
||||
client:NotifyLocalized("You're already holding an item!")
|
||||
return false
|
||||
end
|
||||
|
||||
--[[if !item.useAllHoldTypes and holdTypeData.id != "rhand" then
|
||||
client:NotifyLocalized("You can hold this item only in your right hand.")
|
||||
return false
|
||||
end--]]
|
||||
|
||||
client:TakeHoldableItem(item, ix.holdItems:CanHold(item.uniqueID) and ix.holdItems:CanHold(item.uniqueID).holdData or item.holdData, holdTypeData)
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
local entity = item.entity
|
||||
|
||||
return IsValid(client) and !IsValid(entity) and !item:GetData("holdBy", false) and !ix.holdItems.forbiddenFactions[client:Team()] and true or false
|
||||
end
|
||||
}
|
||||
self.functions.hputback = {
|
||||
name = "Put this item back",
|
||||
tip = "Stop visually displaying this item.",
|
||||
icon = "icon16/bullet_red.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local entity = item.entity
|
||||
|
||||
if (!IsValid(client) or IsValid(entity)) then return false end
|
||||
|
||||
client:PutHoldableItemBack(item)
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
local client = item.player
|
||||
local entity = item.entity
|
||||
|
||||
return IsValid(client) and !IsValid(entity) and item:GetData("holdBy", false) and IsValid(item:GetData("holdBy", false)) and true or false
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
98
gamemodes/ixhl2rp/plugins/wn_holditems/meta/sv_player.lua
Normal file
98
gamemodes/ixhl2rp/plugins/wn_holditems/meta/sv_player.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
--[[
|
||||
| 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 playerMeta = FindMetaTable("Player")
|
||||
|
||||
function playerMeta:TakeHoldableItem(item, itemHoldData, holdTypeData)
|
||||
if (self.ixHoldingItemEnt) then
|
||||
if !IsValid(self.ixHoldingItemEnt) then
|
||||
self.ixHoldingItemEnt = nil
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local inv = self:GetCharacter():GetInventory()
|
||||
|
||||
local holdableItem = ents.Create("prop_physics")
|
||||
holdableItem:SetModel(item:GetModel())
|
||||
|
||||
local pos = self:GetAttachment(self:LookupAttachment(holdTypeData["attachment"])).Pos
|
||||
pos = pos + (self:GetUp() * -1)
|
||||
pos = pos + (self:GetForward() * itemHoldData.vectorOffset.forward) + (self:GetUp() * itemHoldData.vectorOffset.up) + (self:GetRight() * itemHoldData.vectorOffset.right)
|
||||
|
||||
local ang = self:GetAttachment(self:LookupAttachment(holdTypeData["attachment"])).Ang
|
||||
ang:RotateAroundAxis( ang:Forward(), itemHoldData.angleOffset.forward)
|
||||
ang:RotateAroundAxis( ang:Right(), itemHoldData.angleOffset.right)
|
||||
ang:RotateAroundAxis( ang:Up(), itemHoldData.angleOffset.up)
|
||||
|
||||
holdableItem:SetPos(pos)
|
||||
holdableItem:SetAngles(ang)
|
||||
holdableItem:Spawn()
|
||||
holdableItem:Activate()
|
||||
holdableItem:SetSolid(SOLID_NONE)
|
||||
holdableItem:PhysicsInit(SOLID_NONE)
|
||||
holdableItem:SetParent(self, self:LookupAttachment(holdTypeData["attachment"]))
|
||||
holdableItem.item = item
|
||||
holdableItem:CallOnRemove("ixHoldable", function(s)
|
||||
s:GetParent().ixHoldingItemEnt = nil
|
||||
s:GetParent():SetLocalVar("ixHoldableItem", nil)
|
||||
|
||||
if s.item.GetID and ix.item.instances[s.item:GetID()] then
|
||||
s.item:SetData("holdBy", nil)
|
||||
end
|
||||
end)
|
||||
|
||||
self:SetLocalVar("ixHoldableItem", holdableItem)
|
||||
|
||||
local timerID = "ixHoldablesCheckItem" .. holdableItem:EntIndex()
|
||||
|
||||
timer.Create(timerID, 1, 0, function()
|
||||
if !IsValid(holdableItem) then
|
||||
timer.Remove(timerID)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if !holdableItem:GetParent():Alive() then
|
||||
holdableItem:Remove()
|
||||
|
||||
timer.Remove(timerID)
|
||||
return
|
||||
end
|
||||
|
||||
local lookingFor = inv:GetItemsByUniqueID(item.uniqueID)
|
||||
local found = false
|
||||
for _, lItem in pairs(lookingFor) do
|
||||
if lItem:GetData("holdBy", false) then
|
||||
found = true
|
||||
continue
|
||||
end
|
||||
end
|
||||
|
||||
if !found then
|
||||
holdableItem:Remove()
|
||||
|
||||
timer.Remove(timerID)
|
||||
end
|
||||
end)
|
||||
|
||||
self.ixHoldingItemEnt = holdableItem
|
||||
item:SetData("holdBy", self)
|
||||
end
|
||||
|
||||
function playerMeta:PutHoldableItemBack(item)
|
||||
if (self.ixHoldingItemEnt and IsValid(self.ixHoldingItemEnt)) then
|
||||
self.ixHoldingItemEnt:Remove()
|
||||
item:SetData("holdBy", nil)
|
||||
else
|
||||
item:SetData("holdBy", nil)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user