#Summoned creeps

1 messages · Page 1 of 1 (latest)

sullen gulch
#

Hi, everybody.How can I make a summoned unit give gold to its owner for killing creeps?
I tried to do something like this, but print(gold_modify) returns 0
GameEvent entity_killed:

if attacker:GetUnitName() == "npc_dota_goodguys_siege_custom" or attacker:GetUnitName() == "npc_dota_neutral_satyr_trickster_custom" or attacker:GetUnitName() == "npc_dota_neutral_warpine_raider_custom" then
        local bounty_min = killed_unit:GetMinimumGoldBounty()
        local bounty_max = killed_unit:GetMaximumGoldBounty()
        local owner_id = attacker:GetPlayerOwnerID()
        print(owner_id)
        if owner_id then
            local random_bounty = RandomInt(bounty_min,bounty_max)
            print(random_bounty)
            local gold_modify = PlayerResource:ModifyGold(owner_id, random_bounty, false, DOTA_ModifyGold_Unspecified)
            print(gold_modify)
        end
    end
#

The code of the ability that creates the creep (This ability is in the building that the hero creates)

treant_barracks_melee = class({})

function treant_barracks_melee:OnSpellStart()
    local caster = self:GetCaster()
    local owner = caster:GetPlayerOwner()
    local owner_id = owner:GetPlayerID()
    local owner_gold = PlayerResource:GetGold(owner_id)
    local gold = self:GetSpecialValueFor("gold")
    if owner_gold >= gold then
        PlayerResource:SpendGold(owner_id,gold,DOTA_ModifyGold_AbilityCost)
        local creep = CreateUnitByName("npc_dota_neutral_warpine_raider_custom", caster:GetAbsOrigin() + RandomVector(300), true, owner, owner, owner:GetTeamNumber())
        FindClearSpaceForUnit(creep, creep:GetOrigin(), false)
        creep:SetBaseMaxHealth(self:GetSpecialValueFor("melee_hp"))
        creep:SetMaxHealth(self:GetSpecialValueFor("melee_hp"))
        creep:SetHealth(self:GetSpecialValueFor("melee_hp"))
        creep:SetPhysicalArmorBaseValue(self:GetSpecialValueFor("melee_armor"))
        creep:SetBaseHealthRegen(self:GetSpecialValueFor("melee_hp_regen"))
        creep:SetBaseDamageMin(self:GetSpecialValueFor("melee_damage"))
        creep:SetBaseDamageMax(self:GetSpecialValueFor("melee_damage"))
        creep:SetOwner(owner)
        creep:SetControllableByPlayer(owner_id, true)
    end
end
#

code of hero ability:

treant_barracks = class({})

function treant_barracks:OnSpellStart()
    local caster = self:GetCaster()
    local radius = self:GetSpecialValueFor("radius")
    local point = self:GetCursorPosition()
    local units = FindUnitsInRadius(caster:GetTeamNumber(), point, nil, radius, DOTA_UNIT_TARGET_TEAM_BOTH, DOTA_UNIT_TARGET_HERO , DOTA_UNIT_TARGET_FLAG_NONE , FIND_ANY_ORDER, false)
    local trees = GridNav:IsNearbyTree(point, radius, true)
    if #units <= 0 and trees == false then
        local barrack = CreateUnitByName("npc_dota_goodguys_melee_rax_top", point, false, caster, caster, caster:GetTeamNumber())
        local id = caster:GetPlayerID()
        barrack:SetOwner(caster)
        barrack:SetControllableByPlayer(id, true)
        barrack:RemoveModifierByName("modifier_invulnerable")
        barrack:AddNewModifier(caster, self, "modifier_kill", {duration = self:GetSpecialValueFor("barrack_duration")})
        barrack:SetBaseMaxHealth(self:GetSpecialValueFor("barrack_hp"))
        barrack:SetMaxHealth(self:GetSpecialValueFor("barrack_hp"))
        barrack:SetHealth(self:GetSpecialValueFor("barrack_hp"))
        barrack:SetPhysicalArmorBaseValue(self:GetSpecialValueFor("barrack_armor"))
        barrack:SetBaseHealthRegen(self:GetSpecialValueFor("barrack_hp_regen"))
        if self:GetLevel() >= 1 then
            local ability_1 = barrack:AddAbility("treant_barracks_melee")
            ability_1:SetLevel(self:GetLevel())
        end
        if self:GetLevel() >= 2 then
            local ability_2 = barrack:AddAbility("treant_barracks_range")
            ability_2:SetLevel(self:GetLevel())
        end
        if self:GetLevel() >= 3 then
            local ability_2 = barrack:AddAbility("treant_barracks_catapult")
            ability_2:SetLevel(self:GetLevel())
        end
    end
    if #units >= 1 or trees == true then
        self:EndCooldown()
    end
end
#

I will be grateful for your help

tall robin
#

Player:ModifyGold returns int and this int might be just unmapped enum that means something that valve only knows or just broken. You can just calculate gold change yourself or get new gold value if you need it
In your first ability in create unit args try replace "owner" with "caster" (i always passed unit here instead of player and never had issues). Valve also pass unit: https://github.com/SteamDatabase/GameTracking-Dota2/blob/97ca1a30374165b93915fc252564c23d3219862c/game/dota_addons/dungeon/scripts/vscripts/abilities/sand_king_boss_sandstorm.lua#L97
You also don't need to replicate dota gold bounty yourself because you can just use built it one (unless you need special conditions or math). If gold bounty is suddenly broken by valve im sure you will saw at least one thread here with "how to fix new dota patch" by some newbie

GitHub

📥 Game Tracker: Dota 2. Contribute to SteamDatabase/GameTracking-Dota2 development by creating an account on GitHub.

#

In first code if owner_id then doesn't make sense for me. Im sure this function always returns integer (for unit without player owner probably returns -1) and in lua any non null value = true (except false one)

#

For your treant_barracks_melee ability you can use built it GoldCost instead of ManaCost if your ability is just "pay gold and spawn unit" (idk how good this things works, but at least gold display in ui should work i think).
You can also use CastFilterResult to implement nice red error message with sound (at bottom of screen) instead of doing nothing if player lacks gold (return UF_FAIL_CUSTOM in that function and GetCustomCastError returns localization key for missing gold text)

sullen gulch
#

Thanks for the information about the red message, I didn't know how to do it. But I still don't understand how to get the creeps controlled by the hero to give gold for the kill. Provided that the creep creates by unit

tall robin
#

You also might not defined gold bounty for that creeps at all in kv files

sullen gulch
sullen gulch
tall robin
#

Post kv of any unit from first post just be sure that there are no typo or something like that

sullen gulch
#

I cannot place the KV file as text due to the Discord limitation, I will attach a screenshot.

#

Do you need a larger text size?

tall robin
#

Its fine

#

I probably found issue. In first ability try pass caster:GetOwnerEntity() to CreateUnit so owner of that unit would be hero itself instead of building

sullen gulch
#

Something like that?

tall robin
sullen gulch
tall robin
sullen gulch