Исходник Ограничение на поднятие более 1го предмета

iia3uk666

Друзья CG
18 Дек 2021
411
70
Проект
Ушел с CG
Всех с новым 2022 годом, вот вам господа мододелы, исходничек Lua скрипта на ограничение подбора более одного уникального предмета

Благодарность за исходник: "@vulkantsk"

Нам понадобиться:
Пример можно взять тут <- (click)
Путь к файлу:
*:\steam\steamapps\common\dota 2 beta\game\dota_addons\КАРТА\scripts\vscripts\
Название файла:
custom_sword.lua

Lua:
LinkLuaModifier("modifier_item_sword_life_lua", "custom_sword", LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_item_sword_water_lua", "custom_sword", LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_item_sword_death_lua", "custom_sword", LUA_MODIFIER_MOTION_NONE)
LinkLuaModifier("modifier_item_sword_insects_lua", "custom_sword", LUA_MODIFIER_MOTION_NONE)



item_sword_life_lua = class({})

function item_sword_life_lua:GetIntrinsicModifierName()
    return "modifier_item_sword_life_lua"
end

modifier_item_sword_life_lua = class({
    IsHidden                = function(self) return true end,
    IsPurgable              = function(self) return false end,
    IsDebuff                = function(self) return false end,
    IsBuff                  = function(self) return true end,
    RemoveOnDeath           = function(self) return false end,
    DeclareFunctions        = function(self) return
    {
        MODIFIER_PROPERTY_PREATTACK_BONUS_DAMAGE,
    } end,

})


function modifier_item_sword_life_lua:OnCreated()
    local caster = self:GetCaster()
    local vLocation = caster:GetAbsOrigin()
    local item = self:GetAbility()

    if caster.sword == nil then
        caster.sword = self
    else
        Timers:CreateTimer(0, function()
            caster:DropItemAtPositionImmediate(item, vLocation)
            GameRules:SendCustomMessage("<font color='#FA8072'> Нельзя носить более одного уникального меча !</font>",0,0)
        end)
    end
    self.bonus_dmg = self:GetAbility():GetSpecialValueFor("bonus_dmg")
end

function modifier_item_sword_life_lua:OnDestroy()
    local caster = self:GetCaster()

    if caster.sword == self then
        caster.sword = nil
    end
end

function modifier_item_sword_life_lua:GetAttributes()
    return MODIFIER_ATTRIBUTE_MULTIPLE + MODIFIER_ATTRIBUTE_IGNORE_INVULNERABLE
end

function modifier_item_sword_life_lua:GetModifierPreAttack_BonusDamage()
    return self.bonus_dmg
end



item_sword_water_lua = class({})

function item_sword_water_lua:GetIntrinsicModifierName()
    return "modifier_item_sword_water_lua"
end

modifier_item_sword_water_lua = class({
    IsHidden                = function(self) return true end,
    IsPurgable              = function(self) return false end,
    IsDebuff                = function(self) return false end,
    IsBuff                  = function(self) return true end,
    RemoveOnDeath           = function(self) return false end,
    DeclareFunctions        = function(self) return
    {
        MODIFIER_PROPERTY_PREATTACK_BONUS_DAMAGE,
    } end,

})


function modifier_item_sword_water_lua:OnCreated()
    local caster = self:GetCaster()
    local vLocation = caster:GetAbsOrigin()
    local item = self:GetAbility()

    if caster.sword == nil then
        caster.sword = self
    else
        Timers:CreateTimer(0, function()
            caster:DropItemAtPositionImmediate(item, vLocation)
            GameRules:SendCustomMessage("<font color='#FA8072'> Нельзя носить более одного уникального меча !</font>",0,0)
        end)
    end
    self.bonus_dmg = self:GetAbility():GetSpecialValueFor("bonus_dmg")
end

function modifier_item_sword_water_lua:OnDestroy()
    local caster = self:GetCaster()

    if caster.sword == self then
        caster.sword = nil
    end
end

function modifier_item_sword_water_lua:GetAttributes()
    return MODIFIER_ATTRIBUTE_MULTIPLE + MODIFIER_ATTRIBUTE_IGNORE_INVULNERABLE
end

function modifier_item_sword_water_lua:GetModifierPreAttack_BonusDamage()
    return self.bonus_dmg
end



item_sword_death_lua = class({})

