HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Chat String

12-28-2007, 08:01 AM#1
zetanno
i tried many times to make a trigger with the Event - Player x enter "-Frost xxxx" (xxxx = a number). How can i use the entered number (xxxx) in a trigger ? As example when u play dota in single player you can type "-gold xxxx " and u get that number of gold .
12-28-2007, 11:38 AM#2
Silvenon
You use substrings. Then in the TriggerRegisterPlayerChatEvent you would have to set the last parameter to false, because it shouldn't be an exact match.

The word gold has 4 letters, right? Then the number will start at 6th symbol (since space also counts). So if a player, for example, types gold 100, the trigger for that would be:

Collapse JASS:
function Substrings takes nothing returns nothing
    local string goldamount = SubString(GetEventPlayerChatString(), 5, 8)
    // I've put 5 instead of 6 here because JASS always subtracts 1,
    // but I don't know why isn't the end integer subtracted also.....
    local integer int = S2I(goldamount)
endfunction

//===========================================================================
function InitTrig_Substrings takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, Player(0), "gold", false)
    call TriggerAddAction(t, function Substrings)
endfunction

In GUI it will probably be something like:

Trigger:
Substrings
Collapse Events
Player - Player 1 (Red) types a chat message containing gold as A substring
Conditions
Collapse Actions
Set GoldAmount = (Substring((Entered chat string), 6, 8))
Set Int = Integer(GoldAmount)

I'm not doing anything with that value, I'm just storing it in a variable.

Note that this is just an example where that number has 3 digits, it could as well have less or more, then you would have to make ifs to check how many digits there are etc.
12-28-2007, 03:31 PM#3
zetanno
very good example :D and it works too thx very much