fateanother icon indicating copy to clipboard operation
fateanother copied to clipboard

GetPlayerOwner does not work when player has left the game

Open gelguy opened this issue 9 years ago • 3 comments

The GetPlayerOwner() function is used quite a few times in the scripts, most noticeably when taking Master 2 attributes.

    local caster = keys.caster
    local pid = caster:GetPlayerOwnerID()
    local hero = PlayerResource:GetSelectedHeroEntity(pid)

However, I believe it returns nil if the player has disconnected from the game, both before and after abandoning.

This makes heroes who have left unable to take their attributes.

This also occurs for Caster 5 who cannot summon a Workshop again if the old Workshop is destroyed while disconnected.

I'm not sure if there is an API to get the player for a disconnected player, but in most of the cases we can avoid the need to go through pid by setting the hero unit directly as a field e.g. master.hero = GetSelectedHeroEntity(pid) since we can assume the player is connected at the time he enters the game.

gelguy avatar Oct 23 '16 11:10 gelguy

Actually, I started using PlayerResource:GetSelectedHeroEntity(pid) for all recent releases because it still works when player is disconnected. Same for GetPlayerOwnerID(), or it did 3 months ago when I tested it with other modders.

What does NOT work is GetPlayerOwner(), which had been widely used up until Ruler release. https://github.com/dun1007/fateanother/blob/master/game/dota_addons/fateanother/scripts/vscripts/saber_ability.lua#L688-L689

I should replace those with GetSelectedHeroEntity approach one day.

dun1007 avatar Oct 24 '16 19:10 dun1007

Ah, I see.

So changing Master2 to GetPlayerOwnerID() should allow leavers' heroes to acquire attributes?

gelguy avatar Oct 25 '16 00:10 gelguy

No I just need to change all instances where I use GetPlayerOwner():GetAssignedHero() to GetSelectedHeroEntity(caster:GetPlayerOwnerID()), that will allow script an access to leaver's hero table which contains all information required to manipulate hero configs

dun1007 avatar Oct 25 '16 02:10 dun1007