Overthrow rework

Hi everyone,

I'm trying to make a 2 vs 2 game only mid on the dota 2 classic map. I want to count point as 1 point per kill and put the limit at 4. I rework the script of Overthrow and it work.

Now, I want to add a system which add 2 point when a tower fall.

I think I found where points are count (script/vscript/event.lua).

---------------------------------------------------------------------------
-- Event: OnTeamKillCredit, see if anyone won
---------------------------------------------------------------------------
function COverthrowGameMode:OnTeamKillCredit( event )
--  print( "OnKillCredit" )
--  DeepPrint( event )

    local nKillerID = event.killer_userid
    local nTeamID = event.teamnumber
    local nTeamKills = event.herokills
    local nKillsRemaining = self.TEAM_KILLS_TO_WIN - nTeamKills

    local broadcast_kill_event =
    {
        killer_id = event.killer_userid,
        team_id = event.teamnumber,
        team_kills = nTeamKills,
        kills_remaining = nKillsRemaining,
        victory = 0,
        close_to_victory = 0,
        very_close_to_victory = 0,
    }

    if nKillsRemaining <= 0 then
        GameRules:SetCustomVictoryMessage( self.m_VictoryMessages[nTeamID] )
        GameRules:SetGameWinner( nTeamID )
        broadcast_kill_event.victory = 1
    elseif nKillsRemaining == 1 then
        EmitGlobalSound( "ui.npe_objective_complete" )
        broadcast_kill_event.very_close_to_victory = 1
    elseif nKillsRemaining <= self.CLOSE_TO_VICTORY_THRESHOLD then
        EmitGlobalSound( "ui.npe_objective_given" )
        broadcast_kill_event.close_to_victory = 1
    end

    CustomGameEventManager:Send_ServerToAllClients( "kill_event", broadcast_kill_event )
end

I tryed to add this but doesn't work :-/

local killedUnit = EntIndexToHScript( event.entindex_killed )
        if killedUnit:IsTower() then
        killedUnit = 2
        end

Can anyone tell me if the problem come from my syntax or my logic?

Thank you :)

Comments

  • edited April 18 Posts: 94

    @Badbaxx, For tower you need "entity_killed" event "OnTeamKillCredit" is for hero kills .

  • Posts: 7

    Thanks you for your advice :) @Yunten

    I tried to do it work but my syntax is not good :-/

    I tried

     if killedUnit:IsTower() == true then
            killedUnit = 2
            end
    

    but got this error in console

    > [Developer]: scripts/vscripts/events.lua:141: in function <scripts/vscri/events.lua:126>
    > [W VScript]: Script Runtime Error: scripts/vscripts/events.lua:141: attempt to index local 'killedUnit' (a number value)
    > [W VScript]: stack traceback:
    > [W VScript]: scripts/vscripts/events.lua:141: in function <scripts/vscripts/events.lua:126>
    > [General]: Building: npc_dota_badguys_tower1_mid destroyed at 238.058044.
    

    I put it in the fonction that you indicate (script/vscript/event.lua):

    ---------------------------------------------------------------------------
    -- Event: OnEntityKilled
    ---------------------------------------------------------------------------
    function COverthrowGameMode:OnEntityKilled( event )
        local killedUnit = EntIndexToHScript( event.entindex_killed )
        local killedTeam = killedUnit:GetTeam()
        local hero = EntIndexToHScript( event.entindex_attacker )
        local heroTeam = hero:GetTeam()
        local extraTime = 0
        if killedUnit:IsRealHero() then
            self.allSpawned = true
            --print("Hero has been killed")
            --Add extra time if killed by Necro Ult
            if hero:IsRealHero() == true then
                if event.entindex_inflictor ~= nil then
                    local inflictor_index = event.entindex_inflictor
                    if inflictor_index ~= nil then
                        local ability = EntIndexToHScript( event.entindex_inflictor )
                        if ability ~= nil then
                            if ability:GetAbilityName() ~= nil then
                                if ability:GetAbilityName() == "necrolyte_reapers_scythe" then
                                    print("Killed by Necro Ult")
                                    extraTime = 20
                                end
                            end
                        end
                    end
                end
            end
            if hero:IsRealHero() and heroTeam ~= killedTeam then
                --print("Granting killer xp")
                if killedUnit:GetTeam() == self.leadingTeam and self.isGameTied == false then
                    local memberID = hero:GetPlayerID()
                    PlayerResource:ModifyGold( memberID, 500, true, 0 )
                    hero:AddExperience( 100, 0, false, false )
                    local name = hero:GetClassname()
                    local victim = killedUnit:GetClassname()
                    local kill_alert =
                        {
                            hero_id = hero:GetClassname()
                        }
                    CustomGameEventManager:Send_ServerToAllClients( "kill_alert", kill_alert )
                else
                    hero:AddExperience( 50, 0, false, false )
                end
            end
    [...]
    
  • Posts: 94

    @Badbaxx, store points in other var i.e

    local scores = 0
    if killedUnit:IsRealHero() then
        scores = 1
    elseif killedUnit:IsTower() then
        scores = 2
    end 
    
  • edited April 21 Posts: 7

    @Yunten I tried to add this as your advice. I have no red logs in console but still does'nt add 2 point to the score when a tower fall. I think that I'm missing something here ^^' So I tried to add scores to local kill unit

    ---------------------------------------------------------------------------
    -- Event: OnEntityKilled
    ---------------------------------------------------------------------------
    function COverthrowGameMode:OnEntityKilled( event )
    local scores = 0
    if killedUnit:IsRealHero() then
        scores = 1
    elseif killedUnit:IsTower() then
        scores = 2
    end 
    local killedUnit = EntIndexToHScript( event.entindex_killed ) + scores
    

    but got errors

  • Posts: 94

    @Badbaxx, you want to store scores in killed unit? If yes then it should look like this:

    function COverthrowGameMode:OnEntityKilled( event )
        local killedUnit = EntIndexToHScript( event.entindex_killed )
        local scores = 0
        if killedUnit:IsRealHero() then
            scores = 1
        elseif killedUnit:IsTower() then
            scores = 2
        end 
    
        killedUnit.my_scores = killedUnit.my_scores + scores
    end
    
  • edited April 22 Posts: 7

    Sorry @Yunten I don't think I say it very clairly. I want that, when a player destroy a tower, his number of kill increase of 2 (or the number of all the member of the team increase of 1).

    (for exemple a player has alredy killed twice (2 kills 0 death 0 assist) and kill a tower will get (4 kills 0 death 0 assist))

    I think that what you wrote fet pretty good with what I want :) Unfortunately, I got this in console :

    [ W VScript  ]: Script Runtime Error: scripts/vscripts/events.lua:139: attempt to perform arithmetic on field 'my_scores' (a nil value)
    

    Is my_score need to be set at 0 before using it?

  • Posts: 94

    @Badbaxx, yes I missed it.