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: 195

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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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