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

Gammon Software Solutions 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?
(New message)
Subject: Making a script to count mobs killed
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Dfmalh   (3 posts)  [Biography] bio
Date Wed 02 Sep 2009 08:17 PM (UTC)  quote  ]
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 Bast   (76 posts)  [Biography] bio
Date Wed 02 Sep 2009 06:04 PM (UTC)  quote  ]
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 Wed 02 Sep 2009 01:17 PM (UTC)  quote  ]
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 Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 01 Sep 2009 11:01 PM (UTC)  quote  ]
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 Tue 01 Sep 2009 09:55 PM (UTC)  quote  ]
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 WizardsEye   (24 posts)  [Biography] bio
Date Wed 25 Feb 2009 06:46 AM (UTC)  quote  ]
Message
GAH! I had forgotten I had changed that. sigh
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 25 Feb 2009 06:17 AM (UTC)  quote  ]
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 Wed 25 Feb 2009 06:11 AM (UTC)  quote  ]
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  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 25 Feb 2009 12:27 AM (UTC)  quote  ]
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 Tue 24 Feb 2009 07:58 PM (UTC)  quote  ]
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  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 24 Feb 2009 06:32 PM (UTC)  quote  ]
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 Tue 24 Feb 2009 09:16 AM (UTC)  quote  ]
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  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 23 Feb 2009 06:56 PM (UTC)  quote  ]
Message
Another simple alias should do that:


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

killed_mobs =  {}  -- clear mobs table

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



- Nick Gammon

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

Posted by WizardsEye   (24 posts)  [Biography] bio
Date Mon 23 Feb 2009 04:40 PM (UTC)  quote  ]
Message
Hmm, I'm a bit different I guess, Keeping track is good, but wouldn't it be nice to be able to use a command to wipe out the data and start over fast? I like to keep a weeks count myself. That way, I can track my progress for a week and know on friday if I need to catch back up.
[Go to top] top

Posted by Chyort   USA  (35 posts)  [Biography] bio
Date Sat 07 Feb 2009 11:45 PM (UTC)  quote  ]
Message
have to double up the %'s but i saw that earlier when i was browsing the forums. thanks again.

now to play around with it a bit. :)
[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.


12,883 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]