"Who here"-list

Posted by tobiassjosten on Fri 15 Jul 2005 04:45 PM — 3 posts, 18,673 views.

Sweden #0
When sending the command "who here" on the MUD I'm playing, I get a list of players in the room. It looks something like: "Player1, Player2, Player3" or just "Player1". What I want to do is replace this with: "(1) Player1 (2) Player2 (3) Player3", for example. But my trigger doesn't seem to be sending all the parameters it should, or atleast that's what I believe is the problem.

I have:
<trigger name="whohere" enabled="n" keep_evaluating="y" match="^(\w+)(?:\, (\w+))*" regexp="y" omit_from_output="y" omit_from_log="y" send_to="12" script="whohere"></trigger>


And the whohere() function:
function whohere(name, line, wildcards)
    EnableTrigger("whohere", false)
    for k in wildcards do
        ColourTell("silver", "", "(", "lightskyblue", "", tostring(k), "silver", "", ")", "royalblue", "", " " .. tostring(wildcards[k]) .. " ")
    end
    ColourNote("", "", "")
end


When I checked it with "Tyfor, Jherok, Nicanee", all I got was:
1 = Tyfor
2 = Jherok
0 = Tyfor, Jherok, Nicanee


Anyone have any idea why it's behaving like this? Doesn't make much sense to me.
#1
I have learned that you can't create an open-ended set of wildcards just by putting + or * after a pattern. You will have to match the pattern as a single wildcard and then split it yourself, I think.
Sweden #2
I thought it had something to do with the "greedy-mode", but tests showed me it didn't matter.

Any idea on how I could split the line up into an table with each name? Or how should I do this? Looping a table with the names comes first to mind to me.

Edit: Nevermind, I got it to work.
function whohere(name, line)
    EnableTrigger("whohere", false)
    local num = 0
    for w in string.gfind(line, "%w+") do
        num = num + 1
        ColourTell("silver", "", "(", "goldenrod", "", tostring(num), "silver", "", ") " .. w .. " ")
        tgt[num] = w
    end
    if num > 0 then
        ColourNote("", "", "")
    end
end