Trigger changing respawn position

edited June 2015 in Questions

Like: I create a trigger and attach a script that basically says:

units that enter the trigger have 'the center of the trigger box' as new respawn location.

is that possible? Can someone give me an idea on how to extend this skeleton?

function SetRespawnPositionCenterOf(trigger)
    local unit = trigger.activator
end

Best regards

Edit: If this is the correct function, how to I get the vector vOrigin to the correct position?

void SetRespawnPosition(Vector vOrigin) 

Comments

  • edited June 2015 Posts: 1,670
    function SetRespawnPositionCenterOf(trigger)
        local unit = trigger.activator
        local caller = trigger.caller
        if unit:IsRealHero() then
            unit:SetRespawnPosition(caller:GetAbsOrigin)
        end
    end
    

    That should do it. The if is only necessary if you are not using a hero-only trigger.

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • Posts: 5

    Thank you very much. I will report back when I get to it!

  • Posts: 5

    Ok Noya this doesn't work.

    First off, GetAbsOrigin needs to be GetAbsOrigin(). But this is not the problem.

    Following code kills my Unit, but the respawn location stays the same. By the way: my trigger is trigger_hero

    function SetRespawnPositionCenterOf(trigger)
        local unit = trigger.activator
        local caller = trigger.caller
        if unit:IsRealHero() then
            unit:SetRespawnPosition(caller:GetAbsOrigin())
        end
        unit:ForceKill(true)
    end
    
  • edited June 2015 Posts: 1,670

    Try printing the caller:GetAbsOrigin() and comparing it, maybe its not getting it correctly.

    Now, if SetRespawnPosition doesn't work (I can't remember if it was working properly) you'll have to do somewhat of a listen when hero respawns, and instantly move it to that position.
    You can do that on an else of this call in barebones

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • edited July 2015 Posts: 3

    I came up with this a solution that i am using in my map. Mine is a little different since i don't trigger the respawn, i just assign a "random" location when the hero respawns but that might work better for you.

    First i listen to the npc_spawned event and then i pass the npc to my GameMode:RandomRespawnPoint funciton

    ListenToGameEvent("npc_spawned", OnNPCSpawned, nil)
    
    function OnNPCSpawned(event)
        local npc = EntIndexToHScript(event.entindex)
        GameMode:RandomRespawnPoint(npc)
    end
    
    function GameMode:RandomRespawnPoint(npc)
        if npc:IsRealHero() then
            if GameRules:State_Get() ~= DOTA_GAMERULES_STATE_PRE_GAME then 
                local vector = getRandomRespawnVector()
                npc:SetOrigin(vector)
            end
        end
    end
    
    function getRandomRespawnVector()
        local points = Entities:FindAllByName('ob_respawn_point')
        local i = RandomInt( 1, 16 )
        return points[i]:GetAbsOrigin()
    end
    

    The ob_respawn_point is just a entity of class "info_trigger" that i put all over the map. I have 16 of them. Hope that helps someone!

  • Posts: 1,670

    @Suzamaki The check for npc:IsRealHero() should be in the OnNPCSpawned itself, so you avoid calling other functions earlier when you don't want to. But yup that solution is legit

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • Posts: 3

    @Noya Updated my post. Good call