Tables and priorities for a PK mud

Posted by ReallyCurious on Thu 17 May 2007 07:50 PM — 3 posts, 14,347 views.

USA #0
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!!
Amended on Thu 17 May 2007 08:48 PM by ReallyCurious
Australia Forum Administrator #1
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".
USA #2
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