Snippet Entered Chat String

Exide

I am amazingly focused right now!
Reaction score
448
Hi.

I saw a few threads asking about Entered Chat Strings.
So I figured I'd write a short trigger as an example for people to use.
So here it is. :p

What you need:
*Warcraft 3!

Global variables used:
*Hero[(array)]

Code:
Hero Color:
JASS:

function Trig_Hero_Color_Actions takes nothing returns nothing
    local integer textlength  = StringLength(GetEventPlayerChatString())
    local string text = GetEventPlayerChatString()
    local force playzor = CreateForce()             // not necessary.
    local unit colorunit                           // this is the unit that will change color.
    local integer redvalue                           // redvalue, bluevalue and greenvalue are used for setting colors.
    local integer bluevalue
    local integer greenvalue
    
    if ( SubString(text, 1, textlength) == "normal" ) then             // these functions sets the colors.
        set redvalue = 255
        set bluevalue = 255
        set greenvalue = 255
    endif
    
    if ( SubString(text, 1, textlength) == "random" ) then
        set redvalue = GetRandomInt(1, 255)
        set bluevalue = GetRandomInt(1, 255)
        set greenvalue = GetRandomInt(1, 255)
    endif
    
    if ( SubString(text, 1, textlength) == "black" ) then
        set redvalue = 0
        set bluevalue = 0
        set greenvalue = 0
    endif
    
    if ( SubString(text, 1, textlength) == "blue" ) then
        set redvalue = 0
        set bluevalue = 0
        set greenvalue = 255
    endif
    
    if ( SubString(text, 1, textlength) == "red" ) then
        set redvalue = 255
        set bluevalue = 0
        set greenvalue = 0
    endif
    
    if ( SubString(text, 1, textlength) == "green" ) then
        set redvalue = 0
        set bluevalue = 255
        set greenvalue = 0
    endif
    
    if ( SubString(text, 1, textlength) == "yellow" ) then
        set redvalue = 100
        set bluevalue = 100
        set greenvalue = 0
    endif
    
    if ( SubString(text, 1, textlength) == "teal" ) then
        set redvalue = 0
        set bluevalue = 255
        set greenvalue = 255
    endif

    if ( SubString(text, 1, textlength) == "purple" ) then
        set redvalue = 255
        set bluevalue = 0
        set greenvalue = 255
    endif
    
    
    if ( GetTriggerPlayer() == Player(0) ) then        // this checks which player it was that wrote the message.
        set colorunit = udg_Hero[1]
    elseif ( GetTriggerPlayer() == Player(1) ) then
        set colorunit = udg_Hero[2]
    elseif ( GetTriggerPlayer() == Player(2) ) then
        set colorunit = udg_Hero[3]
    endif
    
    call SetUnitVertexColor( colorunit, redvalue, bluevalue, greenvalue, 255 )    // this actually changes color of the unit, acording to 'redvalue', 'bluevalue', and 'greenvalue'.
    
    call ForceAddPlayer(playzor, GetTriggerPlayer())                                              // not necessary.
    call QuestMessageBJ(playzor, bj_QUESTMESSAGE_UPDATED, SubString(( "|cffffcc00Current color: " + text), 2, textlength) )  // not necessary.
    
    set colorunit = null
    set playzor = null          // only necessary if using the 'Current color:' -function.
    set text = null
endfunction

