• 🏆 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!

How to display xp table

Status
Not open for further replies.
Level 6
Joined
Mar 28, 2018
Messages
128
I want to display xp table and create something like this...i wanna set the xp for all units i'm killing.
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Giant Skeleton Warrior Level 1 General
    • Actions
      • Hero - Add 100 experience to (Killing unit), Show level-up graphics
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
You can use a Hashtable for this. The Parent key would be the Unit-type id of the (Dying unit), so in this case the Giant Skeleton Warrior, and the Child key could stay at 0. Then the Value would be the amount of Experience you want to reward when that type of unit dies.

Variables:
ExpHashtable = Hashtable
ExpUnitType = Unit-Type (array)
ExpRewarded = Integer (array)
ExpId = Integer
ExpLoop = Integer

  • Exp Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet ExpHashtable = (Last created hashtable)
      • -------- --------
      • Set VariableSet ExpUnitType[1] = Giant Skeleton Warrior
      • Set VariableSet ExpRewarded[1] = 100
      • -------- --------
      • Set VariableSet ExpUnitType[2] = Red Dragon
      • Set VariableSet ExpRewarded[2] = 200
      • -------- --------
      • Set VariableSet ExpUnitType[3] = Pit Lord
      • Set VariableSet ExpRewarded[3] = 5000
      • -------- --------
      • -------- This should loop from 1 to X, where X is the total number of ExpUnitTypes! --------
      • For each (Integer ExpLoop) from 1 to 3, do (Actions)
        • Loop - Actions
          • Custom script: set udg_ExpId = udg_ExpUnitType[udg_ExpLoop]
          • Hashtable - Save ExpRewarded[ExpLoop] as 0 of ExpId in ExpHashtable.
Now whenever a unit dies you can load the ExpRewarded from the Hashtable and add it to the Killing unit:
  • Exp Add
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: set udg_ExpId = GetUnitTypeId(GetTriggerUnit())
      • Hero - Add (Load 0 of ExpId from ExpHashtable.) experience to (Killing unit), Show level-up graphics


This could even be expanded to store other types of data to each Unit-Type by using different Child keys.
For example, you could Save how much Copper and Silver (custom resources) the Unit-types reward you:
  • Loop - Actions
    • Custom script: set udg_ExpId = udg_ExpUnitType[udg_ExpLoop]
    • Hashtable - Save ExpRewarded[ExpLoop] as 0 of ExpId in ExpHashtable.
    • Hashtable - Save CopperRewarded[ExpLoop] as 1 of ExpId in ExpHashtable.
    • Hashtable - Save SilverRewarded[ExpLoop] as 2 of ExpId in ExpHashtable.
Note the different Child keys -> 0, 1, 2.
You would Load 1 of ExpId to get Copper and Load 2 of ExpId to get Silver.
You'd also want to rename the Variables to something more generic since this Hashtable would no longer be used just for tracking Experience.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,014
@Uncle
I find (when writing examples like you did) that removing need to remember to set the correct index for each item in the list helps avoid a lot of simple errors. And it sets the upper bound for the loop for you.
  • Set EXP_COUNT = (EXP_COUNT + 1)
  • Set ExpUnitType[EXP_COUNT] = Giant Skeleton Warrior
  • Set ExpRewarded[EXP_COUNT] = 100
  • -------- --------
  • Set EXP_COUNT = (EXP_COUNT + 1)
  • Set ExpUnitType[EXP_COUNT] = Red Dragon
  • Set ExpRewarded[EXP_COUNT] = 200

Displaying the XP in the way you want might be a little difficult, @IRoILaurentiu. If you just intend to show the total gained then that's easy. But if you also want to show something like "Level 7 (54%)" that will take a bit more work. The constants (found in "gameplay constants") that affect the XP -> level conversion are not readable in game with any triggers. You will need to manually set some real variables equal to the values of the constants (and update them if you change the actual XP constants for any reason), and then do the appropriate arithmetic to compute the required XP for the current/next/previous level and use that to alter the shown text.
 
Last edited:
On default Exp gained is calced by the unit level of the unit killed and the values in game constants. You could change the game constants and the level of the creeps to fit your wanted values.
The function used to calc exp is:
When no entry at Table[x] -> f(x) = A*f(x-1) + B*x + C
A is previous factor
B is level factor
C is constant
Table[x] values

When you want an easy fixed rising system make A=1, B=0 and C the exp per level. Also could increase the max unit level.
 
Status
Not open for further replies.
Top