Results 1 to 2 of 2

Thread: [Suggestion] Precache cosmetic models on demand when using ReplaceHeroWith

  1. #1
    Basic Member Noya's Avatar
    Join Date
    Dec 2011
    Location
    Uruguay
    Posts
    12,904

    [Suggestion] Precache cosmetic models on demand when using ReplaceHeroWith

    When trying to port the old Wisp selection system from WC3, I encountered a problem with ReplaceHeroWith and the way Precache works.

    Basically, after spawning with a pre-defined hero (made with the very handy dota_custom_game_events.ForceSelectHero) when stepping on a circle, the Wisp gets replaced by whatever hero the player wished to get into the game.

    Spoiler: 


    Code:
    function ReplaceByJugg(event)
            local newHero = PlayerResource:ReplaceHeroWith(event.activator:GetPlayerID(), "npc_dota_hero_juggernaut", 0, 0)
            local starting_point = Vector(-6030,-7611, 128)
            FindClearSpaceForUnit(newHero, starting_point, true)
    end
    npc_dota_hero_juggernaut is an overriden hero in npc_heroes_custom.txt

    The problem is that when ReplaceHeroWith is invoked, the replaced unit will try to use the player cosmetics, which won't be precache'd unless they were loaded specifically in the Precache() block.

    Spoiler: 


    Here is the console debug: http://hastebin.com/qurasidifa.coffee

    After adding the Precache lines corresponding to my own Juggernaut cosmetics, the models are now showing properly (as expected).
    Code:
    PrecacheModel("models/items/juggernaut/wandering_demon_sword/wandering_demon_sword.vmdl", context )
    PrecacheModel("models/items/juggernaut/scowl_of_kogu/scowl_of_kogu.vmdl", context )
    PrecacheModel("models/items/juggernaut/sturdy_bracers_of_the_exiled_ronin/sturdy_bracers_of_the_exiled_ronin.vmdl", context )
    PrecacheModel("models/items/juggernaut/jugg_flag/jugg_flag.vmdl", context )
    PrecacheModel("models/items/juggernaut/armour_of_the_exiled_ronin/armour_of_the_exiled_ronin.vmdl", context )
    Spoiler: 


    But this brings a worrying concern: I need to do a PrecacheModel for each cosmetic possibility, for each hero I want to replace with! And this won't include models which are not currently supported on Source 2.

    If ReplaceHeroWith automatically looked upon the player's cosmetics, that would be nice!



    Note: This only happens when the game is launched through the main Dota 2 Client, as opposed to Workshop Tools which don't use player-owned cosmetics when loading into the game.

  2. #2
    Basic Member Noya's Avatar
    Join Date
    Dec 2011
    Location
    Uruguay
    Posts
    12,904
    Update with a temporal sub-optimal fix:

    Code:
            print('[Precache] Start')
    	local wearables = LoadKeyValues("scripts/items/items_game.txt")
    
    	local wearablesList = {}
    	local precacheWearables = {}
    	for k, v in pairs(wearables) do
    		if k == 'items' then
    			wearablesList = v
    		end
    	end
    	local counter = 0
    	
    	--check wearablesList for certain hero cosmetics
    	for k, v in pairs(wearablesList) do
    	  	if IsForHero("npc_dota_hero_juggernaut", k, wearablesList[k]) then
                for key, value in pairs(wearablesList[k]) do
    				if key == 'model_player' then
    					counter = counter+1
    					precacheWearables[value] = true
    				end
    			end
    		end
    	end
    
    	for wearable,_ in pairs( precacheWearables ) do
    		print("Precache: " .. wearable)
    		PrecacheResource( "model", wearable, context )
    	end
    	print('[Precache]' .. counter .. " models loaded!")
    	print('[Precache] End')
    source in here

    At the moment with my 8 playable heroes I get 295 models loaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •