Вопрос Игнор фракции для системы голода

  • 31
  • 0
Контакты для связи отсутствуют.
Как в эту систему голода (ниже) добавить игнор определенной фракции? (helix)

код:
PLUGIN.name = "Survival System"
PLUGIN.author = "ZeMysticalTaco"
PLUGIN.description = "A survival system consisting of hunger and thirst."


local speed = 300
local decay = 1

ix.config.Add("hungerDecaySpeed", speed, "Speed at which hunger should decay.", nil, {
    data = {min = 100, max = 600},
    category = "Survival System"
})

ix.config.Add("hungerDecayAmount", decay, "Amount at which hunger should decay", nil, {
    data = {min = 0, max = 5},
    category = "Survival System"
})

ix.config.Add("thirstDecaySpeed", speed, "Speed at which thirst should decay.", nil, {
    data = {min = 100, max = 600},
    category = "Survival System"
})

ix.config.Add("thirstDecayAmount", decay, "Amount at which thirst should decay", nil, {
    data = {min = 0, max = 5},
    category = "Survival System"
})

if SERVER then
    function PLUGIN:OnCharacterCreated(client, character)
        character:SetData("hunger", 100)
        character:SetData("thirst", 100)
    end

    function PLUGIN:PlayerLoadedCharacter(client, character)
        timer.Simple(0.25, function()
            client:SetLocalVar("hunger", character:GetData("hunger", 100))
            client:SetLocalVar("thirst", character:GetData("thirst", 100))
        end)
    end

    function PLUGIN:CharacterPreSave(character)
        local client = character:GetPlayer()

        if (IsValid(client)) then
            character:SetData("hunger", client:GetLocalVar("hunger", 0))
            character:SetData("thirst", client:GetLocalVar("thirst", 0))
        end
    end

    local playerMeta = FindMetaTable("Player")

    function playerMeta:SetHunger(amount)
        local char = self:GetCharacter()

        if (char) then
            char:SetData("hunger", amount)
            self:SetLocalVar("hunger", amount)
        end
    end

    function playerMeta:SetThirst(amount)
        local char = self:GetCharacter()

        if (char) then
            char:SetData("thirst", amount)
            self:SetLocalVar("thirst", amount)
        end
    end

    function playerMeta:TickThirst(amount)
        local char = self:GetCharacter()

        if (char) then
            char:SetData("thirst", char:GetData("thirst", 100) - amount)
            self:SetLocalVar("thirst", char:GetData("thirst", 100) - amount)

            if char:GetData("thirst", 100) < 0 then
                char:SetData("thirst", 0)
                self:SetLocalVar("thirst", 0)
            end
        end
    end

    function playerMeta:TickHunger(amount)
        local char = self:GetCharacter()

        if (char) then
            char:SetData("hunger", char:GetData("hunger", 100) - amount)
            self:SetLocalVar("hunger", char:GetData("hunger", 100) - amount)

            if char:GetData("hunger", 100) < 0 then
                char:SetData("hunger", 0)
                self:SetLocalVar("hunger", 0)
            end
        end
    end

    function PLUGIN:PlayerTick(ply)
        if ply:GetNetVar("hungertick", 0) <= CurTime() then
            ply:SetNetVar("hungertick", ix.config.Get("hunger_decay_speed", 300) + CurTime())
            ply:TickHunger(ix.config.Get("hunger_decay_amount", 1))
        end

        if ply:GetNetVar("thirsttick", 0) <= CurTime() then
            ply:SetNetVar("thirsttick", ix.config.Get("thirst_decay_speed", 300) + CurTime())
            ply:TickThirst(ix.config.Get("thirst_decay_amount", 1))
        end
    end
else
    ix.bar.Add(function()
        local status = ""
        local var = LocalPlayer():GetLocalVar("hunger", 0) / 100

        if var < 0.2 then
            status = ""
        elseif var < 0.4 then
            status = ""
        elseif var < 0.6 then
            status = ""
        elseif var < 0.8 then
            status = ""
        end

        return var, status
    end, Color(171, 67, 40), nil, "hunger")

    ix.bar.Add(function()
        local status = ""
        local var = LocalPlayer():GetLocalVar("thirst", 0) / 100

        if var < 0.2 then
            status = ""
        elseif var < 0.4 then
            status = ""
        elseif var < 0.6 then
            status = ""
        elseif var < 0.8 then
            status = ""
        end

        return var, status
    end, Color(0, 119, 101), nil, "thirst")
end

local playerMeta = FindMetaTable("Player")

function playerMeta:GetHunger()
    local char = self:GetCharacter()

    if (char) then
        return char:GetData("hunger", 100)
    end
end

function playerMeta:GetThirst()
    local char = self:GetCharacter()

    if (char) then
        return char:GetData("thirst", 100)
    end
end

function PLUGIN:AdjustStaminaOffset(client, offset)
    if client:GetHunger() < 15 or client:GetThirst() < 20 then
        return -1
    end
end




--TODO: Populate Hunger and Thirst Items.
--TODO: Drown out colors and restrict stamina restoration for hungry / thirsty players.
local hunger_items = {
    ["cook"] = {
        ["name"]    = "Печенье",
        ["model"]   = "models/hlvr/food/biscuits_box_1.mdl",
        ["desc"]    = "Небольшие мучные кондитерские изделия различной формы и пониженной влажности.",
        ["hunger"]  = 20,
        ["thirst"]  = 0,
    },
    ["kola"] = {
        ["name"]    = "Кока-кола",
        ["model"]   = "models/hlvr/food/can_1.mdl",
        ["desc"]    = "Кока-кола.",
        ["hunger"]  = 0,
        ["thirst"]  = 50,
      },
    ["cookcombine"] = {
        ["name"]    = "Печенье Альянса",
        ["model"]   = "models/hlvr/food/biscuits_box_1_combine.mdl",
        ["desc"]    = "Небольшие мучные кондитерские изделия различной формы и пониженной влажности, производитель печенья - Альянс.",
        ["hunger"]  = 35,
        ["thirst"]  = 0,
    },
    ["cookcombine"] = {
        ["name"]    = "Арбуз",
        ["model"]   = "models/props_junk/watermelon01.mdl",
        ["desc"]    = "арбуз сытный и вкусный.",
        ["hunger"]  = 45,
        ["thirst"]  = 30,
    },
    ["cookcombine"] = {
        ["name"]    = "ХэдКраб",
        ["model"]   = "models/Lamarr.mdl",
        ["desc"]    = "ХэдКраб что вы можете его сьесть?.",
        ["hunger"]  = 30,
        ["thirst"]  = 0,
    },
    ["crackers"] = {
        ["name"]    = "Крэкеры",
        ["model"]   = "models/hlvr/food/crackers_box_1.mdl",
        ["desc"]    = "Хрустящее печенье со слоистой структурой и маслянистой поверхностью.",
        ["hunger"]  = 25,
        ["thirst"]  = 0,
    },
    ["bread"] = {
        ["name"]    = "Хлеб",
        ["model"]   = "models/uu_branded/bioshockinfinite/dread_loaf.mdl",
        ["desc"]    = "Хлебобулочное изделие продолговатой формы.",
        ["hunger"]  = 30,
        ["thirst"]  = 0,
    },
    ["cabbage"] = {
        ["name"]    = "Капуста",
        ["model"]   = "models/hlvr/food/cabbage01a.mdl",
        ["desc"]    = "Двулетнее растение, сельскохозяйственная культура.",
        ["hunger"]  = 35,
        ["thirst"]  = 0,
    },
     ["salat"] = {
        ["name"]    = "Салат",
        ["model"]   = "models/uu_branded/mres/consumables/lag_mre.mdl",
        ["desc"]    = "Смешаные овощи.",
        ["hunger"]  = 50,
        ["thirst"]  = 15,
    },
     ["soup"] = {
        ["name"]    = "Суп",
        ["model"]   = "models/hlvr/food/spam_3.mdl",
        ["desc"]    = "Суп приготовленый своими руками",
        ["hunger"]  = 64,
        ["thirst"]  = 75,
    },
    
    ["teaa"] = {
        ["name"]    = "Чай в банке",
        ["model"]   = "models/uu_branded/bioshockinfinite/xoffee_mug_closed.mdl",
        ["desc"]    = "Чай в банке",
        ["hunger"]  = 0,
        ["thirst"]  = 100,
    },
    
    ["spam"] = {
        ["name"]    = "Овощной суп",
        ["model"]   = "models/hlvr/food/spam_3.mdl",
        ["desc"]    = "Консервированный суп с овощами.",
        ["hunger"]  = 45,
        ["thirst"]  = 0,
        
    },
    ["ration_bar"] = {
        ["name"]    = "Вода Альянса",
        ["model"]   = "models/props_junk/popcan01a.mdl",
        ["desc"]    = "Небольшая бутылка наполненная водой Альянса.",
        ["hunger"]  = 0,
        ["thirst"]  = 45,
    },
    ["potato"] = {
        ["name"]    = "Картошка",
        ["model"]   = "models/uu_branded/bioshockinfinite/hext_potato.mdl",
        ["desc"]    = "Небольшой пакет наполненный картошкой.",
        ["hunger"]  = 25,
        ["thirst"]  = 0,
    },
    ["hotpotato"] = {
        ["name"]    = "Жареная картошка",
        ["model"]   = "models/uu_branded/bioshockinfinite/bag_of_hhips.mdl",
        ["desc"]    = "Небольшой пакет наполненный картошкой.",
        ["hunger"]  = 65,
        ["thirst"]  = 0,
    },
    ["ogurec"] = {
        ["name"]    = "Огурец",
        ["model"]   = "models/hlvr/food/zucchini01a.mdl",
        ["desc"]    = "Огурец.",
        ["hunger"]  = 12,
        ["thirst"]  = 1,
    },
    ["water_vend"] = {
        ["name"]    = "Вода",
        ["model"]   = "models/uu_branded/props_lunk/popcan01a.mdl",
        ["desc"]    = "Синяя банка с водой.",
        ["hunger"]  = 0,
        ["thirst"]  = 65,
        
    },
    ["headkrabicdeadinside"] = {
        ["name"]    = "Сердце хэд-краба",
        ["model"]   = "models/hlvr/food/headcrab_gland.mdl",
        ["desc"]    = "Только для вортов",
        ["hunger"]  = 63,
        ["thirst"]  = 12,
    },
    ["supervoda"] = {
        ["name"]    = "Огромная бутылка воды",
        ["model"]   = "models/props_junk/garbage_plasticbottle003a.mdl",
        ["desc"]    = "Большая бутылочка.",
        ["hunger"]  = 0,
        ["thirst"]  = 89,
    },
    ["cumchatka"] = {
        ["name"]    = "CHATKA",
        ["model"]   = "models/hlvr/food/can_square.mdl",
        ["desc"]    = "",
        ["hunger"]  = 0,
        ["thirst"]  = 34,
    },
    ["levvodka"] = {
        ["name"]    = "Водка",
        ["model"]   = "models/uu_branded/bioshockinfinite/ebsinthebottle.mdl",
        ["desc"]    = "",
        ["hunger"]  = 0,
        ["thirst"]  = 42,
    },
    ["bashkapear"] = {
        ["name"]    = "Пиво",
        ["model"]   = "models/uu_branded/bioshockinfinite/hext_bottle_lager.mdl",
        ["desc"]    = "",
        ["hunger"]  = 0,
        ["thirst"]  = 22,
    },
    ["vinod"] = {
        ["name"]    = "Вино",
        ["model"]   = "models/uu_branded/bioshockinfinite/jin_bottle.mdl",
        ["desc"]    = "",
        ["hunger"]  = 0,
        ["thirst"]  = 32,
    },
    ["can"] = {
        ["name"]    = "Вода",
        ["model"]   = "models/props_junk/popcan01a.mdl",
        ["desc"]    = "Небольшая металлическая банка наполненная водой Альянса.",
        ["hunger"]  = 0,
        ["thirst"]  = 35,
    },
    ["mpfeat1"] = {
        ["name"]    = "Пищевые добавки ГэО",
        ["model"]   = "models/uu_branded/mres/consumables/zag_mre.mdl",
        ["desc"]    = "Небольшая металлическая банка наполненная водой Альянса.",
        ["hunger"]  = 45,
        ["thirst"]  = 15,
    },
    ["citizeneat1"] = {
        ["name"]    = "Пищевые добавки",
        ["model"]   = "models/hlvr/food/ration_bar.mdl",
        ["desc"]    = "Небольшая металлическая банка с непонятной субстанцией.",
        ["hunger"]  = 35,
        ["thirst"]  = 10,
    },
}
for k, v in pairs(hunger_items) do
    local ITEM = ix.item.Register(k, nil, false, nil, true)
    ITEM.name = v.name
    ITEM.description = v.desc
    ITEM.model = v.model
    ITEM.width = v.width or 1
    ITEM.height = v.height or 1
    ITEM.category = "Еда"
    ITEM.hunger = v.hunger or 0
    ITEM.thirst = v.thirst or 0
    ITEM.empty = v.empty or false
    function ITEM:GetDescription()
        return self.description
    end
    ITEM.functions.Consume = {
        name = "Употребить",
        OnCanRun = function(item)
            if item.thirst != 0 then
                if item.player:GetCharacter():GetData("thirst", 100) >= 100 then
                    return false
                end
            end
            if item.hunger != 0 then
                if item.player:GetCharacter():GetData("hunger", 100) >= 100 then
                    return false
                end
            end
        end,
        OnRun = function(item)
            local hunger = item.player:GetCharacter():GetData("hunger", 100)
            local thirst = item.player:GetCharacter():GetData("thirst", 100)
            item.player:SetHunger(hunger + item.hunger)
            item.player:SetThirst(thirst + item.thirst)
            item.player:EmitSound("physics/flesh/flesh_impact_hard6.wav")
            if item.empty then
                local inv = item.player:GetCharacter():GetInventory()
                inv:Add(item.empty)
            end
        end
    }
end
 
Сверху Снизу