//===========================================================================
function InitTrig_Hero_Color takes nothing returns nothing
    local trigger gg_trg_Hero_Color = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Hero_Color, Player(0), ( "-" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Hero_Color, Player(1), ( "-" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Hero_Color, Player(2), ( "-" + "" ), false )
    call TriggerAddAction( gg_trg_Hero_Color, function Trig_Hero_Color_Actions )
endfunction


Player Name:
JASS:

function Trig_Player_Name_Actions takes nothing returns nothing
    local integer textlength  = StringLength(GetEventPlayerChatString())
    local string text = GetEventPlayerChatString()
    local player whozor = GetTriggerPlayer()
    
    
    call SetPlayerName( whozor, SubString(text, 6, textlength) )
    
    set whozor = null
    set text = null
endfunction

//===========================================================================
function InitTrig_Player_Name takes nothing returns nothing
    local trigger gg_trg_Player_Name = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Player_Name, Player(0), ( "-" + "name" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Player_Name, Player(1), ( "-" + "name" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Player_Name, Player(2), ( "-" + "name" + "" ), false )
    call TriggerAddAction( gg_trg_Player_Name, function Trig_Player_Name_Actions )
endfunction


Kick Player:
JASS:

function Trig_Kick_Player_Actions takes nothing returns nothing
    local integer textlength  = StringLength(GetEventPlayerChatString())
    local string text = GetEventPlayerChatString()
    local player whozor
    
    
    if ( SubString(text, 6, textlength) == "red" ) then
        set whozor = Player(0)
    endif
    
    if ( SubString(text, 6, textlength) == "blue" ) then
        set whozor = Player(1)
    endif
    
    if ( SubString(text, 6, textlength) == "teal" ) then
        set whozor = Player(2)
    endif
    

    call CustomDefeatBJ( whozor, "You were kicked!" )
    call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, ( "|c00FF0000" + ( GetPlayerName(whozor)) + " was kicked!" ) )

    set whozor = null    
endfunction

//===========================================================================
function InitTrig_Kick_Player takes nothing returns nothing
    local trigger gg_trg_Kick_Player = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_Player, Player(0), ( "-" + "kick" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_Player, Player(1), ( "-" + "kick" + "" ), false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_Player, Player(2), ( "-" + "kick" + "" ), false )
    call TriggerAddAction( gg_trg_Kick_Player, function Trig_Kick_Player_Actions )
endfunction



Example Map, v1.2 Attached.
Last Update: 12/7.
 

Attachments

  • [Snippet] Entered Chat String v1.2.w3x
    27.8 KB · Views: 197

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
So, it sets your name color? I would suggest developing this into a system and allowing name changes.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
A slightly more efficient version would get the substring just once, and also use "player number".
And, what is a Hero array? Some units? Some unit types? Something else?

More interesting though is, why the heck is the actual point of interest of that post hidden in a spoiler?
 

Exide

I am amazingly focused right now!
Reaction score
448
>So, it sets your name color? I would suggest developing this into a system and allowing name changes.
-Nah, it sets the unit vertex color of 'Hero[*]'.
A quick remake of the trigger can make it change name and color and similar of the players, as well, though.
:p


>And, what is a Hero array? Some units? Some unit types? Something else?
-In case there are several players owning a hero each.

>More interesting though is, why the heck is the actual point of interest of that post hidden in a spoiler?
-Removed the spoiler tags. ^^
 

Prometheus

Everything is mutable; nothing is sacred
Reaction score
590
Didn't look too deeply at the code. :p
Cool though, +rep. :D
 

darkRae

Ueki Fan (Ueki is watching you)
Reaction score
173
Just a suggestion, instead of 'first' 'second' 'third' you might wanna use 'redvalue' 'greenvalue' 'bluevalue' (or similar) instead.
 

Exide

I am amazingly focused right now!
Reaction score
448
Just a suggestion, instead of 'first' 'second' 'third' you might wanna use 'redvalue' 'greenvalue' 'bluevalue' (or similar) instead.

Not like it matters.
But yes, you are right. Those are obviously betters names. :thup:
I'll try to remember to change, when/if I update it. ^^
 

Exide

I am amazingly focused right now!
Reaction score
448
*Bump!*
Updated.
Version 1.1

-Changed the Color-trigger slightly.
-Added a new trigger, called Player Name. Which sets the name of the player. (Obviously.) :thup:


EDIT #2:
Version 1.2
A second change, all in the same day!

-Changed the Player Name-trigger slightly.
-Added a new trigger, called Kick Player. Which kicks a player. (Obviously.) :D
 

Exide

I am amazingly focused right now!
Reaction score
448
>It can only kick player 1, 2 and 3...
It's meant to be that way.
If you want to add more players, you'll do it yourself.
-No need to have 12 identical if/then/else -functions in an example map. :D
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
JASS:
library Kick initializer Init

globals
    private string array colors
endglobals

private function Actions takes nothing returns nothing
    local string text = GetEventPlayerChatString()
    local integer textlength  = StringLength(text)
    local string who = SubString(text, 6, textlength)
    local player whozor
    local integer i = 0
    
    loop
    exitwhen i > 11
        if ( who == colors<i> ) then
            set whozor = Player(i)
            exitwhen true
        endif

        set i = i + 1
    endloop

    call CustomDefeatBJ( whozor, &quot;You were kicked!&quot; )
    call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, ( &quot;|c00FF0000&quot; + ( GetPlayerName(whozor)) + &quot; was kicked!&quot; ) )

    set whozor = null    
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger T = CreateTrigger()
    local integer i = 0

    loop
    exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent(T, Player(i), &quot;-kick&quot;, false)
        set i = i + 1
    endloop
    call TriggerAddAction(T, function Actions)

    set colors[0]=&quot;red&quot;
    set colors[1]=&quot;blue&quot;
    set colors[2]=&quot;etc.&quot;
    set colors[4]=&quot;etc.&quot;
    set colors[5]=&quot;etc.&quot;
    set colors[6]=&quot;etc.&quot;
    set colors[7]=&quot;etc.&quot;
    set colors[8]=&quot;etc.&quot;
    set colors[9]=&quot;etc.&quot;
    set colors[10]=&quot;etc.&quot;
    set colors[11]=&quot;etc.&quot;
endfunction
endlibrary
</i>


Works for everyone and didn't need you to write 12 if/then/else...
P.S.: Fill in the colors at the bottom
P.P.S.: Don't need to null players I.I.R.C.
P.P.P.S.: Requires NewGen
 

Exide

I am amazingly focused right now!
Reaction score
448
Works for everyone and didn't need you to write 12 if/then/else...
P.S.: Fill in the colors at the bottom
P.P.S.: Don't need to null players I.I.R.C.
P.P.P.S.: Requires NewGen

Depends on how many players there are in the map, I guess.
With only a few players I think my version is simpler.

I.I.R.C.?

I was told handles are to be nulled, I dunno. :p

I don't use NewGen. With my version it's not needed, so anyone can use it. ^^

EDIT: I appriciated the effort, though. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top