System Multiple Custom Values

Exfyre

hmm...
Reaction score
60
This system allows you to attach multiple custom values to a unit via GUI.

Import Difficulty: Easy
GUI/JASS: GUI
Difficulty of Use: Moderate
Leakless: yup
Other: This system recycles unused custom values as units are removed from the game.

I made this earlier today because i was making a TD which uses the custom values for selling. I also wanted to use it to keep track of how many kills each tower made. So I made this.

Importing:
Code:
Steps:
Copy this trigger into your map.
Create variables:
  MCVS_spacer = integer.  default value should be zero
  MCVS_NumberOfValuesPerUnit = integer.  default value should be the number of custom values you want each unit to have.
  MCVS_booleantest = boolean.  default value should be true.
  MCVS_CustomValue = integer array with 8192 dimensions.  default value should be zero.

Use:
When using this system, you can call the custom value by the following syntax (in GUI):
MCVS_CustomValue[Custom Value of (Your Unit Here)] + ((index of your custom value)- 1)

NOTE:
If you would like to give preset units custom values, copy this trigger and replace the event 'Unit - A unit enters (Entire map)' with the event 'Map initialization'

Main Code
Code:
Set Custom Values
    Events
        Unit - A unit enters (Entire map)
    Conditions
    Actions
        Set MCVS_spacer = (1 - MCVS_NumberOfValuesPerUnit)
         Do Multiple ActionsFor each (Integer A) from 1 to (8172 / MCVS_NumberOfValuesPerUnit), do (Actions)
            Loop - Actions
                Set MCVS_booleantest = True
                Set MCVS_spacer = (MCVS_spacer + MCVS_NumberOfValuesPerUnit)
                Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
                    Loop - Actions
                         Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                            Then - Actions
                                 Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        (Custom value of (Picked unit)) Equal to (==) MCVS_spacer
                                    Then - Actions
                                        Set MCVS_booleantest = False
                                    Else - Actions
                            Else - Actions
                 Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        MCVS_booleantest Equal to (==) True
                    Then - Actions
                        Unit - Set the custom value of (Triggering unit) to MCVS_spacer
                        Skip remaining actions
                    Else - Actions
 

Attachments

  • Multi Custom Value System.w3x
    16.6 KB · Views: 252

Flare

Stops copies me!
Reaction score
662
Interesting way of doing it (you are assigning a block of array values to each unit, or...?)

If you are assigning an array value to the unit, I can see one problem.

Unit 1 has custom value 6 index 5
Unit 2 has custom value 5 index 6

Both of those units units will have the same place in the array since 6+(5-1) = 5+(6-1). If they both do something which relies on the indexes for MUI, bad things could happen?

EDIT: Doesn't (Units in Playable Map Area) leak?
 

darkRae

Ueki Fan (Ueki is watching you)
Reaction score
173
Code:
Custom Script: Set bj_wantDestroyGroup = true
Unit Group - Pick units . . .
 
Reaction score
333
The only problem is, each time a unit enters the map all the other units are looped through. This seems suboptimal to me.
 

Exfyre

hmm...
Reaction score
60
yeah. I used three custom values per unit, and after there were about 100 units oln the field, it lagged pretty bad everytime a unit came into the map, but that may be a aresult of the unit group leak
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top