- Joined
- Nov 4, 2007
- Messages
- 337
Requirements: TimerUtils
Well, to me this is useful.
The PlayerColors library does actually the same stuff several other libraries do: It colors the name of a player.
With one difference: Instead of needing additional functions to get the player name colored,
this hooks GetPlayerName and makes it return a colored player name. Instead of having a GetPlayerNameColored function, this library provides GetPlayerNameUncolored.
Here an example:

Well, to me this is useful.
The PlayerColors library does actually the same stuff several other libraries do: It colors the name of a player.
With one difference: Instead of needing additional functions to get the player name colored,
this hooks GetPlayerName and makes it return a colored player name. Instead of having a GetPlayerNameColored function, this library provides GetPlayerNameUncolored.
JASS:
library PlayerColors initializer init requires TimerUtils
//===========================================================================
// Information:
//==============
//
// There are already several libraries that support functions like GetPlayerNameColored,
// I know. This does actually the same thing, but the other way round.
// It hooks GetPlayerName so that it will always return the player name colored nicely
// and has got a GetPlayerNameUncolored function instead of that.
//
// Since this uses native hooking, you don't have to go through old maps and replace
// every 'GetPlayerName' with 'GetPlayerNameColored'. And colored player names
// make a map seem much more professional, believe me.
//
// This is pretty stable and still works correctly if you use functions like SetPlayerName and
// SetPlayerColor.
//
//===========================================================================
// Implementation:
//===============
//
// 1. Download a tool called 'JassNewGen', and unpack it somewhere. You need that
// edit to use this tool. The 'JassNewGen' is used very commonly and offers other
// nice features. You can find it at:
// [url]http://www.wc3c.net/showthread.php?t=90999[/url]
// You should also update to the latest JassHelper.
//
// 2. Make a new trigger, and convert it to custom text. Insert everything
// the library contains into that trigger.
//
// 3. Download TimerUtils from this link:
//
// and do the same implemenation stuff with it.
//
// 3. Save your map.
//
//===========================================================================
globals
private string array ColorString
private string array PlayerNames
private boolean IsChangingColor = false
private boolean Init
endglobals
function GetPlayerNameUncolored takes player p returns string
return PlayerNames[GetPlayerId(p)]
endfunction
private function ResetColor takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer ID = GetTimerData(t)
set IsChangingColor = true
call SetPlayerName(Player(ID),PlayerNames[ID])
call ReleaseTimer(t)
set IsChangingColor = false
endfunction
private function TempColorName takes player p returns nothing
local integer ID
local timer t
if Init == false then
set IsChangingColor = true
set ID = GetPlayerId(p)
set t = NewTimer()
call SetPlayerName(p,ColorString[ID]+PlayerNames[ID]+"|r")
call SetTimerData(t,ID)
call TimerStart(t,0.00,false,function ResetColor)
set IsChangingColor = false
endif
endfunction
private function UpdateColor takes player p, playercolor c returns nothing
set ColorString[GetPlayerId(p)] = ColorString[GetHandleId(c)]
endfunction
private function UpdateName takes player p, string name returns nothing
if IsChangingColor == false then
set PlayerNames[GetPlayerId(p)] = name
endif
endfunction
hook GetPlayerName TempColorName
hook SetPlayerColor UpdateColor
hook SetPlayerName UpdateName
private function init takes nothing returns nothing
set ColorString[0] = "|cffff0000" //red
set ColorString[1] = "|cff0000ff" //blue
set ColorString[2] = "|cff00f5ff" //Teal
set ColorString[3] = "|cff551A8B" //Purple
set ColorString[4] = "|cffffff00" //Yellow
set ColorString[5] = "|cffEE9A00" //Orange
set ColorString[6] = "|cff00CD00" //Green
set ColorString[7] = "|cffFF69B4" //Pink
set ColorString[8] = "|cffC0C0C0" //Gray
set ColorString[9] = "|cffB0E2FF" //Light Blue
set ColorString[10] = "|cff006400" //Dark Green
set ColorString[11] = "|cff8B4513" //Brown
set Init = true
set PlayerNames[0] = GetPlayerName(Player(0))
set PlayerNames[1] = GetPlayerName(Player(1))
set PlayerNames[2] = GetPlayerName(Player(2))
set PlayerNames[3] = GetPlayerName(Player(3))
set PlayerNames[4] = GetPlayerName(Player(4))
set PlayerNames[5] = GetPlayerName(Player(5))
set PlayerNames[6] = GetPlayerName(Player(6))
set PlayerNames[7] = GetPlayerName(Player(7))
set PlayerNames[8] = GetPlayerName(Player(8))
set PlayerNames[9] = GetPlayerName(Player(9))
set PlayerNames[10] = GetPlayerName(Player(10))
set PlayerNames[11] = GetPlayerName(Player(11))
set Init = false
endfunction
endlibrary
Here an example:

Last edited: