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
➜ Tables and priorities for a PK mud
|
Tables and priorities for a PK mud
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| ReallyCurious
USA (50 posts) Bio
|
| Date
| Thu 17 May 2007 07:50 PM (UTC) Amended on Thu 17 May 2007 08:48 PM (UTC) by ReallyCurious
|
| Message
| In the mud I play(which is a pk mud) acting first and acting accordingly can sometimes decide the outcome of who wins and who loses, as a big battle only lasts 40-90 seconds. so!
Example:
Bob walks in from the west
Steve walks in from the west
Cleric walks in from the west
Julian walks in from the west
24321H 2123V...
--
Now, what I want to do is examine the names here and do an action on a name with a predefined priority to handle which name gets an action. In other words, I'd have all these names in a pk_list table so that if:
Bob walks in from the west -- kill bob
Bob walks in from the west
Cleric walks in from the west -- kill cleric
--
So, pk_list = {"Bob", "Cleric", "Steve", "Julian", "Susan", "Tiffany"}
--
Enable a trigger to match: (\w+) walks in from the west$
pk_check = {} -- create empty table or erase values if table exists already
for i,v in ipairs(pk_list) do
if v == "%1" then
EnableTrigger("pk_check_start", true)
EnableTrigger("pk_check_stop", true)
EnableTrigger("This_Trigger", false) -- so it stops matching (\w+) walks in from the west$
table.insert(pk_check, %1) -- to put the name that started the trigger into the table.
end end
--
pk_check_start trigger would match: *
table.insert(pk_check, "%0") -- adds to pk_check table everything coming from the mud.
pk_check_stop trigger would match: ^(\d+)H|^$
EnableTrigger("pk_check_start", false)
EnableTrigger("pk_check_stop", false)
for i,v in ipairs(pk_check) do
print(i,v) end
--
So on print(i,v) in table pk_check I'd have:
1 Bob
2 Steve walks in from the west
3 Cleric walks in from the west
4 Julian walks in from the west
--
I've got all the names I wanted to capture into the table, but at this point I'm not sure what to do to have certain names predefined to take the action first over other names. And also I would have to extract the names I want from the strings, so I'd probably create another table from that and get a table full of just names(if i even need to do that).
I'd appreciate any thoughts/suggestions.
Thanks!! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 17 May 2007 09:36 PM (UTC) |
| Message
| My first reaction is that you will be in trouble if Bob walks in from the east, but I will let that pass. ;)
Quote:
table.insert(pk_check, %1) -- to put the name that started the trigger into the table.
First off, that should read:
table.insert(pk_check, "%1")
To work out which to kill it might be easier to save it as the key, and not the value. In other words:
pk_check.%1 = true
Effectively this would do this (for Bob):
pk_check.Bob = true
For subsequent people, rather that storing the whole line, why not still match on:
(\w+) walks in from the \w+$
That way you just get their name, and not the "walks in" bit.
Then for all the subsequent people, you can also do this:
pk_check.%1 = true
After doing this, in your original example, we can now see who has walked in:
require "tprint"
tprint (pk_check)
Output
"Steve"=true
"Julian"=true
"Cleric"=true
"Bob"=true
Now we need to know who to attack, right?
Let's make the pk_list be the people we want to kill, in the correct order (priority order).
Now we can go through that list sequentially, and do a keyed lookup of who is actually in the room, attacking the first one we find:
pk_list = {"Cleric", "Bob", "Steve", "Julian", "Susan", "Tiffany"}
for i, v in ipairs (pk_list) do
if pk_check [v] then
Send ("kill " .. v)
break
end -- if
end -- for
In this case, it sends "kill Cleric".
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| ReallyCurious
USA (50 posts) Bio
|
| Date
| Reply #2 on Fri 18 May 2007 04:34 PM (UTC) |
| Message
| K that works well. I was thinking about what to do with multiple tables representing different factions(in the mud)
pk_list_clanA = {"Healer", "Susan", "Claire"}
pk_list_clanB = {"ReallyCurious", "Nick Gammon", "Shaun Biggs"}
Sometimes I will want to only catch clanA, sometimes clanB, or both. But I can just make pk_list_clanAB and put in values where they're appropriate.
pk_list_clanAB = {"Healer", "ReallyCurious", "Nick Gammon", "Shaun Biggs", "Susan", "Claire"}
thanks | | 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.
13,617 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top