[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Tables and priorities for a PK mud
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Tables and priorities for a PK mud

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by ReallyCurious   USA  (50 posts)  [Biography] 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!!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by ReallyCurious   USA  (50 posts)  [Biography] 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
[Go to top] 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.


2,746 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]