[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]  Getting Started
. . -> [Subject]  Making a script to count mobs killed
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Making a script to count mobs killed

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


Pages: 1  2 3  

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #15 on Tue 24 Feb 2009 09:16 AM (UTC)
Message
Yes, that works...a bit to well. After I cleared it. It won't record any kills now. Tried restarting the client. Tried recreating it too. No luck.
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #16 on Tue 24 Feb 2009 06:32 PM (UTC)
Message
I don't see why that would happen, unless you somehow removed something important from the plugin. Is the trigger firing? It needs to, to count kills.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #17 on Tue 24 Feb 2009 07:58 PM (UTC)
Message
It doesn't appear like it is. Here's what I have.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, January 08, 2008, 3:26 -->
<!-- MuClient version 4.20 -->

<!-- Plugin "Count_Mobs_Killed" generated by Plugin Wizard -->

<muclient>
<plugin
name="Count_Mobs_Killed"
author="Nick Gammon"
id="f11e3bb0e48d526152798439"
language="Lua"
purpose="Counts how many mobs I have killed"
save_state="y"
date_written="2008-01-08 15:17:18"
requires="4.00"
version="1.0"
>
<description trim="y">
<![CDATA[
Counts how many mobs have been killed.

Type "show_killed" to see a count.
]]>
</description>

</plugin>


<!-- Triggers -->

<triggers>
<trigger
custom_colour="2"
enabled="y"
match="* is DEAD!!"
send_to="12"
sequence="100"
>
<send>killed_mobs = killed_mobs or {} -- make mobs table

mob_name = "%1" -- this mob's name (first wildcard)

-- add this mob if first time

killed_mobs [mob_name] = killed_mobs [mob_name] or { count = 0 }

-- add 1 to count of mobs
killed_mobs [mob_name].count = killed_mobs [mob_name].count + 1

-- remember when we last killed it
killed_mobs [mob_name].last_time = os.time ()

</send>
</trigger>
</triggers>

<!-- Aliases -->

<aliases>
<alias
match="show_killed"
enabled="y"
send_to="12"
sequence="100"
>
<send>if not killed_mobs or next (killed_mobs) == nil then
ColourNote ("white", "blue", "No mobs killed yet")
return
end -- if nothing

-- go through each one

count = 0
for k, v in pairs (killed_mobs) do
Note (string.format ("%%-30s x %%i (last at %%s)",
k,
v.count,
os.date ("%%H:%%M %%d %%b %%Y", v.last_time)))
count = count + v.count
end -- for loop

-- show total

Note (string.format ("%%5i mobs killed.", count))</send>
</alias>
</aliases>

<aliases>
<alias
match="reset_mob_counts"
enabled="y"
send_to="12"
sequence="100"
>
<send>

killed_mobs = {} -- clear mobs table

</send>
</alias>
</aliases>

<!-- Script -->


<script>
<![CDATA[

-- on plugin install, convert variable into Lua table
function OnPluginInstall ()
require "serialize" -- needed to serialize table to string
killed_mobs = {} -- ensure table exists, if not loaded from variable
assert (loadstring (GetVariable ("killed_mobs") or "")) ()
end -- function OnPluginInstall

-- on saving state, convert Lua table back into string variable
function OnPluginSaveState ()
SetVariable ("killed_mobs", "killed_mobs = " ..
serialize.save_simple (killed_mobs))
end -- function OnPluginSaveState
]]>
</script>


<!-- Plugin help -->

<aliases>
<alias
script="OnHelp"
match="Count_Mobs_Killed:help"
enabled="y"
>
</alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script>

</muclient>
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #18 on Wed 25 Feb 2009 12:27 AM (UTC)
Message
Can you copy and paste some of the MUD output that happens when something dies?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #19 on Wed 25 Feb 2009 06:11 AM (UTC)
Message
Sure can, It was working just fine before I did the count reset.

Snow crab claws you.
Snow crab pinches you.
You got 1245 xp.
Snow crab died horribly.
Snow crab dies.
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #20 on Wed 25 Feb 2009 06:17 AM (UTC)
Message
The trigger match is:


match="* is DEAD!!"


There is no way that will match any of what you posted.

You need to change it to:


match="* dies."



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Reply #21 on Wed 25 Feb 2009 06:46 AM (UTC)
Message
GAH! I had forgotten I had changed that. sigh
[Go to top] top

Posted by Dfmalh   (3 posts)  [Biography] bio
Date Reply #22 on Tue 01 Sep 2009 09:55 PM (UTC)
Message
Hi, I just started to give Triggers, Aliases, etc a try, so I am very much a newbie...

I followed the example and I get the trigger working as well as the "tprint" module. Here is the output for "/tprint (killed_mobs)":

"the wyvern":
"count"=1
"last_time"=function: 00D6FCD8
"the goblin":
"count"=8
"last_time"=function: 00D6FCD8

I follow the example further, but run into problems after I have configured and added the alias. I get the following output for "show_killed"

Run-time error
World: WaterdeepMUD - CharName
Immediate execution
[string "Alias: "]:13: bad argument #2 to 'date' (number expected, got function)
stack traceback:
[C]: in function 'date'
[string "Alias: "]:13: in main chunk

I do not know what is wrong, some thing with the date argument?

[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #23 on Tue 01 Sep 2009 11:01 PM (UTC)
Message
Hmmm - can you post what you did please?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


Quote:

"last_time"=function: 00D6FCD8


Offhand, this looks like are storing a function, not a function result. For example, this might do it:


last_time = os.time


That stores a function, whereas you want:


last_time = os.time ()


Note the brackets.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dfmalh   (3 posts)  [Biography] bio
Date Reply #24 on Wed 02 Sep 2009 01:17 PM (UTC)
Message
Hi Nick, thanks for the quick response.

Sorry I jumped into my problem without enough background...

I am following the "Making a script to count mobs killed" example/tutorial that can be found here:



I basically cut and past the code from the website into MC.

As I said before, I get the trigger working as well as activate the "tprint" module. Here is the code:


killed_mobs = killed_mobs or {}  -- make mobs table

mob_name = "%1"  -- this mob's name (first wildcard)

-- add this mob if first time

killed_mobs [mob_name] = killed_mobs [mob_name] or { count = 0 }

-- add 1 to count of mobs
killed_mobs [mob_name].count = killed_mobs [mob_name].count + 1

-- remember when we last killed it
killed_mobs [mob_name].last_time = os.time


And here is the output for "/tprint (killed_mobs)":

Quote:

"the wyvern":
"count"=1
"last_time"=function: 00D6FCD8
"the goblin":
"count"=8
"last_time"=function: 00D6FCD8


So everything up to here works. I follow the example further. But run into problems after I have configured and added the alias. Here is my Alias code:


if not killed_mobs or next (killed_mobs) == nil then
  ColourNote ("white", "blue", "No mobs killed yet")
  return
end -- if nothing

-- go through each one

count = 0
for k, v in pairs (killed_mobs) do
  Note (string.format ("%%-30s x %%i (last at %%s)",
        k, 
        v.count,
        os.date ("%%H:%%M %%d %%b %%Y", v.last_time)))
  count = count + v.count
end -- for loop

-- show total

Note (string.format ("%%5i mobs killed.", count))


With this code I get the following output for "show_killed":

Quote:

Run-time error
World: WaterdeepMUD - CharName
Immediate execution
[string "Alias: "]:13: bad argument #2 to 'date' (number expected, got function)
stack traceback:
[C]: in function 'date'
[string "Alias: "]:13: in main chunk


I hope I have explained my problem a little better. Hmmm, as an after thought, I use Mc through Wine on Ubuntu. My other trigers (Drink water and Show Exits, also from you website works fine).
[Go to top] top

Posted by Bast   (77 posts)  [Biography] bio
Date Reply #25 on Wed 02 Sep 2009 06:04 PM (UTC)
Message
Dfmalh said:


-- remember when we last killed it
killed_mobs [mob_name].last_time = os.time



os.time should be os.time()

That should do the trick.

Bast

Bast

Scripts: http://bastmush.googlecode.com
[Go to top] top

Posted by Dfmalh   (3 posts)  [Biography] bio
Date Reply #26 on Wed 02 Sep 2009 08:17 PM (UTC)
Message
Hi Nick and Bast,

Thanks for pointing the specific "()" problem. I completely missed it in the previous post. I also went back to check the code from where I cut it... and well... all my fault, I missed, or did not select the final two characters, ()

Thanks for your help! Now I will proceed with he rest of the tut.

:-)))
[Go to top] top

Posted by Liam   (1 post)  [Biography] bio
Date Reply #27 on Tue 26 Nov 2013 02:34 AM (UTC)
Message
You got 57 xp.
[something]
[something]
Mob Dies.

I've got the following text on output.

What I'm trying to do is incorporate the following information into the Show_killed alias.

I want to keep a running tally of the XP accumulated from each mob type and then divide it by the number of mobs killed to gain an average xp per mob.

But can't as multi-line triggers don't work as I expect.

What are my options?

[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #28 on Tue 26 Nov 2013 04:03 AM (UTC)
Message
Template:faq=37 Please read the MUSHclient FAQ - point 37.


Basically remember the number of xp (the first line). When the mob dies you can record that against the mob name.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tharius   (29 posts)  [Biography] bio
Date Reply #29 on Sun 01 Dec 2013 02:13 PM (UTC)
Message
There is one bug with this script that I had to encounter when I wrote a similar script in zmud.

The line prior to the kill line tells you who in fact made the kill. For alignment reasons groups are often disbanded just before the kill blow and so this trigger will count a false positive.

It's not critical but for some purposes I'd rather know my true list.

Is there a simple way to have this trigger fire, but then check the first word of the prior line(s) for the word "Your"... as in "Your slash horribly disfigures some-mob\nSome-mob is DEAD!!!"?

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.


36,848 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

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]