function item_sword_death_lua:GetIntrinsicModifierName()
    return "modifier_item_sword_death_lua"
end

modifier_item_sword_death_lua = class({
    IsHidden                = function(self) return true end,
    IsPurgable              = function(self) return false end,
    IsDebuff                = function(self) return false end,
    IsBuff                  = function(self) return true end,
    RemoveOnDeath           = function(self) return false end,
    DeclareFunctions        = function(self) return
    {
        MODIFIER_PROPERTY_PREATTACK_BONUS_DAMAGE,
    } end,

})


function modifier_item_sword_death_lua:OnCreated()
    local caster = self:GetCaster()
    local vLocation = caster:GetAbsOrigin()
    local item = self:GetAbility()

    if caster.sword == nil then
        caster.sword = self
    else
        Timers:CreateTimer(0, function()
            caster:DropItemAtPositionImmediate(item, vLocation)
            GameRules:SendCustomMessage("<font color='#FA8072'> Нельзя носить более одного уникального меча !</font>",0,0)
        end)
    end
    self.bonus_dmg = self:GetAbility():GetSpecialValueFor("bonus_dmg")
end

function modifier_item_sword_death_lua:OnDestroy()
    local caster = self:GetCaster()

    if caster.sword == self then
        caster.sword = nil
    end
end

function modifier_item_sword_death_lua:GetAttributes()
    return MODIFIER_ATTRIBUTE_MULTIPLE + MODIFIER_ATTRIBUTE_IGNORE_INVULNERABLE
end

function modifier_item_sword_death_lua:GetModifierPreAttack_BonusDamage()
    return self.bonus_dmg
end



item_sword_insects_lua = class({})

function item_sword_insects_lua:GetIntrinsicModifierName()
    return "modifier_item_sword_insects_lua"
end

modifier_item_sword_insects_lua = class({
    IsHidden                = function(self) return true end,
    IsPurgable              = function(self) return false end,
    IsDebuff                = function(self) return false end,
    IsBuff                  = function(self) return true end,
    RemoveOnDeath           = function(self) return false end,
    DeclareFunctions        = function(self) return
    {
        MODIFIER_PROPERTY_PREATTACK_BONUS_DAMAGE,
    } end,

})


function modifier_item_sword_insects_lua:OnCreated()
    local caster = self:GetCaster()
    local vLocation = caster:GetAbsOrigin()
    local item = self:GetAbility()

    if caster.sword == nil then
        caster.sword = self
    else
        Timers:CreateTimer(0, function()
            caster:DropItemAtPositionImmediate(item, vLocation)
            GameRules:SendCustomMessage("<font color='#FA8072'> Нельзя носить более одного уникального меча !</font>",0,0)
        end)
    end
    self.bonus_dmg = self:GetAbility():GetSpecialValueFor("bonus_dmg")
end

function modifier_item_sword_insects_lua:OnDestroy()
    local caster = self:GetCaster()

    if caster.sword == self then
        caster.sword = nil
    end
end

function modifier_item_sword_insects_lua:GetAttributes()
    return MODIFIER_ATTRIBUTE_MULTIPLE + MODIFIER_ATTRIBUTE_IGNORE_INVULNERABLE
end

function modifier_item_sword_insects_lua:GetModifierPreAttack_BonusDamage()
    return self.bonus_dmg
