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

[Spell] Changing colour of unit on purpose

Status
Not open for further replies.
Level 3
Joined
Feb 19, 2016
Messages
32
Greetings.
I want to make simple command that would change colour of target unit/building. I'm using hashtables to save values for each player, but I don't really know how to split a string by spaces, instead of splitting it by lenght, like 'substring' does.
The trigger is pretty simple(Check below). I want to make a command that sets values 3, 4 and 5 to chosen. Like -rgb X Y Z. I struggle here, cause every of those three variables can be both a one, two and three digit number.
I also would like to avoid JASS, for I don't know this language(Yet, if it's the only way, I'll try it).
PS: 6th value is implemented by -alpha command.

  • Colour Command Execute
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Unit-type of (Ordered unit)) Equal to ModDecoUnitType
          • (Issued order) Equal to (Order(controlmagic))
    • Actions
      • Set RotatedUnit = (Target unit of issued order)
      • Set RotatedUnitOwner = (Owner of RotatedUnit)
      • Set RotatedUnitOwnerNumber = (Player number of RotatedUnitOwner)
      • Animation - Change RotatedUnit's vertex coloring to ((Load 3 of RotatedUnitOwnerNumber from PlayerProperties)%, (Load 4 of RotatedUnitOwnerNumber from PlayerProperties)%, (Load 5 of RotatedUnitOwnerNumber from PlayerProperties)%) with (Load 6 of RotatedUnitOwnerNumber from PlayerProperties)% transparency
 
Last edited:
It's possible in GUI but you don't really need any JASS knowledge to use this.

  • Trigger
    • Events
      • Player - Player 1 (Red) types a chat message containing -rgb as A substring
      • Player - Player 2 (Blue) types a chat message containing -rgb as A substring
    • Conditions
    • Actions
      • -------- Get the values from the entered chat string --------
      • Set StringVar = (Substring((Entered chat string), 6, 999))
      • -------- Add a space to the end of the string --------
      • Set StringVar = (StringVar + )
      • -------- Find values --------
      • Custom script: set udg_StringArray[0] = StringSplit(udg_StringVar, " ", 0)
      • Custom script: set udg_StringArray[1] = StringSplit(udg_StringVar, " ", 1)
      • Custom script: set udg_StringArray[2] = StringSplit(udg_StringVar, " ", 2)
      • -------- Display --------
      • Game - Display to (All players) the text: (Red: + StringArray[0])
      • Game - Display to (All players) the text: (Blue: + StringArray[1])
      • Game - Display to (All players) the text: (Green: + StringArray[2])
      • -------- Set colors --------
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Triggering player)) and do (Actions)
        • Loop - Actions
          • Animation - Change (Picked unit)'s vertex coloring to ((Real(StringArray[0]))%, (Real(StringArray[1]))%, (Real(StringArray[2]))%) with 0.00% transparency

All you need to do is copy the StringSplit function to your maps header.

You can do this by clicking the map icon / filename at the top left of your trigger editor and pasting in the code below.

JASS:
function StringSplit takes string source, string delimiter, integer index returns string
    local string out = ""
    local integer i = 0
    local integer c = 0
    local string s
    
    loop
        set s = SubString(source, i, i + 1)
        exitwhen s == null
        
        if (s == delimiter) then
            if (c == index) then
                return out
            endif
            set out = ""
            set c = c + 1
        else
            set out = out + s
        endif
        
        set i = i + 1
    endloop
    
    return null
endfunction
 
Status
Not open for further replies.
Top