#Trying to change base gold award for killing creep

1 messages · Page 1 of 1 (latest)

swift wind
#

I am trying to adjust the gold received in a custom map from a creep. However, it is not halfing at all.

---redacted ---
-- Event handler for entity killed
function YourGameMode:OnEntityKilled(keys)
    local killedUnit = EntIndexToHScript(keys.entindex_killed)
    local killerEntity = nil
    
    if keys.entindex_attacker ~= nil then
        killerEntity = EntIndexToHScript(keys.entindex_attacker)
    end
    
    -- Check if the killed unit is a creep and the killer is a hero
    if killedUnit and killerEntity and killedUnit:IsCreep() and killerEntity:IsHero() then
        -- Get the original bounty
        local originalBounty = killedUnit:GetGoldBounty()
        
        -- Set to 50% of the original bounty
        local modifiedBounty = math.floor(originalBounty * 0.5)
        
        -- Remove the original gold that would be given automatically
        killerEntity:ModifyGold(-originalBounty, true, DOTA_ModifyGold_CreepKill)
        
        -- Give the modified amount
        killerEntity:ModifyGold(modifiedBounty, true, DOTA_ModifyGold_CreepKill)
        
        -- Print debug information
        print("Creep kill - setting gold to half: " .. modifiedBounty .. " (original: " .. originalBounty .. ")")
        
        -- Optional: Display the modified gold amount
        local player = killerEntity:GetPlayerOwner()
        if player then
            -- Create a floating gold text
            local particleID = ParticleManager:CreateParticleForPlayer("particles/msg_fx/msg_gold.vpcf", PATTACH_OVERHEAD_FOLLOW, killerEntity, player)
            ParticleManager:SetParticleControl(particleID, 1, Vector(0, modifiedBounty, 0))
            ParticleManager:SetParticleControl(particleID, 2, Vector(1, math.floor(math.log10(modifiedBounty)) + 1, 0))
            ParticleManager:SetParticleControl(particleID, 3, Vector(255, 200, 33))
        end
    end
end```
oak breach
#

So what are your prints saying

swift wind
#

Wait I think i see whats going on Creep kill - setting gold to half: 17 (original: 34) is shown in the console but the actual gold symbol that pops over my head shows 34. I actually receive 17 though

wide nymph
#

didnt' you get any error in console?
SetFilterMoreGold is a method that on GameRules

swift wind
swift wind
#

Hmm, i know this is now unrelated to getting the actual gold value, but is there a way to actually hide the base gold graphic completely? The one that pops up after you kill a creep and says like +34

wide nymph
#

I copyed your code, and it works well
I dont know why there's a problem with yours

swift wind
#

did you not also see +36?

wide nymph
#

no

fading vigil
#

you can use gold filter instead of event. this solution change gold numbers in particle and players will understand why they get more gold from killing creeps and fix double particle message if you have this

wide nymph
#

oh my, why did you replace filter with event?
your filter version code works well, and it changes the display number

#
local gameMode = GameRules:GetGameModeEntity()
function gameMode:FilterGold(filterTable)
    DeepPrint(filterTable)
    -- Check if this is a creep kill
    if filterTable.reason_const == DOTA_ModifyGold_CreepKill then
        -- Get the original bounty from the filter table
        local originalBounty = filterTable.gold

        -- Set to half the original bounty
        filterTable.gold = math.floor(originalBounty * 0.5)
        print("Creep kill!! - setting gold to half: " .. filterTable.gold .. " (original: " .. originalBounty .. ")")
    end

    -- Return true to apply our changes
    return true
end

gameMode:SetModifyGoldFilter(Dynamic_Wrap(gameMode, "FilterGold"), gameMode)
GameRules:SetFilterMoreGold(true) -- Important! Enable filtering for ALL gold events

filter worked unsatisfactory without context
so I changed your code
use this version

swift wind
#

okay let me try. im like the internet kid meme working on this stuff...i thought it would be so much easier to just make creeps in a staggered state at 1hp for 1 sec (no creeps can kill them) and just half the value of those creeps bounty on kill. But now this dang particle showing the base value and then another particle showing the actual value is throwing me all off and my eyes are seeing the code starting to blend together

valid edge
#

I think you're overengineering this at this point.

It would help understanding what's the difference between gold filter and gold received event:

Gold Filter triggers before any player gets gold. It provides the amount of gold the player is about to get, alongside some other information (such as reason why the player is getting gold). You can modify those values directly. When you return true you allow the gold to go through and be accepted by the player. When you return false, the player will not get any gold.

After the filter is finished, then the particle is rendered and the gold is awarded.

Gold Receieved Event: happens after any player got gold. It will mention how much gold they got and the reason. At this point, it is too late to modify anything, since everything was already done. However, this lets you react to such events; for example, you could make the hero heal HP equal to gold gained and play some effects.

#

So for your usecase it's clear that the correct choice is filter, since it lets you affect the actual gold earned amount.

swift wind
#

I do think its over engineered. I think I am missing game design basics on how the filter and events work. Because once I changed to filter, it doesnt actually adjust the amount based on conditionals. But when i use events, i ended up actually getting the gold I expected but it still shows both particles (+32 and +11 floating for example). Really I just want to adjust the game to be more forgiving and more fluid when it comes to CS so its better to actually play.

  1. When a enemy kills an enemy creep they get base gold reward.
  2. When a creep is about to be killed, it instead goes into a "kneeling" state where it is stunned. In this stunned state, only heroes or towers can kill the creeps. However, only creep on creep damage that will kill the creep can put the creep into this kneeling state. Nothing else can put the creep into a kneeling state.
    a. IF a creep is in a kneeled state and creep is killed by a enemy hero, the bounty award is 30% of the default bounty.
    b. If the kneeling creep is killed by an enemy hero, then a 15% creep bounty is also distributed to a random enemy hero in 500 range.
  3. The gold particle popup in the game should reflect the gold earned (this is infuriating to try to actually get working inside the conditionals)
wide nymph
#

I didnt see your code,
but I may understand your idea:

  1. creeps killed by hero only provide half of the bounty by default. (34->17
  2. if they were "killed" by any other creep, they'll be stunned and waiting for hero to do last hit, in this case, they provide a 30% and a 15% of the default bounty. ( 34->10+5
    I guess you do this to ensure that the hero wont lose the lane gold, but reduce the gold amount they can farm

some suggestions:
use GetMaximumGoldBounty/GetMinimumGoldBounty and SetMaximumGoldBounty/SetMinimumGoldBounty when creep spawn to adjust the default bounty,
there's a event npc_spawned that can help you, remember to record the original bounty;
add a passive modifier to prevent their death from other creeps,
if this triggered, add stunned and low attack priority, set their bounty to 0 to prevent the gold particle,
and then listen the kill event (modifier event OnKilled or game event, dispatch the bounty manually