HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Player leaving script error

04-26-2007, 07:30 AM#1
Kam
This is a script I'm trying to use to let the game detect the color of the player name and display it in the "player has left the game" message. I get a valid argument error.

Collapse JASS:
function Trig_Player_Leaves_Actions takes nothing returns nothing

call DisplayTextToForce([GetPlayerId(GetTriggerPlayer())]+GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")

endfunction

//===========================================================================
function InitTrig_Player_Leaves takes nothing returns nothing
    set gg_trg_Player_Leaves = CreateTrigger(  )
 call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(0) )
    call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(1) )
    call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(10) )
    call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(5) )
    call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(6) )
    call TriggerRegisterPlayerEventLeave( gg_trg_Player_Leaves, Player(9) )
    call TriggerAddAction( gg_trg_Player_Leaves, function Trig_Player_Leaves_Actions )
endfunction

04-26-2007, 07:51 AM#2
Fireeye
You don't give enough arguments to pass that call,
1. You don't use any force to which the text should be displayed
2. You use GetPlayerId(GetTriggerPlayer()), which returns an integer and can't be used without an I2S in a display and also not as argument to whom the text should be displayed, because it's ont a force.
Here's what you propably want:
Collapse JASS:
call DisplayTextToForce(GetPlayersAll(),GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")
or use this one instead of GetPlayersAll() if you only want to show it to allies.
Collapse JASS:
GetPlayersAllies(GetTriggerPlayer())
04-26-2007, 01:36 PM#3
Kam
The works but it only colorizes the "has left the game" part of the text. Is there no way to assign each player a text color so it appears like:

Fireeye has left the game
04-26-2007, 03:54 PM#4
TheSecretArts
add this to your custom script
Collapse JASS:
function GetPlayerColorCode takes player whichPlayer returns string
    if ( whichPlayer == Player(0) ) then
        return "|c00FF0000"
    endif
    if ( whichPlayer == Player(1) ) then
        return "|c000000FF"
    endif
    if ( whichPlayer == Player(2) ) then
        return "|c0040E0D0"
    endif
    if ( whichPlayer == Player(3) ) then
        return "|c00A020F0"
    endif
    if ( whichPlayer == Player(4) ) then
        return "|c00FFFF00"
    endif
    if ( whichPlayer == Player(5) ) then
        return "|c00FFA500"
    endif
    if ( whichPlayer == Player(6) ) then
        return "|c0000FF00"
    endif
    if ( whichPlayer == Player(7) ) then
        return "|c00FFC0CB"
    endif
    if ( whichPlayer == Player(8) ) then
        return "|c00BEBEBE"
    endif
    if ( whichPlayer == Player(9) ) then
        return "|c00ADD8E6"
    endif
    if ( whichPlayer == Player(10) ) then
        return "|c00006400"
    endif
    if ( whichPlayer == Player(11) ) then
        return "|c00A52A2A"
    endif
    return null
endfunction
And change so that this:
Collapse JASS:
call DisplayTextToForce(GetPlayersAll(),GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")
should be this:
Collapse JASS:
call DisplayTextToForce(GetPlayersAll,GetPlayerColorCode(GetTriggerPlayer())+GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")
04-26-2007, 07:35 PM#5
Fireeye
would also be possible with a global arrays, would look like this.
What you need:
a global string array called PlayerColor

Collapse JASS:
globals
string array udg_PlayerColor
endglobals

function MapInit takes nothing returns nothing
    set udg_PlayerColor[0] = "|c00FF0000"
    set udg_PlayerColor[1] = "|c000000FF"
    set udg_PlayerColor[2] = "|c0040E0D0"
    set udg_PlayerColor[3] = "|c00A020F0"
    set udg_PlayerColor[4] = "|c00FFFF00"
    set udg_PlayerColor[5] = "|c00FFA500"
    set udg_PlayerColor[6] = "|c0000FF00"
    set udg_PlayerColor[7] = "|c00FFC0CB"
    set udg_PlayerColor[8] = "|c00BEBEBE"
    set udg_PlayerColor[9] = "|c00ADD8E6"
    set udg_PlayerColor[10] = "|c00006400"
    set udg_PlayerColor[11] = "|c00A52A2A"
endfunction
and change this
Collapse JASS:
call DisplayTextToForce(GetPlayersAll(),GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")
to the following, you don't need to do it this way, it's just an alternative.
Collapse JASS:
call DisplayTextToForce(GetPlayersAll(),udg_PlayerColor[GetPlayerId(GetTriggerPlayer())]+GetPlayerName(GetTriggerPlayer())+"|r"+"|c00ff0303 has left the game.|r")
04-26-2007, 07:39 PM#6
TheSecretArts
that works too!
04-26-2007, 07:44 PM#7
Kam
Thanks to both of you. +rep
04-27-2007, 03:23 AM#8
moyack
I did this script for my project, probably it can be useful too. The other codes work fine, but this one returns the right color, even if the player has changed its color.

Collapse JASS:
function SetPlayerColorText takes player p, string s returns string
    //Set the color in the text
    local playercolor pc = GetPlayerColor(p)
    local string color
    if pc == ConvertPlayerColor(0) then
        set color = "|CFFFF0000"
    elseif pc == ConvertPlayerColor(1) then
        set color = "|CFF0000FF"
    elseif pc == ConvertPlayerColor(2) then
        set color = "|CFF18E7BD"
    elseif pc == ConvertPlayerColor(3) then
        set color = "|CFF520084"
    elseif pc == ConvertPlayerColor(4) then
        set color = "|CFFFFFF00"
    elseif pc == ConvertPlayerColor(5) then
        set color = "|CFFFF8A08"
    elseif pc == ConvertPlayerColor(6) then
        set color = "|CFF18BE00"
    elseif pc == ConvertPlayerColor(7) then
        set color = "|CFFE759AD"
    elseif pc == ConvertPlayerColor(8) then
        set color = "|CFF949694"
    elseif pc == ConvertPlayerColor(9) then
        set color = "|CFF7BBEF7"
    elseif pc == ConvertPlayerColor(10) then
        set color = "|CFF086142"
    elseif pc == ConvertPlayerColor(11) then
        set color = "|CFF4A2800"
    else
        set color = "|CFFFFFFFF"
    endif
    set pc = null
    return color + s
endfunction