(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > JASS Functions

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 08-03-2007, 02:05 PM   #1 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


Player Color Code Functions

Well I saw a real lack of basic useful JASS functions so heres three nice easy ones that involve player colour codes. (the bottom one is by me)

GetPlayerColorString
by Silvenon

function GetPlayerColorString takes player p, string s returns string
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        set s = "|cffFF0202" + s + "|r"
    elseif c == PLAYER_COLOR_BLUE then
        set s = "|cff0041FF" + s + "|r"
    elseif c == PLAYER_COLOR_CYAN then
set s = "|cff1BE5B8" + s + "|r"
    elseif c == PLAYER_COLOR_PURPLE then
set s = "|cff530080" + s + "|r"
    elseif c == PLAYER_COLOR_YELLOW then
set s = "|cffFFFC00" + s + "|r"
    elseif c == PLAYER_COLOR_ORANGE then
set s = "|cffFE890D" + s + "|r"
    elseif c == PLAYER_COLOR_GREEN then
set s = "|cff1FBF00" + s + "|r"
    elseif c == PLAYER_COLOR_PINK then
set s = "|cffE45AAF" + s + "|r"
    elseif c == PLAYER_COLOR_LIGHT_GRAY then
set s = "|cff949596" + s + "|r"
    elseif c == PLAYER_COLOR_LIGHT_BLUE then
set s = "|cff7DBEF1" + s + "|r"
    elseif c == PLAYER_COLOR_AQUA then
set s = "|cff0F6145" + s + "|r"
    elseif c == PLAYER_COLOR_BROWN then
set s = "|cff4D2903" + s + "|r"
    else
set s = "|cffFFFFFF" + s + "|r"
    endif
    set c = null
    return s
endfunction

Like other Player Color String functions, but takes the string to colorize to be slightly more efficient

GetPlayerColorString
by PurgeandFire111

function GetPlayerColorString takes player p returns string
//Credits to Andrewgosu from TH for the color codes//
    local playercolor c = GetPlayerColor(p)
    local string s
    if c == PLAYER_COLOR_RED then
        set s = "|cffFF0202"
    elseif c == PLAYER_COLOR_BLUE then
        set s = "|cff0041FF"
    elseif c == PLAYER_COLOR_CYAN then
        set s = "|cff1BE5B8"
    elseif c == PLAYER_COLOR_PURPLE then
        set s = "|cff530080"
    elseif c == PLAYER_COLOR_YELLOW then
        set s = "|cffFFFC00"
    elseif c == PLAYER_COLOR_ORANGE then
        set s = "|cffFE890D"
    elseif c == PLAYER_COLOR_GREEN then
        set s = "|cff1FBF00"
    elseif c == PLAYER_COLOR_PINK then
        set s = "|cffE45AAF"
    elseif c == PLAYER_COLOR_LIGHT_GRAY then
        set s = "|cff949596"
    elseif c == PLAYER_COLOR_LIGHT_BLUE then
        set s = "|cff7DBEF1"
    elseif c == PLAYER_COLOR_AQUA then
        set s = "|cff0F6145"
    elseif c == PLAYER_COLOR_BROWN then
        set s = "|cff4D2903"
    else
        set s = "|cffFFFFFF"
    endif
    set c = null
    return s
endfunction


This function returns the player colour code in case you want to use it for another function. e.g :
Quote:
Originally Posted by PurgeandFire111 View Post
call BJDebugMsg(GetPlayerColorString(p)+" This is orange text|r")

It'll display this:
Player 5 (Orange) This is orange text|r

If you want, I guess you could remove the GetPlayerName+|r and instead have this function.

function PlayerColorText takes player whichPlayer, string text returns string
    return GetPlayerColorString(whichPlayer)+text+"|r"
endfunction

GetPlayerNameColoured
I did not create the first of this type, but I did this one from scratch:

function GetPlayerNameColoured takes player p returns string
    local playercolor pc = GetPlayerColor(p)
    local string s
    if pc == PLAYER_COLOR_RED then
        set s = "|cffFF0202"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_BLUE then
        set s = "|cff0041FF"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_CYAN then
        set s = "|Cff1BE5B8"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_PURPLE then
        set s = "|CFF530080"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_YELLOW then
        set s = "|CFFFFFC00"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_ORANGE then
        set s = "|CFFFE890D"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_GREEN then
        set s = "|CFF1FBF00"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_PINK then
        set s = "|CFFE45AAF"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_LIGHT_GRAY then
        set s = "|CFF949596"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_LIGHT_BLUE then
        set s = "|CFF7DBEF1"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_AQUA then
        set s = "|CFF0F6145"+GetPlayerName(p)+"|r"
    elseif pc == PLAYER_COLOR_BROWN then
        set s = "|CFF4D2903"+GetPlayerName(p)+"|r"
    else // A safty function
        set s = "|CFFFFFFFF"+GetPlayerName(p)+"|r"
    endif
    set pc = null
    return s
endfunction
Credit to PurgeAndFire for the colour scripts.

The function returns the players name coloured, according to what colour he/she is. It does not return the color based on what playerslot the player is in, and is compatible with changing player colors.
- Kixer

Updated:
Fixed the colours using a program called Chaos Spectrum by Fougie47, hopefully they are correct now.
The playercolor pc is nulled because it is a handle.
Updated:
Now uses the colour codes that have been suggested as they seem to be correct.
*Updated*
__________________

[ Current Project : Fallen Legends - Anub'arak ]

Last edited by PurplePoot; 08-30-2007 at 06:05 PM..
Kixer is offline  
Old 08-05-2007, 12:48 AM   #2 (permalink)
 
Thunder_eye's Avatar

User
 
Join Date: May 2004
Posts: 207

Thunder_eye has little to show at this moment (5)


The color codes are not exactly correct.
__________________
Thunder_eye is offline  
Old 08-05-2007, 12:58 AM   #3 (permalink)
 
PurgeandFire111's Avatar

User Title
 
Join Date: Nov 2006
Posts: 1,029

PurgeandFire111 is a jewel in the rough (155)


Damn you... Damn you!! Damn you so much... :P

The thing is, I made this one a while back. Technically, Diablo-dk did part of it and I finished it then he made more crazy stuff and stuff. The color codes seem kind of incorrect, maybe you should use Andrewgosu's; or just use my code:
function GetPlayerColorString takes player p returns string
//Credits to Andrewgosu from TH for the color codes//
    local playercolor c = GetPlayerColor(p)
    if c == PLAYER_COLOR_RED then
        return "|cffFF0202"
    elseif c == PLAYER_COLOR_BLUE then
        return "|cff0041FF"
    elseif c == PLAYER_COLOR_CYAN then
        return "|cff1BE5B8"
    elseif c == PLAYER_COLOR_PURPLE then
        return "|cff530080"
    elseif c == PLAYER_COLOR_YELLOW then
        return "|cffFFFC00"
    elseif c == PLAYER_COLOR_ORANGE then
        return "|cffFE890D"
    elseif c == PLAYER_COLOR_GREEN then
        return "|cff1FBF00"
    elseif c == PLAYER_COLOR_PINK then
        return "|cffE45AAF"
    elseif c == PLAYER_COLOR_LIGHT_GRAY then
        return "|cff949596"
    elseif c == PLAYER_COLOR_LIGHT_BLUE then
        return "|cff7DBEF1"
    elseif c == PLAYER_COLOR_AQUA then
        return "|cff0F6145"
    elseif c == PLAYER_COLOR_BROWN then
        return "|cff4D2903"
    else
        return "|cffFFFFFF"
    endif
endfunction
I don't think playercolor's would need to be nulled... Though I'm not sure. I just know it isn't a very big leak. :D

But your's is good. +rep
__________________
Vote For The Hive Workshop!
Funny but the TRUTH! :
Quote:
Originally Posted by Sopho
Unprotecting maps is not right its like crime and YOU GO MAKE YOUR OWN MAP AND BE HAPPY! Don't be gay n00b!

1. You can if it is yours but you should not if it is not. It is like stealing information and using it as if it is your own. It si gay stuff and people who unprotect maps are gay themselves.
PurgeandFire111 is offline  
Old 08-05-2007, 06:05 AM   #4 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


Ok I'll update the colours asap, probably later today or at least by tomorrow...
__________________

[ Current Project : Fallen Legends - Anub'arak ]
Kixer is offline  
Old 08-05-2007, 03:11 PM   #5 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


*Script Updated*
Now the colours are correct ( or to close to be noticably wrong ).
Also fixed a major stupid mistake with the use of light blue twice.
__________________

[ Current Project : Fallen Legends - Anub'arak ]
Kixer is offline  
Old 08-05-2007, 03:49 PM   #6 (permalink)
 
Thunder_eye's Avatar

User
 
Join Date: May 2004
Posts: 207

Thunder_eye has little to show at this moment (5)


They are, as you said, still not exactly correct. Should be fixed.
__________________
Thunder_eye is offline  
Old 08-05-2007, 04:47 PM   #7 (permalink)
 
DragoonZombie's Avatar

Back to business.
 
Join Date: Mar 2005
Posts: 286

DragoonZombie is a jewel in the rough (194)DragoonZombie is a jewel in the rough (194)


The color codes from PurgeandFire are correct. I'm using them too.
Heres a example

The upper ones are the custom text messages.
__________________
Get 3ds Max 5 :: PM me - Available again!
DragoonZombie is offline  
Old 08-05-2007, 05:44 PM   #8 (permalink)
 
Thunder_eye's Avatar

User
 
Join Date: May 2004
Posts: 207

Thunder_eye has little to show at this moment (5)


__________________
Thunder_eye is offline  
Old 08-05-2007, 08:49 PM   #9 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


*Updated*
Updated again to now use the suggested and seemingly preferred colour codes.
Thanks to all that made suggestions and pointed out mistakes.
__________________

[ Current Project : Fallen Legends - Anub'arak ]
Kixer is offline  
Old 08-05-2007, 10:48 PM   #10 (permalink)
 
PurgeandFire111's Avatar

User Title
 
Join Date: Nov 2006
Posts: 1,029

PurgeandFire111 is a jewel in the rough (155)


I think you should remove the "GetPlayerName(p)" for the "set s = " part.

The thing is, some people might just want the color. So if they did this:
call BJDebugMsg(GetPlayerColorString(p)+" This is orange text|r")

It'll display this:
Player 5 (Orange) This is orange text|r

If you want, I guess you could remove the GetPlayerName+|r and instead have this function.

function PlayerColorText takes player whichPlayer, string text returns string
    return GetPlayerColorString(whichPlayer)+text+"|r"
endfunction

__________________
Vote For The Hive Workshop!
Funny but the TRUTH! :
Quote:
Originally Posted by Sopho
Unprotecting maps is not right its like crime and YOU GO MAKE YOUR OWN MAP AND BE HAPPY! Don't be gay n00b!

1. You can if it is yours but you should not if it is not. It is like stealing information and using it as if it is your own. It si gay stuff and people who unprotect maps are gay themselves.
PurgeandFire111 is offline  
Old 08-06-2007, 05:11 AM   #11 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

They're both handy functions, with the GetPlayerNameColored function being a bit more specialized, but useful nonetheless.

I can't test those strings at the exact moment, but since there seems to be a general consensus that they're close enough to correct, ~approved~
PurplePoot is offline  
Old 08-06-2007, 05:40 AM   #12 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


Thank you Purple,
Im going to update this and change it into player colour string functions if no one minds.
I'll add Purge's GetPlayerColourString and maybe a few examples of use later today...
__________________

[ Current Project : Fallen Legends - Anub'arak ]
Kixer is offline  
Old 08-06-2007, 01:14 PM   #13 (permalink)
 
HappyTauren's Avatar

Banned
 
Join Date: Nov 2006
Posts: 6,459

HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)


Ow man you really had to use so many "elseif"-s...

globals
string array GPC_PCString
endglobals

library GPC
function GetPlayerColour takes player p returns string
return GPC_PCString[GetPlayerId(p)]
endfunction

function GetPlayerNameColoured takes player p returns string
return GPC_PCString[GetPlayerId(p)]+GetPlayerName(p)+"|r"
endfunction

function GetPlayerIdColour takes integer i returns string
return GPC_PCString[i]
endfunction

function GetPlayerIdNameColoured takes integer i returns string
return GPC_PCString[i]+GetPlayerName(Player(i))+"|r"
endfunction

function InitTrig_GetPlayerColour takes nothing returns nothing
set GPC_PCString[0] = "|c00ff0000"
set GPC_PCString[1] = "|c000000ff"
set GPC_PCString[2] = "|c0018e7bd"
set GPC_PCString[3] = "|c00520084"
set GPC_PCString[4] = "|c00ffff00"
set GPC_PCString[5] = "|c00ff8a08"
set GPC_PCString[6] = "|c0018be00"
set GPC_PCString[7] = "|c00e759ad"
set GPC_PCString[8] = "|c00949694"
set GPC_PCString[9] = "|c007bbef7"
set GPC_PCString[10] = "|c00086142"
set GPC_PCString[11] = "|c004a2800"
endfunction
endlibrary

You could do it all this way, it is simplier, and waaay faster. These are 100% right colours, for nitpicking people like Thunder_eye :)
Attached Files
File Type: w3x Player Color Tag System.w3x (11.8 KB, 118 views)
HappyTauren is offline  
Old 08-06-2007, 01:43 PM   #14 (permalink)
 
Kixer's Avatar

Yawn...
 
Join Date: Jul 2006
Posts: 751

Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)Kixer will become famous soon enough (111)


There really is no need to use vJASS,
This is a simple new JASSer orientated script....
__________________

[ Current Project : Fallen Legends - Anub'arak ]
Kixer is offline  
Old 08-06-2007, 02:02 PM   #15 (permalink)
 
HappyTauren's Avatar

Banned
 
Join Date: Nov 2006
Posts: 6,459

HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)HappyTauren has much of which to be proud (1015)


but this is uber fast. It is WAAAAAAAAAAAAAAAAAAAAAAAAAY faster to use variables instead of elseif, it has been proved many times. And anyawy, kixer, you can rip colours from my system ;)
HappyTauren is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump