• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Changing ability tooltips for local player

Status
Not open for further replies.
Hi,

currently, in the hero selection part of my map, I have a copy of each hero as a neutral building. These buildings have dummy abilities that are just used to show the actual abilities of the respective hero, so they inherit the ability tooltip, name, and icon of the hero ability. This required about ~150 such abilities which all have to be loaded at the start of the game. Therefore, the loading time is increased drastically; by about 5-8 seconds.

I was thinking about adding the abilities to the selecter building only when a player selects it, but that would cause a ~0.5 second lag each time a new building is selected. That would probably be just as annoying as the increased loading time.

So I had instead the idea that all buildings have the same ~5 dummy abilities and whenever a player selects a new building, the tooltips, names, and icons of all those abilities are changed locally to the respective hero.

JASS:
function ChangeSelecterAbilities_Conditions takes nothing returns boolean
    //Point value is what I use to list the different buildings. So building 1 has point value 1, building 2 has point value 2 etc.
   return GetUnitPointValue(GetTriggerUnit()) > 0
endfunction

function ChangeSelecterAbilities takes nothing returns nothing
   local integer H = GetUnitPointValue(GetTriggerUnit())
   local integer A = 1
 
   if GetLocalPlayer() == GetTriggerPlayer() then
       loop
       exitwhen A > 7
           if heroAbility[A] != 0 then
               call BlzSetAbilityTooltip( selecterAbility[A], GetAbilityName(heroAbility[H][A]), 1 )
               call BlzSetAbilityExtendedTooltip( selecterAbility[A], BlzGetAbilityResearchExtendedTooltip(heroAbility[H][A], 1), 1 )
               call BlzSetAbilityIcon( selecterAbility[A], BlzGetAbilityIcon(heroAbility[H][A]) )
           endif
           set A = A + 1
       endloop
   endif
endfunction

//===========================================================================
function InitTrig_ChangeSelecterAbilities takes nothing returns nothing
   local integer N = 0
    set gg_trg_ChangeSelecterAbilities = CreateTrigger(  )
   loop
   exitwhen N > 9
       call TriggerRegisterPlayerSelectionEventBJ( gg_trg_ChangeSelecterAbilities, Player(N), true )
       set N = N + 1
   endloop
    call TriggerAddAction( gg_trg_ChangeSelecterAbilities, function ChangeSelecterAbilities )
    call TriggerAddCondition( gg_trg_ChangeSelecterAbilities, function ChangeSelecterAbilities_Conditions )
endfunction

Would this work or could it cause desyncs? Does anyone have suggestions for improvement? I want to make sure I'm getting this right because it will be quite some work to implement.

Cheers
 
Level 8
Joined
Oct 4, 2016
Messages
208
AFAIK changing variables locally, desyncs.
The better way to work with Local Player blocks its Define all variable stuff outside the IF. And then call methods in local block with already defined variables.

JASS:
local string str1,str2, str3.
loop
    exitwhen A > 7  
        if HeroAbility[A] != 0 then
            set str1 =....
            set str2 =....
            set str3 =....
             if localPlayerCond then
                 //change tooltips using string variables.
            endif
        endif
endloop
 
JASS:
function ChangeSelecterAbilities takes nothing returns nothing
   local integer H = GetUnitPointValue(GetTriggerUnit())
   local integer A = 1
   

   loop
   exitwhen A > 7
       if GetLocalPlayer() == GetTriggerPlayer() then
           if heroAbility[H][A] != 0 then
               call BlzSetAbilityTooltip( selecterAbility[A], GetAbilityName(heroAbility[H][A]), 1 )
               call BlzSetAbilityIcon( selecterAbility[A], BlzGetAbilityIcon(heroAbility[H][A]) )
               if A <= 5 then
                   call BlzSetAbilityExtendedTooltip( selecterAbility[A], BlzGetAbilityResearchExtendedTooltip(heroAbility[H][A], 1), 1 )
               else
                   call BlzSetAbilityExtendedTooltip( selecterAbility[A], BlzGetAbilityExtendedTooltip(heroAbility[H][A], 1), 1 )
               endif
           else
               call BlzSetAbilityIcon( selecterAbility[A], "ReplaceableTextures\\CommandButtons\\BTNInfoText.blp" )
           endif
       endif
       set A = A + 1
   endloop
endfunction

I tested it like this in multiplayer. It works.

Thanks!
 
Status
Not open for further replies.
Top