CustomGames.ru - Dota 2 пользовательские игры

Не обнуляется урон

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн Adam Smith

  • Друзья CG
  • 468
  • Мощь: 6
  • жрять жри его
Не обнуляется урон
« : 15-03-2016, 18:55:56 »
Код
ursa_battle_trance = class({})
LinkLuaModifier( "ursa_battle_trance_modifier", "ursa_battle_trance.lua", LUA_MODIFIER_MOTION_NONE )


--------------------------------------------------------------------------------

function ursa_battle_trance:GetCooldown( nLevel )
    if self:GetCaster():HasScepter() then
        return 20
    end

    return self.BaseClass.GetCooldown( self, nLevel )
end
--------------------------------------------------------------------------------

function ursa_battle_trance:IsHiddenWhenStolen()
    return true
end

--------------------------------------------------------------------------------

function ursa_battle_trance:OnSpellStart()
    self.damage_reduction = self:GetSpecialValueFor( "damage_reduction" )*0.01
    self.heal_persent = self:GetSpecialValueFor( "healing_scepter" )
    self.duration = self:GetSpecialValueFor( "duration" )
    _G.heal = nil
    _G.damage = nil
    local caster = self:GetCaster()
    caster:EmitSound("Hero_Ursa.Enrage")
    caster:EmitSound("Hero_Ursa.Enrage")
    _G.CastHealth = caster:GetHealth()
    caster:AddNewModifier( self:GetCaster(), self, "ursa_battle_trance_modifier", { duration = self.duration } )
    local vTargetPosition = caster:GetAbsOrigin()
    nFXIndex_promise = ParticleManager:CreateParticle( "particles/units/heroes/hero_oracle/oracle_false_promise.vpcf", PATTACH_POINT_FOLLOW, self:GetCaster() )
    ParticleManager:SetParticleControl( nFXIndex_promise, 0, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 1, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 2, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 4, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 5, vTargetPosition )

    EmitSoundOnLocationWithCaster( vTargetPosition, "Hero_Ursa.Enrage", self:GetCaster() )
    Timers:CreateTimer(self.duration,
    function()
        ParticleManager:DestroyParticle(nFXIndex_promise, false)
        return nil
    end)
end

--------------------------------------------------------------------------------

ursa_battle_trance_modifier = class({})

function ursa_battle_trance_modifier:DeclareFunctions()
    return { MODIFIER_EVENT_ON_TAKEDAMAGE }
end

function ursa_battle_trance_modifier:OnCreated()
    local ability = self:GetAbility()
    local caster = self:GetCaster()
    self.tick_interval = 0.03
    self:StartIntervalThink(self.tick_interval)
    _G.heal = 0
    _G.damage = 0
end

function ursa_battle_trance_modifier:OnIntervalThink()
    local caster = self:GetParent()
    if caster:HasScepter() and caster:GetHealth() > _G.CastHealth then
        _G.heal = _G.heal + (caster:GetHealth() - _G.CastHealth)
        caster:SetHealth(_G.CastHealth)
    end
end

function ursa_battle_trance_modifier:OnTakeDamage( event )
    local caster = self:GetCaster()
    self.attacker = event.attacker
    local damage_dealed = event.damage
    _G.damage = _G.damage + damage_dealed

    caster:SetHealth(_G.CastHealth)
end
function ursa_battle_trance_modifier:OnDestroy()
    local caster = self:GetCaster()
    local ability = self

    if not caster:HasScepter() then
        ApplyDamage({attacker = self.attacker, victim = caster, ability = ability, damage = _G.damage, damage_type = DAMAGE_TYPE_PURE})
        caster:EmitSound("Hero_Oracle.FalsePromise.Damaged")
        caster:EmitSound("Hero_Oracle.FalsePromise.Damaged")
        _G.damage = nil
        ParticleManager:CreateParticle("particles/units/heroes/hero_oracle/oracle_false_promise_dmg.vpcf", PATTACH_OVERHEAD_FOLLOW, caster)
    else
        caster:Heal(_G.heal, caster)
        ApplyDamage({attacker = caster, victim = self.attacker, ability = ability, damage = _G.damage, damage_type = DAMAGE_TYPE_PURE})
        ApplyDamage({attacker = self.attacker, victim = caster, ability = ability, damage = _G.damage, damage_type = DAMAGE_TYPE_PURE})
        caster:EmitSound("Hero_Oracle.FalsePromise.Healed")
        _G.heal = nil
        _G.damage = nil
        ParticleManager:CreateParticle("particles/units/heroes/hero_oracle/oracle_false_promise_dmg.vpcf", PATTACH_OVERHEAD_FOLLOW, caster)
    end
end


function ursa_battle_trance_modifier:GetStatusEffectName()
    return "particles/status_fx/status_effect_huskar_lifebreak.vpcf"
end

function ursa_battle_trance_modifier:IsHidden()
    return false
end
function ursa_battle_trance_modifier:IsBuff()
    return true
end

function ursa_battle_trance_modifier:IsPurgable()
    return false
end
Никак не хочет обнулять урон, в чем дело?
By PG.Freeman

Оффлайн Adam Smith

  • Друзья CG
  • 468
  • Мощь: 6
  • жрять жри его
Re: Не обнуляется урон
« Ответ #1 : 15-03-2016, 18:57:46 »
Хотя нет обнуляет...но все равно на OnDestroy убивает на месте
И еще такая ошибка
Код
[ W VScript   ]: 	...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:68: in function <...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:66>
[   Developer ]: ...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:68: attempt to call method 'GetHealth' (a nil value)
[   Developer ]: ...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:68: in function <...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:66>
[ W VScript   ]: Script Runtime Error: ...addons\hero_wars\scripts\vscripts\ursa_battle_trance.lua:68: attempt to call method 'GetHealth' (a nil value)
[ W VScript   ]: stack traceback:
By PG.Freeman