end
Путь к файлу:
*:\steam\steamapps\common\dota 2 beta\game\dota_addons\КАРТА\scripts\npc\
Название файла:
npc_items_custom.txt
Код:
"DOTAAbilities"
{

     "item_sword_insects_lua"
        {
            "BaseClass"                     "item_lua"
            "ScriptFile"                    "custom_sword"
            "AbilityBehavior"                "DOTA_ABILITY_BEHAVIOR_PASSIVE"
               "Model"                        "models/sword_insects.vmdl"
                   "AbilityTextureName"                "sword_insects"

            "AbilitySpecial"
            {
                "01"
                {
                    "var_type"            "FIELD_INTEGER"
                    "bonus_dmg"            "150"
                }
            }
        }

    "item_sword_death_lua"
        {
            "BaseClass"                     "item_lua"
            "ScriptFile"                    "custom_sword"
            "AbilityBehavior"                "DOTA_ABILITY_BEHAVIOR_PASSIVE"
              "Model"                        "models/sword_death.vmdl"
                  "AbilityTextureName"                "sword_death"

            "AbilitySpecial"
            {
                "01"
                {
                    "var_type"            "FIELD_INTEGER"
                    "bonus_dmg"            "150"
                }
            }
        }

   "item_sword_water_lua"
       {
           "BaseClass"                     "item_lua"
           "ScriptFile"                    "custom_sword"
           "AbilityBehavior"                "DOTA_ABILITY_BEHAVIOR_PASSIVE"
           "Model"                        "models/sword_water.vmdl"
                   "AbilityTextureName"                "sword_water"

           "AbilitySpecial"
           {
               "01"
               {
                   "var_type"            "FIELD_INTEGER"
                   "bonus_dmg"            "150"
               }
           }
       }

  "item_sword_life_lua"
    {
        "BaseClass"                     "item_lua"
        "ScriptFile"                    "custom_sword"
        "AbilityBehavior"                "DOTA_ABILITY_BEHAVIOR_PASSIVE"
        "Model"                            "models/sword_life.vmdl"
        "AbilityTextureName"            "sword_life"
        "RingRadius"                "99"
        "HealthBarOffset"            "300"
        "AbilitySpecial"
        {
            "01"
            {
                "var_type"            "FIELD_INTEGER"
                "bonus_dmg"            "150"
            }
        }
    }
}
Закиньте файл с любым названием - содержание:
Lua:
--[[
  -- A timer running every second that starts immediately on the next frame, respects pauses
  Timers:CreateTimer(function()
      print ("Hello. I'm running immediately and then every second thereafter.")
      return 1.0
    end
  )
  -- A timer running every second that starts 5 seconds in the future, respects pauses
  Timers:CreateTimer(5, function()
      print ("Hello. I'm running 5 seconds after you called me and then every second thereafter.")
      return 1.0
    end
  )
  -- 10 second delayed, run once using gametime (respect pauses)
  Timers:CreateTimer({
    endTime = 10, -- when this timer should first execute, you can omit this if you want it to run first on the next frame
    callback = function()
      print ("Hello. I'm running 10 seconds after when I was started.")
    end
  })
  -- 10 second delayed, run once regardless of pauses
  Timers:CreateTimer({
    useGameTime = false,
    endTime = 10, -- when this timer should first execute, you can omit this if you want it to run first on the next frame
    callback = function()
      print ("Hello. I'm running 10 seconds after I was started even if someone paused the game.")
    end
  })
  -- A timer running every second that starts after 2 minutes regardless of pauses
  Timers:CreateTimer("uniqueTimerString3", {
    useGameTime = false,
    endTime = 120,
    callback = function()
      print ("Hello. I'm running after 2 minutes and then every second thereafter.")
      return 1
    end
  })
  -- A timer using the old style to repeat every second starting 5 seconds ahead
  Timers:CreateTimer("uniqueTimerString3", {
    useOldStyle = true,
    endTime = GameRules:GetGameTime() + 5,
    callback = function()
      print ("Hello. I'm running after 5 seconds and then every second thereafter.")
      return GameRules:GetGameTime() + 1
    end
  })
]]

TIMERS_THINK = 0.01

if Timers == nil then
    print ( '[Timers] creating Timers' )
    Timers = {}
    Timers.__index = Timers
end

function Timers:new( o )
    o = o or {}
    setmetatable( o, Timers )
    return o
end

function Timers:start()
    Timers = self
    self.timers = {}

    local ent = Entities:CreateByClassname("info_target") -- Entities:FindByClassname(nil, 'CWorld')
    ent:SetThink("Think", self, "timers", TIMERS_THINK)
end

function Timers:Think()
    if GameRules:State_Get() >= DOTA_GAMERULES_STATE_POST_GAME then
        return
    end

    -- Track game time, since the dt passed in to think is actually wall-clock time not simulation time.
    local now = GameRules:GetGameTime()

    -- Process timers
    for k,v in pairs(Timers.timers) do
        local bUseGameTime = true
        if v.useGameTime ~= nil and v.useGameTime == false then
            bUseGameTime = false
        end
        local bOldStyle = false
        if v.useOldStyle ~= nil and v.useOldStyle == true then
            bOldStyle = true
        end

        local now = GameRules:GetGameTime()
        if not bUseGameTime then
            now = Time()
        end

        if v.endTime == nil then
            v.endTime = now
        end
        -- Check if the timer has finished
        if now >= v.endTime then
            -- Remove from timers list
            Timers.timers[k] = nil

            -- Run the callback
            local status, nextCall = pcall(v.callback, GameRules:GetGameModeEntity(), v)

            -- Make sure it worked
            if status then
                -- Check if it needs to loop
                if nextCall then
                    -- Change its end time

                    if bOldStyle then
                        v.endTime = v.endTime + nextCall - now
                    else
                        v.endTime = v.endTime + nextCall
                    end

                    Timers.timers[k] = v
                end

                -- Update timer data
                --self:UpdateTimerData()
            else
                -- Nope, handle the error
                Timers:HandleEventError('Timer', k, nextCall)
            end
        end
    end

    return TIMERS_THINK
end

function Timers:HandleEventError(name, event, err)
    print(err)

    -- Ensure we have data
    name = tostring(name or 'unknown')
    event = tostring(event or 'unknown')
    err = tostring(err or 'unknown')

    -- Tell everyone there was an error
    --Say(nil, name .. ' threw an error on event '..event, false)
    --Say(nil, err, false)

    -- Prevent loop arounds
    if not self.errorHandled then
        -- Store that we handled an error
        self.errorHandled = true
    end
end

function Timers:CreateTimer(name, args)
    if type(name) == "function" then
        args = {callback = name}
        name = DoUniqueString("timer")
    elseif type(name) == "table" then
        args = name
        name = DoUniqueString("timer")
    elseif type(name) == "number" then
        args = {endTime = name, callback = args}
        name = DoUniqueString("timer")
    end
    if not args.callback then
        print("Invalid timer created: "..name)
        return
    end


    local now = GameRules:GetGameTime()
    if args.useGameTime ~= nil and args.useGameTime == false then
        now = Time()
    end

    if args.endTime == nil then
        args.endTime = now
    elseif args.useOldStyle == nil or args.useOldStyle == false then
        args.endTime = now + args.endTime
    end

    Timers.timers[name] = args

    return name
end

function Timers:RemoveTimer(name)
    Timers.timers[name] = nil
end

function Timers:RemoveTimers(killAll)
    local timers = {}

    if not killAll then
        for k,v in pairs(Timers.timers) do
            if v.persist then
                timers[k] = v
            end
        end
    end

    Timers.timers = timers
end

Timers:start()
Это таймеры, если у вас вдруг их нет
И подключите файл через:
require ("Ваше название") //без формата: require ("timers")
В файле addon_game_mode.lua
Путь к файлу:
*:\steam\steamapps\common\dota 2 beta\game\dota_addons\КАРТА\resource\
Файл:
addon_russian.txt
Код:
"lang"
{
    "Language"        "russian"
    "Tokens"
    {
  
        "DOTA_Tooltip_ability_item_sword_life_lua"                          "Меч повелителя теплокровных"
        "DOTA_Tooltip_ability_item_sword_life_lua_Lore"                        "По легенде этот меч способен покарить теплокровных существ"
        "DOTA_Tooltip_ability_item_sword_life_lua_bonus_dmg"                "+к урону по живым"

        "DOTA_Tooltip_ability_item_sword_water_lua"                          "Меч повелителя хладнокровных"
        "DOTA_Tooltip_ability_item_sword_water_lua_Lore"                     "По легенде этот меч способен покарить хлоднокровных существ"
        "DOTA_Tooltip_ability_item_sword_water_lua_bonus_dmg"             "+к урону по амфибиям"

        "DOTA_Tooltip_ability_item_sword_insects_lua"                        "Меч повелителя насекомых"
        "DOTA_Tooltip_ability_item_sword_insects_lua_Lore"                     "По легенде этот меч способен покарить членистоногих"
        "DOTA_Tooltip_ability_item_sword_insects_lua_bonus_dmg"             "+к урону по насекомым"

        "DOTA_Tooltip_ability_item_sword_death_lua"                          "Меч повелителя смерти"
        "DOTA_Tooltip_ability_item_sword_death_lua_Lore"                     "По легенде этот меч способен покарить всю нечисть"
        "DOTA_Tooltip_ability_item_sword_death_lua_bonus_dmg"             "+к урону по мертвым"
    }
}



as5c_tW2--A.jpg
7cr_tPQCy3I.jpg
 
Последнее редактирование:
Реклама: