HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with script

01-26-2008, 11:31 PM#1
Tastingo
Hey I'm creating a trigger that allows someone to change their unit's player color when they type the command -unit (color). It is going to be done locally so that they can only see it, but it doesn't seem to be working. I think it has to do with the checking of the first part of the substring, I think.

Collapse JASS:
function UnitColorChange takes nothing returns nothing
local group u = CreateGroup()
local boolexpr b = null
call GroupEnumUnitsOfPlayer(u, GetTriggerPlayer(), b)
call DestroyBoolExpr(b)
    if( SubString(GetEventPlayerChatString(), 0, 5) == "-unit ") then
        if( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "red") then
            if(GetLocalPlayer() == GetTriggerPlayer()) then
            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_RED )
            endif
                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "blue") then
                if(GetLocalPlayer() == GetTriggerPlayer()) then
                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_BLUE )
                endif
                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "teal") then
                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_CYAN )
                        endif
                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "purple") then
                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_PURPLE )
                                endif
                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "yellow") then
                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_YELLOW )
                                        endif
                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "orange") then
                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_ORANGE )
                                                endif
                                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "green") then
                                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_GREEN )
                                                        endif
                                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "pink") then
                                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_PINK )
                                                                endif
                                                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "gray") then
                                                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_LIGHT_GRAY )
                                                                        endif
                                                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "grey") then
                                                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_LIGHT_GRAY )
                                                                                endif
                                                                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "light blue") then
                                                                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_LIGHT_BLUE )
                                                                                        endif
                                                                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "lightblue") then
                                                                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_LIGHT_BLUE )
                                                                                                endif
                                                                                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "dark green") then
                                                                                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_AQUA )
                                                                                                        endif
                                                                                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "darkgreen") then
                                                                                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                                                    call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_AQUA )
                                                                                                                endif
                                                                                                                        elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "brown") then
                                                                                                                        if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                                                            call SetUnitColor( FirstOfGroup(u), PLAYER_COLOR_BROWN )
                                                                                                                        endif
                                                                                                                                elseif( SubString(GetEventPlayerChatString(), 6, StringLength(GetEventPlayerChatString())) == "black") then
                                                                                                                                if(GetLocalPlayer() == GetTriggerPlayer()) then
                                                                                                                                    call SetUnitColor( FirstOfGroup(u), ConvertPlayerColor(12) )
                                                                                                                                endif
        endif
    endif
call DestroyGroup(u)
endfunction
01-27-2008, 12:07 AM#2
MaD[Lion]
try make it goes from 1 to 6
01-27-2008, 12:15 AM#3
Av3n
GetLocalPlayer

-Av3n
01-27-2008, 12:34 AM#4
Tastingo
What about GetLocalPlayer... I don't see what you really mean by that. The color change is supposed to be only local for the person that types the message. I tried changing it to 1-6 instead of 0-5, still didn't work.
01-27-2008, 12:51 AM#5
Av3n
If you want to change the colour here's a simliar function: http://www.wc3jass.com/viewtopic.php?t=2746. Its further down, prehaps you can modify that function instead to work for your needs

Though i highly doubt in this situation it would be safe. Here's a reference to it: TuT

-Av3n
01-27-2008, 01:32 AM#6
Salbrismind
Your problem is not that part. Look at your ifs, they read the values between 6 and last line.

Code:
-unit red
|||||||||
123456789

The problem is it doesn't start at 6 it starts at 7. 6 is a space thats your problem.

Also ya its not 0 - 5 its 1 - 5.
01-27-2008, 03:20 AM#7
Ammorth
Using SubString() the first letter is at the index 0. Using SubStringBJ() (gui version) has the first letter at the index of 1.
01-27-2008, 04:07 AM#8
Salbrismind
Oh, so then the problem is its still supposed to be 6 for the ifs but the first part is 0 - 4...

Code:
-unit red
|||||||||
012345678
|   |

0 is start 4 is the t, in this one 5 is the space so 6 is the start of the word.
01-27-2008, 11:46 AM#9
MaD[Lion]
a gift for u who wanna make commands for changing color locally

teh code: just copy paste into a trigger and it works
Collapse JASS:
//! textmacro Commands
    //===> SETUP COLOR COMMAND <===//
    // You can change these commands to anything without worrying
    // about the main code.
    
        set Command = "-Color "
        set ColorStr[0]  = "red"
        set ColorStr[1]  = "blue"
        set ColorStr[2]  = "teal"
        set ColorStr[3]  = "purple"
        set ColorStr[4]  = "yellow"
        set ColorStr[5]  = "orange"
        set ColorStr[6]  = "green"
        set ColorStr[7]  = "pink"
        set ColorStr[8]  = "gray"
        set ColorStr[9]  = "light blue"
        set ColorStr[10] = "dark green"
        set ColorStr[11] = "brown"
    
    //===>
//! endtextmacro

library Boredom initializer Setup

    private keyword SetLocalPlayerUnitColor
    
    function CommandColorChange takes nothing returns nothing
        local string Command
        local string array ColorStr
        local string ChatStr = GetEventPlayerChatString()
        local integer i
        //---
        local integer t
        local integer s
        local integer color

        // Set the commands from text macro
        //! runtextmacro Commands()
        // Get the length of command
        set t = StringLength(Command)

        // First check if command is correct
        if (SubString(ChatStr,0,t)==Command) then
            // Start checking the color commands for each player
            set i = 0
            loop
                set s = StringLength(ColorStr[i])
                // If the color command is correct for current player
                if (SubString(ChatStr,t,t+s)==ColorStr[i]) then
                    // Change unit color of player locally
                    call SetLocalPlayerUnitColor.evaluate(GetTriggerPlayer(),GetPlayerColor(Player(i)))
                endif
            exitwhen i>=11
            set i = i+1
            endloop
        endif
    endfunction

    private function SetLocalPlayerUnitColor takes player pl, playercolor color returns nothing
        local group g = CreateGroup()
        local unit u
        call GroupEnumUnitsOfPlayer(g, pl, null)
        // Loop for each unit in group, we dont use GroupEnum for simplicity and control
        set u = FirstOfGroup(g)
        loop
            exitwhen u==null
            if (GetLocalPlayer() == pl) then
                call SetUnitColor(u,color)
            endif
            call GroupRemoveUnit(g,u)
            set u = FirstOfGroup(g)
        endloop
        // Clean ups
        call DestroyGroup(g)
        set g = null
        set u = null
    endfunction
    
    function Setup takes nothing returns nothing
        local trigger T = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerChatEvent( T,Player(i),"",false)
            exitwhen i >= 11
            set i = i+1
        endloop
        call TriggerAddAction( T, function CommandColorChange )
    endfunction
endlibrary
Attached Files
File type: w3mboredom.w3m (21.0 KB)
01-27-2008, 11:53 AM#10
Fireeye
Try changing the range of the Substring from 0 to 6.
Code:
 - u n i t   
0 1 2 3 4 5 6
01-27-2008, 04:20 PM#11
Salbrismind
Quote:
Originally Posted by Fireeye
Try changing the range of the Substring from 0 to 6.
Code:
 - u n i t   
0 1 2 3 4 5 6


That is pretty horribly wrong, sorry.
01-27-2008, 04:34 PM#12
Fireeye
Then explain my detailed WHY should it be wrong?
As much as i see it, it is correct.
01-27-2008, 05:02 PM#13
Ammorth
Quote:
Originally Posted by Salbrismind
That is pretty horribly wrong, sorry.

Yet he is correct. Irony is so much fun!
01-27-2008, 06:22 PM#14
Salbrismind
Quote:
Originally Posted by Fireeye
Then explain my detailed WHY should it be wrong?
As much as i see it, it is correct.

what you have there is nothing... Why are there spaces? Is the person gonna type it that way no...

they type it "-unit" not " - u n i t", besides 0 - 6 would still be wrong because your including a space before and after the text.

Is this some kind of joke or am I missing something big?
01-27-2008, 07:05 PM#15
Troll-Brain
i think it's just for be more readable, cause he did it for the numbers as well.