Problems adding custom ability to unit

Zurtrogx

Active Member
Reaction score
24
Problem status: SOLVED

______________________________________________________________

In my map, there are three races, x, l, and b. There are three unit types, m, a, and r. And, there are three building types, l, m, and h.
When you build you building and select your unit type, the building will gain two abilities depending on what you race is, what unit type you selected, and what type of building it is.

For example, lets say you are race x, have building m, and choose unit type r.
The raw codes for the abilities will be:
Xmrd and Xmrd

In order to do this, I've made a function that converts the string into an Ability ID (10 digit number) and then add the ability with UnitAddAbilityBJ.

However, I seem to be having some problems.

The ability doesn't add properly; it instead adds an ability similar to it (For example, I want to add Xmrd, it will add XmaD). It also lags for a few seconds when I try to add these abilities.
However, if I add another custom ability, such as XbaS it works, or Ak02 will also work. The strange thing is that it won't lag when I try to add these abilities.

Using the Display Text to All players, I have discovered that the Raw Code generated in the string matches that of the ability I want to add AND the Ability Id also matches that of the ability I want to add. However, it still continues to add the wrong ability.

EDIT: I've created a map that allows you to see what's happening. Use "-a<raw code>" to add an ability and "-r<raw code>" to remove an ability. Try add Bhaa (which won't work) and then Bh99 or Bhat (which are identical copies of Bhaa) which do work. I think it might have something to do with the raw code that is causing it to malfunction. I reccommend using windowed mode so you can Alt+Tab between the object editor (to see the raw codes) and Warcraft 3. I have used newgen to make this map.

Here are the two triggers I am using to make this work. I've cropped out some of the unneccesary information to make it easier for you to view.

Trigger:
  • setup variables
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set character_value_string[0] = ABCDEFGHIJKLMNOPQRSTUVWXYZ
      • For each (Integer setup_loop) from 0 to 9, do (Actions)
        • Loop - Actions
          • Set character_value_string[(setup_loop + 48)] = (String(setup_loop))
      • For each (Integer setup_loop) from 1 to 26, do (Actions)
        • Loop - Actions
          • Set character_value_string[(setup_loop + 64)] = (Substring(character_value_string[0], setup_loop, setup_loop))
          • Set character_value_string[(setup_loop + 96)] = (String((Substring(character_value_string[0], setup_loop, setup_loop))) as Lower case)



The trigger below also does other functions but they have been removed since they are not necessary for adding the ability. Remove this has problem reduced the length of this trigger by 60%+. If you do wish to view the WHOLE trigger, please let me know and I will post it.
Trigger:
  • Unit Type upgrade
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to Melee
          • (Ability being cast) Equal to Ranged
          • (Ability being cast) Equal to Magic
    • Actions
      • Unit - Order (Triggering unit) to Stop
      • Set US_structure_type = (Substring((String((Unit-type of (Triggering unit)))), 10, 10))
      • Set US_unit_type_selected = (Substring((String((Name of (Ability being cast))) as Lower case), 1, 2))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • US_unit_type_selected Equal to ma
        • Then - Actions
          • Set US_upgrade_string_unit_type = a
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • US_unit_type_selected Equal to me
        • Then - Actions
          • Set US_upgrade_string_unit_type = m
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • US_unit_type_selected Equal to ra
        • Then - Actions
          • Set US_upgrade_string_unit_type = r
        • Else - Actions
      • Set US_upgrade_string = (((String(US_race_type[(Player number of (Owner of (Triggering unit)))]) as Upper case) + US_structure_type) + (US_upgrade_string_unit_type + a))
      • Set US_upgrade_AbilID = 0
      • Set US_upgrade_power = 3.00
      • For each (Integer US_upgrade_check_loop1) from 1 to 4, do (Actions)
        • Loop - Actions
          • For each (Integer US_upgrade_check_loop2) from 48 to 122, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Substring(US_upgrade_string, US_upgrade_check_loop1, US_upgrade_check_loop1)) Equal to character_value_string[US_upgrade_check_loop2]
                • Then - Actions
                  • Set US_upgrade_AbilID = (US_upgrade_AbilID + (US_upgrade_check_loop2 x (Integer((Power(256.00, US_upgrade_power))))))
                  • Set US_upgrade_power = (US_upgrade_power - 1.00)
                • Else - Actions
      • Custom script: call UnitAddAbilityBJ(udg_US_upgrade_AbilID, GetTriggerUnit() )
      • Set US_upgrade_string = (((String(US_race_type[(Player number of (Owner of (Triggering unit)))]) as Upper case) + US_structure_type) + (US_upgrade_string_unit_type + d))
      • Set US_upgrade_AbilID = 0
      • Set US_upgrade_power = 3.00
      • For each (Integer US_upgrade_check_loop1) from 1 to 4, do (Actions)
        • Loop - Actions
          • For each (Integer US_upgrade_check_loop2) from 48 to 122, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Substring(US_upgrade_string, US_upgrade_check_loop1, US_upgrade_check_loop1)) Equal to character_value_string[US_upgrade_check_loop2]
                • Then - Actions
                  • Set US_upgrade_AbilID = (US_upgrade_AbilID + (US_upgrade_check_loop2 x (Integer((Power(256.00, US_upgrade_power))))))
                  • Set US_upgrade_power = (US_upgrade_power - 1.00)
                • Else - Actions
      • Custom script: call UnitAddAbilityBJ( udg_US_upgrade_AbilID, GetTriggerUnit() )
      • Unit - Remove Melee from (Triggering unit)
      • Unit - Remove Ranged from (Triggering unit)
      • Unit - Remove Magic from (Triggering unit)
 

Attachments

  • AddRemove abilities.w3x
    143.8 KB · Views: 58

Zurtrogx

Active Member
Reaction score
24
I've noticed that when I do the following:

Custom script: call DisplayTimedTextToForce( GetPlayersAll(), 30, GetAbilityName(udg_US_upgrade_AbilID) )
Custom script: call UnitAddAbilityBJ( udg_US_upgrade_AbilID, udg_UNIT )


It seems to work fine. But, when I do this:

Custom script: call UnitAddAbilityBJ( udg_US_upgrade_AbilID, udg_UNIT )
Custom script: call DisplayTimedTextToForce( GetPlayersAll(), 30, GetAbilityName(udg_US_upgrade_AbilID) )


It adds the correct ability, but it doesn't show the Tooltip extended.


However, this solution only works sometimes. And, other times, when an ability is add to one unit it causes an ability to replace an existing ability on another unit that wasn't referred to in the trigger.

EDIT: I changed the Raw Code and it works fine now.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top