how to make talent cd reduction display correct cd on client

edited August 11 in Questions
--not sure how i can get this to display correct cd on client.
--the FindAbilityByName function is server only and its used to determine if the caster has the talent ---that reduces cd

function sven_storm_bolt_lua:GetCooldown( nLevel )
    --get errors without this
    if not IsServer() then 
        return self.BaseClass.GetCooldown(self, nLevel)
    end

    local talent = self:GetCaster():FindAbilityByName("special_bonus_unique_sven")
    local reduction = 0
    if talent then
        if talent:GetLevel() > 0 then
            reduction = talent:GetSpecialValueFor("value")
        end
    end

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

Comments

  • Posts: 158

    solution: modifier stacks

    --have to use modifier stacks to transfer the talent value from server to client
    function sven_storm_bolt_lua:GetCooldown( nLevel )
        local reduction = 0
    
        if IsServer() and not self:GetCaster():HasModifier("modifier_sven_talent") then 
            local talent = self:GetCaster():FindAbilityByName("special_bonus_unique_sven")
            if talent then
                if talent:GetLevel() > 0 then
                    local mod = self:GetCaster():AddNewModifier(self:GetCaster(), self, "modifier_sven_talent", {})
                    mod:SetStackCount(talent:GetSpecialValueFor("value"))
                end
            end
        end
    
        if self:GetCaster():HasModifier("modifier_sven_talent") then
            reduction = self:GetCaster():GetModifierStackCount("modifier_sven_talent", self:GetCaster())
        end
        return self.BaseClass.GetCooldown(self, nLevel) - reduction
    end
    
  • Posts: 405

    I'm sure there is a solution not involving stacks. For example you can iterate entities (abilities are entities as well) and do your checks. Not saying stack based solution is bad.

  • edited August 14 Posts: 158

    how would i iterate through ability entities clientside? not sure where i would get the ability ent index from

    edit: or did you literally mean to just do something like

    local i = 0
    while i do
        local ent = EntIndexToHScript(i)
        if --[[ent is the ability im looking for]] then
            reduction = ent:GetSpecialValueFor("value")
           i = nil
        else
           i = i+1
        end
    end
    
  • Posts: 271

    @DoctorGester

    Can you give an example code how to use Entities:Next() and Entities:First()?

  • edited August 22 Posts: 108
    local aliveList = {}
    local ent = Entities:First()
    while (ent) do
      if ent:IsAlive() then
        table.insert(aliveList, ent)
      end
      ent = Entities:Next(ent)
    end
    

    Github: Profile Steam: Profile

  • Posts: 271

    @lolle

    Thank you.