Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Wildcards and tables
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Garrion
(21 posts) Bio
|
| Date
| Tue 08 Dec 2009 04:11 AM (UTC) |
| Message
| Hi all,
I am wanting to match a players name and see if that player is in my 'players' table. I can do this so far with a simple if statement:
Char_Name = string.lower(wildcards[1])
if players [Char_Name] then
So if 'Garrion' tells me something it will check the name 'garrion' is valid in the players table (eg. players.garrion).
But I am finding that there are way to many variables to try to match with my trigger so it only works some of the time.
The trigger and example text that sends to this function is below:
<trigger
enabled="y"
match="^(.*) (tells|asks|chats|exclaims )(.*)(to you|you|and you)(\:)(.*)"
name="tell_hit"
script="pshow"
regexp="y"
send_to="12"
sequence="100"
>
</trigger>
The ghost of Garrion D'Chaser tells you: blah blah
Garrion D'Chaser tells you: blah blah
Garrion tells you: blah blah -- matches table
These are just a few of the possible matches.
So with the above example my wildcard could be:
the ghost of garrion d'chaser
garrion d'chaser
garrion
My thinking was to somehow do a string.find on my wildcard to see if any of the words are in my table. Is this even possible and if so could someone point me in the right dirrection please?
Thanks,
Garrion. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Tue 08 Dec 2009 04:22 AM (UTC) |
| Message
| A brute-force approach would be to, for every player, try to match.
eg.
local match = nil
local Char_Name = string.lower(wildcards[1])
for k, v in pairs (players) do
if string.match (Char_Name, k:lower ()) then
match = k -- remember match
end -- if
end -- for
if match then -- we found it
Note ("Warning, player " .. match .. " here.")
end -- if
This code assumes that the player names is the key of the players table. Effectively it will go through every possible player, trying to match on whatever it found in wildcard 1.
A potential problem here is if some names are part of longer names. Eg. this code would match on GarrionSan without noticing that Garrion is only part of the word.
There are workarounds for this (eg. break up the wildcard into individual words first), but this should get you started. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Garrion
(21 posts) Bio
|
| Date
| Reply #2 on Tue 08 Dec 2009 04:57 AM (UTC) |
| Message
| Thanks Nick!
Exacly what I was after :) | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
17,559 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top