Оффлайн Adam Smith

  • Друзья CG
  • 468
  • Мощь: 6
  • жрять жри его
Re: Не обнуляется урон
« Ответ #2 : 16-03-2016, 09:12:28 »
Решил проблему так
Код
ursa_battle_trance = class({})
LinkLuaModifier( "ursa_battle_trance_modifier", "ursa_battle_trance.lua", LUA_MODIFIER_MOTION_NONE )


--------------------------------------------------------------------------------

function ursa_battle_trance:GetCooldown( nLevel )
    if self:GetCaster():HasScepter() then
        return 20
    end

    return self.BaseClass.GetCooldown( self, nLevel )
end
--------------------------------------------------------------------------------

function ursa_battle_trance:IsHiddenWhenStolen()
    return true
end
function ursa_battle_trance:GetBehavior()
    if self:GetCaster():HasScepter() then
        return DOTA_ABILITY_BEHAVIOR_NO_TARGET + DOTA_ABILITY_BEHAVIOR_IMMEDIATE + DOTA_ABILITY_BEHAVIOR_UNRESTRICTED
    end
    return DOTA_ABILITY_BEHAVIOR_NO_TARGET + DOTA_ABILITY_BEHAVIOR_IMMEDIATE
end

--------------------------------------------------------------------------------

function ursa_battle_trance:OnSpellStart()
    self.damage_reduction = self:GetSpecialValueFor( "damage_reduction" )*0.01
    self.heal_persent = self:GetSpecialValueFor( "healing_scepter" )
    self.duration = self:GetSpecialValueFor( "duration" )
    local caster = self:GetCaster()
    self.heal = 0
    _G.damage = 0
    caster:EmitSound("Hero_Ursa.Enrage")
    caster:EmitSound("Hero_Ursa.Enrage")
    _G.CastHealth = caster:GetHealth()
    caster:AddNewModifier( self:GetCaster(), self, "ursa_battle_trance_modifier", { duration = self.duration } )
    local vTargetPosition = caster:GetAbsOrigin()
    nFXIndex_promise = ParticleManager:CreateParticle( "particles/units/heroes/hero_oracle/oracle_false_promise.vpcf", PATTACH_POINT_FOLLOW, self:GetCaster() )
    ParticleManager:SetParticleControl( nFXIndex_promise, 0, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 1, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 2, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 4, vTargetPosition )
    ParticleManager:SetParticleControl( nFXIndex_promise, 5, vTargetPosition )
    Timers:CreateTimer(0.03,
    function()
        if caster:HasModifier("ursa_battle_trance_modifier") then
            if caster:HasScepter() and caster:GetHealth() > _G.CastHealth then
                self.heal =  self.heal + (caster:GetHealth() - _G.CastHealth)
                caster:SetHealth(_G.CastHealth)
            else
                caster:SetHealth(_G.CastHealth)
            end
            return 0.03
        else
            caster:Heal( self.heal, self)
            self.heal = 0
            local damage = {
                victim = self:GetCaster(),
                attacker = _G.attacker,
                damage = _G.damage,
                damage_type = DAMAGE_TYPE_PHYSICAL,
                ability = self
            }
            ApplyDamage( damage )
            caster:EmitSound("Hero_Oracle.FalsePromise.Damaged")
            caster:EmitSound("Hero_Oracle.FalsePromise.Damaged")
            print(_G.damage)

            ParticleManager:CreateParticle("particles/units/heroes/hero_oracle/oracle_false_promise_dmg.vpcf", PATTACH_OVERHEAD_FOLLOW, caster)
                 if  caster:HasScepter() then
                     local damage = {
                         victim = _G.attacker,
                         attacker = self:GetCaster(),
                         damage = _G.damage,
                         damage_type = DAMAGE_TYPE_PURE,
                         ability = self
                     }
                     ApplyDamage( damage )
                      caster:EmitSound("Hero_Oracle.FalsePromise.Healed")
                      self.heal = 0
                     _G.damage = nil
                     ParticleManager:CreateParticle("particles/units/heroes/hero_oracle/oracle_false_promise_dmg.vpcf", PATTACH_OVERHEAD_FOLLOW, caster)
                 end
            return nil
        end
    end)

    EmitSoundOnLocationWithCaster( vTargetPosition, "Hero_Ursa.Enrage", self:GetCaster() )
    Timers:CreateTimer(self.duration,
    function()
        ParticleManager:DestroyParticle(nFXIndex_promise, false)
        return nil
    end)
end

--------------------------------------------------------------------------------

ursa_battle_trance_modifier = class({})

function ursa_battle_trance_modifier:DeclareFunctions()
    return { MODIFIER_EVENT_ON_TAKEDAMAGE }
end

function ursa_battle_trance_modifier:OnTakeDamage( event )
    local caster = self:GetCaster()
    _G.attacker = event.attacker
    local damage_dealed = event.damage
    if damage_dealed > 41 then
        _G.damage = _G.damage + damage_dealed
        print(damage_dealed)
    end
    caster:SetHealth(_G.CastHealth)
end
function ursa_battle_trance_modifier:GetStatusEffectName()
    return "particles/status_fx/status_effect_huskar_lifebreak.vpcf"
end

function ursa_battle_trance_modifier:IsHidden()
    return false
end
function ursa_battle_trance_modifier:IsBuff()
    return true
end

function ursa_battle_trance_modifier:IsPurgable()
    return false
end
By PG.Freeman