mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 13:53:45 +03:00
Upload
This commit is contained in:
287
gamemodes/helix/plugins/needs/items/base/sh_food.lua
Normal file
287
gamemodes/helix/plugins/needs/items/base/sh_food.lua
Normal file
@@ -0,0 +1,287 @@
|
||||
--[[
|
||||
| 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/
|
||||
--]]
|
||||
|
||||
|
||||
ITEM.name = "Consumable Base"
|
||||
ITEM.model = Model("models/props_junk/garbage_takeoutcarton001a.mdl")
|
||||
ITEM.description = "A base for consumables."
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.category = "Consumable"
|
||||
|
||||
ITEM.useSound = {"npc/barnacle/barnacle_crunch3.wav", "npc/barnacle/barnacle_crunch2.wav"}
|
||||
|
||||
ITEM.hunger = 0
|
||||
ITEM.thirst = 0
|
||||
ITEM.health = 0
|
||||
ITEM.damage = 0
|
||||
ITEM.spoilTime = 14
|
||||
|
||||
ITEM.colorAppendix = {}
|
||||
|
||||
ITEM.base = "base_stackable"
|
||||
ITEM.maxStackSize = 1
|
||||
|
||||
function ITEM:GetName()
|
||||
if (self:GetSpoiled()) then
|
||||
local spoilText = self.spoilText or "Tarihi Geçmiş"
|
||||
return spoilText.." "..self.name
|
||||
end
|
||||
|
||||
return self.name
|
||||
end
|
||||
|
||||
function ITEM:GetDescription()
|
||||
local description = {self.description}
|
||||
if (!self:GetSpoiled() and self:GetData("spoilTime")) then
|
||||
local spoilTime = math.floor((self:GetData("spoilTime") - os.time()) / 60)
|
||||
local text = " minute"
|
||||
if (spoilTime > 60) then
|
||||
text = " saat"
|
||||
spoilTime = math.floor(spoilTime / 60)
|
||||
end
|
||||
|
||||
if (spoilTime > 24) then
|
||||
text = " gün"
|
||||
spoilTime = math.floor(spoilTime / 24)
|
||||
end
|
||||
|
||||
-- not necessary in Turkish
|
||||
-- if (spoilTime > 1) then
|
||||
-- text = text.."s"
|
||||
-- end
|
||||
|
||||
description[#description + 1] = "\n"..spoilTime..text.." içinde tarihi geçecek."
|
||||
end
|
||||
|
||||
return table.concat(description, "")
|
||||
end
|
||||
|
||||
function ITEM:GetBoostAppend()
|
||||
local boostAppend = {}
|
||||
if (self.boosts) then
|
||||
boostAppend[#boostAppend + 1] = "LONG-TERM BOOSTS:\n"
|
||||
|
||||
if (self.boosts.strength) then
|
||||
boostAppend[#boostAppend + 1] = string.format("Güç: %d\n", self.boosts.strength)
|
||||
end
|
||||
if (self.boosts.agility) then
|
||||
boostAppend[#boostAppend + 1] = string.format("Çeviklik: %d\n", self.boosts.agility)
|
||||
end
|
||||
if (self.boosts.intelligence) then
|
||||
boostAppend[#boostAppend + 1] = string.format("Akıl: %d\n", self.boosts.intelligence)
|
||||
end
|
||||
if (self.boosts.perception) then
|
||||
boostAppend[#boostAppend + 1] = string.format("Algı: %d", self.boosts.perception)
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(boostAppend, "")
|
||||
end
|
||||
|
||||
function ITEM:GetColorAppendix()
|
||||
return {["yellow"] = self:GetBoostAppend()}
|
||||
end
|
||||
|
||||
function ITEM:GetSpoiled()
|
||||
local spoilTime = self:GetData("spoilTime")
|
||||
if (!spoilTime) then
|
||||
return false
|
||||
end
|
||||
|
||||
return os.time() > spoilTime
|
||||
end
|
||||
|
||||
function ITEM:OnInstanced()
|
||||
if (self.spoil and !self:GetData("spoilTime")) then
|
||||
self:SetData("spoilTime", os.time() + 24 * 60 * 60 * self.spoilTime)
|
||||
end
|
||||
|
||||
if (!self:GetData("stack")) then
|
||||
self:SetStack(self:GetStackSize())
|
||||
end
|
||||
end
|
||||
|
||||
ITEM.functions.Consume = {
|
||||
name = "Tüket",
|
||||
icon = "icon16/user.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local character = item.player:GetCharacter()
|
||||
local bSpoiled = item:GetSpoiled()
|
||||
|
||||
if (item.damage > 0) then
|
||||
client:TakeDamage(item.damage, client, client)
|
||||
end
|
||||
|
||||
if (item.instantHeal) then
|
||||
client:SetHealth(client:GetMaxHealth())
|
||||
|
||||
character:SetBleedout(-1)
|
||||
|
||||
local healing = character:GetHealing()
|
||||
if (healing and istable(healing) and !table.IsEmpty(healing)) then
|
||||
healing.fakeHealth = 0
|
||||
character:SetHealing("table", healing)
|
||||
end
|
||||
|
||||
character:SetGasPoints(0)
|
||||
|
||||
client:SetLocalVar("stm", 100)
|
||||
|
||||
character:SetGlasses(false)
|
||||
end
|
||||
|
||||
-- Spawn the junk item if it exists
|
||||
if (item:IsSingleItem() and item.junk) then
|
||||
if (!character:GetInventory():Add(item.junk)) then
|
||||
ix.item.Spawn(item.junk, client)
|
||||
end
|
||||
end
|
||||
|
||||
if (item.useSound) then
|
||||
if (istable(item.useSound)) then
|
||||
client:EmitSound(table.Random(item.useSound))
|
||||
else
|
||||
client:EmitSound(item.useSound)
|
||||
end
|
||||
end
|
||||
|
||||
if (!bSpoiled) then
|
||||
if item.OnConsume then
|
||||
item:OnConsume(client, character)
|
||||
end
|
||||
if (item.thirst > 0) then
|
||||
character:SetThirst(math.Clamp(character:GetThirst() - (client:Team() == FACTION_BIRD and item.thirst * 2 or item.thirst), 0, 100))
|
||||
end
|
||||
|
||||
if (item.hunger > 0) then
|
||||
character:SetHunger(math.Clamp(character:GetHunger() - (client:Team() == FACTION_BIRD and item.hunger * 2 or item.hunger), 0, 100))
|
||||
end
|
||||
|
||||
if (item.health > 0) then
|
||||
client:SetHealth(math.Clamp(client:Health() + (client:Team() == FACTION_BIRD and item.health * 2 or item.health), 0, client:GetMaxHealth()))
|
||||
end
|
||||
|
||||
if (item.boosts) then
|
||||
for k, v in pairs(item.boosts) do
|
||||
character:SetSpecialBoost(k, v, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item.
|
||||
ITEM.functions.give = {
|
||||
name = "Karakter üzerinde kullan",
|
||||
tip = "giveTip",
|
||||
icon = "icon16/user_go.png",
|
||||
OnCanRun = function(item)
|
||||
if (item.entity) then return false end
|
||||
|
||||
local trace = item.player:GetEyeTraceNoCursor()
|
||||
local target = trace.Entity
|
||||
if (!IsValid(target)) then
|
||||
return false
|
||||
end
|
||||
|
||||
if (CLIENT and target:GetClass() == "prop_ragdoll") then
|
||||
return true
|
||||
end
|
||||
|
||||
if (target:GetClass() == "prop_ragdoll" and IsValid(target.ixPlayer)) then
|
||||
target = target.ixPlayer
|
||||
end
|
||||
|
||||
if (!target:IsPlayer() or !target:GetCharacter()) then
|
||||
return false
|
||||
end
|
||||
|
||||
if (target:Health() >= target:GetMaxHealth()) then
|
||||
local targetChar = target:GetCharacter()
|
||||
if (targetChar:GetHealing("fakeHealth") == 0 and targetChar:GetBleedout() == -1) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end,
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
local character = item.player:GetCharacter()
|
||||
local bSpoiled = item:GetSpoiled()
|
||||
|
||||
local trace = item.player:GetEyeTraceNoCursor()
|
||||
local target = trace.Entity
|
||||
if (target:GetClass() == "prop_ragdoll" and IsValid(target.ixPlayer)) then
|
||||
target = target.ixPlayer
|
||||
end
|
||||
|
||||
local targetChar = target:GetCharacter()
|
||||
|
||||
if (item.instantHeal) then
|
||||
target:SetHealth(target:GetMaxHealth())
|
||||
|
||||
targetChar:SetBleedout(-1)
|
||||
|
||||
local healing = targetChar:GetHealing()
|
||||
if (healing and istable(healing) and !table.IsEmpty(healing)) then
|
||||
healing.fakeHealth = 0
|
||||
targetChar:SetHealing("table", healing)
|
||||
end
|
||||
|
||||
targetChar:SetGasPoints(0)
|
||||
|
||||
target:SetLocalVar("stm", 100)
|
||||
|
||||
targetChar:SetGlasses(false)
|
||||
end
|
||||
|
||||
-- Spawn the junk item if it exists
|
||||
if (item:IsSingleItem() and item.junk) then
|
||||
if (!character:GetInventory():Add(item.junk)) then
|
||||
ix.item.Spawn(item.junk, client)
|
||||
end
|
||||
end
|
||||
|
||||
if (item.useSound) then
|
||||
if (istable(item.useSound)) then
|
||||
target:EmitSound(table.Random(item.useSound))
|
||||
else
|
||||
target:EmitSound(item.useSound)
|
||||
end
|
||||
end
|
||||
|
||||
if (!bSpoiled) then
|
||||
if item.OnConsume then
|
||||
item:OnConsume(client, character)
|
||||
end
|
||||
|
||||
if (item.thirst > 0) then
|
||||
targetChar:SetThirst(math.Clamp(targetChar:GetThirst() - (target:Team() == FACTION_BIRD and item.thirst * 2 or item.thirst), 0, 100))
|
||||
end
|
||||
|
||||
if (item.hunger > 0) then
|
||||
targetChar:SetHunger(math.Clamp(targetChar:GetHunger() - (target:Team() == FACTION_BIRD and item.hunger * 2 or item.hunger), 0, 100))
|
||||
end
|
||||
|
||||
if (item.health > 0) then
|
||||
target:SetHealth(math.Clamp(target:Health() + (target:Team() == FACTION_BIRD and item.health * 2 or item.health), 0, target:GetMaxHealth()))
|
||||
end
|
||||
|
||||
if (item.boosts) then
|
||||
for k, v in pairs(item.boosts) do
|
||||
targetChar:SetSpecialBoost(k, v, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
151
gamemodes/helix/plugins/needs/sh_plugin.lua
Normal file
151
gamemodes/helix/plugins/needs/sh_plugin.lua
Normal file
@@ -0,0 +1,151 @@
|
||||
--[[
|
||||
| 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 = "Needs"
|
||||
PLUGIN.author = "Gr4Ss"
|
||||
PLUGIN.description = "Implements needs."
|
||||
|
||||
ix.char.RegisterVar("hunger", {
|
||||
field = "hunger",
|
||||
fieldType = ix.type.number,
|
||||
default = 0,
|
||||
isLocal = true,
|
||||
bNoDisplay = true
|
||||
})
|
||||
|
||||
ix.char.RegisterVar("thirst", {
|
||||
field = "thirst",
|
||||
fieldType = ix.type.number,
|
||||
default = 0,
|
||||
isLocal = true,
|
||||
bNoDisplay = true
|
||||
})
|
||||
|
||||
CAMI.RegisterPrivilege({
|
||||
Name = "Helix - Manage Needs",
|
||||
MinAccess = "admin"
|
||||
})
|
||||
|
||||
ix.config.Add("killOnMaxNeeds", false, "Enable players being killed when reaching max hunger or thirst", nil, {
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.config.Add("needsPermaKill", false, "Enable players being perma-killed when reaching max hunger or thirst. Only works if 'killOnMaxNeeds' is enabled too!", nil, {
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.config.Add("needsDeathDamage", 2, "The amount of damage to apply to players that are dying from max needs.", nil, {
|
||||
data = {min = 1, max = 5},
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.config.Add("hungerHours", 6, "How many hours it takes for a player to gain 60 hunger", nil, {
|
||||
data = {min = 1, max = 24},
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.config.Add("thirstHours", 4, "How many hours it takes for a player to gain 60 thirst", nil, {
|
||||
data = {min = 1, max = 24},
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.config.Add("needsTickTime", 300, "How many seconds between each time a player's needs are calculated", nil, {
|
||||
data = {min = 60, max = 300},
|
||||
category = "needs"
|
||||
})
|
||||
|
||||
ix.util.Include("sv_hooks.lua")
|
||||
|
||||
ix.command.Add("CharSetHunger", {
|
||||
description = "Set character's hunger",
|
||||
privilege = "Manage Needs",
|
||||
arguments = {
|
||||
ix.type.character,
|
||||
bit.bor(ix.type.number, ix.type.optional),
|
||||
},
|
||||
OnRun = function(self, client, character, level)
|
||||
character:SetHunger(level or 0)
|
||||
client:Notify(character:GetName().."'s hunger was set to "..(level or 0))
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("CharSetThirst", {
|
||||
description = "Set character's thirst",
|
||||
privilege = "Manage Needs",
|
||||
arguments = {
|
||||
ix.type.character,
|
||||
bit.bor(ix.type.number, ix.type.optional),
|
||||
},
|
||||
OnRun = function(self, client, character, level)
|
||||
character:SetThirst(level or 0)
|
||||
client:Notify(character:GetName().."'s thirst was set to "..(level or 0))
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("CharSetNeeds", {
|
||||
description = "Set character's thirst",
|
||||
privilege = "Manage Needs",
|
||||
arguments = {
|
||||
ix.type.character,
|
||||
bit.bor(ix.type.number, ix.type.optional),
|
||||
},
|
||||
OnRun = function(self, client, character, level)
|
||||
character:SetThirst(level or 0)
|
||||
character:SetHunger(level or 0)
|
||||
client:Notify(character:GetName().."'s needs were set to "..(level or 0))
|
||||
end
|
||||
})
|
||||
|
||||
if (CLIENT) then
|
||||
local thirstIcon = ix.util.GetMaterial("willardnetworks/hud/thirst.png")
|
||||
local foodIcon = ix.util.GetMaterial("willardnetworks/hud/food.png")
|
||||
|
||||
function PLUGIN:DrawBars(client, character, alwaysShow, minimalShow, DrawBar)
|
||||
local faction = ix.faction.Get(client:Team())
|
||||
if (!faction) then return end
|
||||
if (faction.noNeeds) then return end
|
||||
|
||||
if (alwaysShow or character:GetHunger() > 20) then
|
||||
if (alwaysShow or !minimalShow or character:GetHunger() > 40) then
|
||||
DrawBar(foodIcon, (100 - character:GetHunger()) / 100)
|
||||
end
|
||||
end
|
||||
if (alwaysShow or character:GetThirst() > 20) then
|
||||
if (alwaysShow or !minimalShow or character:GetThirst() > 40) then
|
||||
DrawBar(thirstIcon, (100 - character:GetThirst()) / 100)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:RenderScreenspaceEffects()
|
||||
if (ix.option.Get("ColorModify", true)) then
|
||||
local character = LocalPlayer():GetCharacter()
|
||||
|
||||
if (character) then
|
||||
local needsSum = character:GetHunger() + character:GetThirst()
|
||||
|
||||
if (needsSum >= 100) then
|
||||
DrawColorModify({
|
||||
["$pp_colour_addr"] = 0,
|
||||
["$pp_colour_addg"] = 0,
|
||||
["$pp_colour_addb"] = 0,
|
||||
["$pp_colour_brightness"] = 0,
|
||||
["$pp_colour_contrast"] = 1,
|
||||
["$pp_colour_colour"] = 1 - math.Remap(math.min(200, needsSum), 100, 200, 0, 0.9),
|
||||
["$pp_colour_mulr"] = 0,
|
||||
["$pp_colour_mulg"] = 0,
|
||||
["$pp_colour_mulb"] = 0
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
121
gamemodes/helix/plugins/needs/sv_hooks.lua
Normal file
121
gamemodes/helix/plugins/needs/sv_hooks.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
--[[
|
||||
| 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
|
||||
local ix = ix
|
||||
local math = math
|
||||
|
||||
function PLUGIN:PlayerLoadedCharacter(client, character, lastChar)
|
||||
local uniqueID = "ixNeeds" .. client:SteamID64()
|
||||
|
||||
if (timer.Exists(uniqueID)) then
|
||||
timer.Remove(uniqueID)
|
||||
end
|
||||
|
||||
timer.Create(uniqueID, ix.config.Get("needsTickTime", 300), 0, function()
|
||||
if (!IsValid(client)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (!client:Alive()) then return end
|
||||
|
||||
if (hook.Run("ShouldCalculatePlayerNeeds", client, character) == false) then
|
||||
return
|
||||
end
|
||||
|
||||
local scale = 1
|
||||
local count = math.max(character:GetInventory():GetFilledSlotCount(), 0) / 30
|
||||
local vcsqr = client:GetVelocity():LengthSqr()
|
||||
local walkSpeed = ix.config.Get("walkSpeed")
|
||||
|
||||
if ( client:KeyDown(IN_SPEED) and !client:InVehicle() and (vcsqr >= (walkSpeed * walkSpeed))) then
|
||||
scale = scale + count
|
||||
elseif (vcsqr > 0) then
|
||||
scale = scale + count * 0.3
|
||||
else
|
||||
scale = scale + count * 0.1
|
||||
end
|
||||
|
||||
if (client:Health() < client:GetMaxHealth()) then
|
||||
scale = scale + math.Remap(client:Health() / client:GetMaxHealth(), 1, 0, 0, 0.4)
|
||||
end
|
||||
|
||||
local tickTime = ix.config.Get("needsTickTime", 300)
|
||||
|
||||
local hunger = math.Clamp(character:GetHunger() + 60 * scale * tickTime / (3600 * ix.config.Get("hungerHours", 6)), 0, 100)
|
||||
local thirst = math.Clamp(character:GetThirst() + 60 * scale * tickTime / (3600 * ix.config.Get("thirstHours", 4)), 0, 100)
|
||||
|
||||
character:SetHunger(hunger)
|
||||
character:SetThirst(thirst)
|
||||
|
||||
if (ix.config.Get("killOnMaxNeeds", false)) then
|
||||
local damage = 0
|
||||
if (hunger >= 100 and thirst >= 100) then
|
||||
damage = ix.config.Get("needsDeathDamage") * 1.5
|
||||
elseif (hunger >= 100 or thirst >= 100) then
|
||||
damage = ix.config.Get("needsDeathDamage")
|
||||
end
|
||||
|
||||
if (damage > 0) then
|
||||
character.ixNeedsDamageScale = (character.ixNeedsDamageScale or 0.9) + 0.1
|
||||
damage = damage * character.ixNeedsDamageScale
|
||||
|
||||
if (!character.ixNeedsWarningGiven) then
|
||||
character.ixNeedsWarningGiven = true
|
||||
client:Notify("Açlık ve/veya susuzluktan yavaşça ölüyorsunuz. Bir şeyler yiyin/için.")
|
||||
end
|
||||
|
||||
local newHP = client:Health() - damage
|
||||
if (newHP > 0) then
|
||||
client:SetHealth(newHP)
|
||||
return
|
||||
end
|
||||
|
||||
local permakill = ix.config.Get("needsPermaKill")
|
||||
if (permakill) then
|
||||
character:SetHunger(0)
|
||||
character:SetThirst(0)
|
||||
character:SetData("needsPermaKill", true)
|
||||
else
|
||||
character:SetHunger(70)
|
||||
character:SetThirst(70)
|
||||
end
|
||||
|
||||
character.ixNeedsWarningGiven = nil
|
||||
character.ixNeedsDamageScale = nil
|
||||
|
||||
client:Kill()
|
||||
ix.log.Add(client, "qolDeathLog", "starvation/dehydration")
|
||||
else
|
||||
character.ixNeedsWarningGiven = nil
|
||||
character.ixNeedsDamageScale = nil
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function PLUGIN:ShouldCalculatePlayerNeeds(client, character)
|
||||
if (character and client and
|
||||
((client:GetMoveType() == MOVETYPE_NOCLIP and !client:InVehicle()) or client:IsAFK())) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerSpawn(client)
|
||||
local character = client:GetCharacter()
|
||||
if (!character) then return end
|
||||
if (ix.config.Get("needsPermaKill") and character:GetData("needsPermaKill")) then
|
||||
character:SetData("needsPermaKill", nil)
|
||||
character:Ban()
|
||||
else
|
||||
character:SetData("needsPermaKill", nil)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user