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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Need some ideas/help on how to make a table of values

Need some ideas/help on how to make a table of values

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


Posted by Bevern   (9 posts)  [Biography] bio
Date Fri 01 Aug 2008 10:44 PM (UTC)
Message
I'm trying to fix this plugin which is supposed to calculate all experience earned over the last hour but instead just shows all experience gained since it was reset. I'm thinking that the only way to do this would be to create a table like this:

"13:04:55","some mob name","experience","gold"
"13:05:55","some mob name","experience","gold"
"13:06:55","some mob name","experience","gold"
"14:15:55","some mob name","experience","gold"

But how would I go about doing that without creating a Mysql database and how would I retrieve only a certain range depending on the time?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Fri 01 Aug 2008 10:49 PM (UTC)
Message
In Lua this would be pretty easy, but it looks like you want to do it in VBscript so I'll describe the general concept. (I'm not familiar enough with VBS to write it off the top of my head.)

You want a list of records, each containing the time, the mob name, and the XP and gold obtained. Append new items to the list. Every time you add something, check the items at the beginning of the list to see if they were more than an hour ago; if so, expire those items (remove them from the list).

This will work fairly well if you kill things often. It will however fail to update the list when you're not killing things. In that case, you would want to have a timer around that issues a command every once in a while to update the list by purging old values.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Bevern   (9 posts)  [Biography] bio
Date Reply #2 on Sat 02 Aug 2008 12:06 AM (UTC)
Message
So would LUA be a better option and if so why? I've got a script that tracks EXP but it just keeps it in one variable instead of tracking it by hour like it's supposed to.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Sat 02 Aug 2008 03:31 AM (UTC)
Message
Lua isn't necessarily a better option in the absolute, it's just that I know how to do it and it tends to be better supported by people here in general.

I would do something like this:


-- create the list of tracked kills
tracking = {}

-- (upon killing something)
record = {}
record.xp = [how much xp I got]
record.gold = [how much gold I got]
record.name = [the mob's name]
record.time = os.time()
table.insert(tracking, record)

-- purge the table:
while next(tracking) ~= nil do
  record = tracking[1]
  if record.time < os.time() - 3600 then
    table.remove(tracking, 1)
  else
    -- if this one is recent enough, everything after it
    -- must be too
    break
  end
end


That is the basic framework, obviously some details need adjusting and you need to add things like triggers.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 02 Aug 2008 03:49 AM (UTC)
Message
I agree with what David said. Lua is the way to go, as making tables is easy. Below is a plugin I used for Aardwolf to track kills, not quite in the way you wanted, but it should give you a start. You will need to revamp it a bit to get the data, I used the "stats" plugin to find who I had just killed. You could replace that with a suitable trigger.

What the plugin below does is track the last 5 kills (which you can change by changing the variable "MAXAVERAGE = 5"). Each time you kill something, if there are 5 items or more in the table, it throws away the first one. To do what you want, instead you would throw away any which had a time associated with them of over an hour ago. I used 5 items because you tend to get into a rhythm, and then the plugin can predict how long it will take to level, based on your most recent 5 kills.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, July 11, 2008, 5:43 PM -->
<!-- MuClient version 4.33 -->

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

<muclient>
<plugin
   name="Aardwolf_Exp_gain"
   author="Nick Gammon"
   id="e34c9929c87f4f77c24d6687"
   language="Lua"
   purpose="Estimates time to level based on recent kills"
   date_written="2008-07-11 17:41:42"
   requires="4.33"
   version="1.1"
   >
<description trim="y">
<![CDATA[
xp           - show names and counts of mobs we killed
xp reset     - resets "recent kills" table, use when starting a new killing session
xp reset all - same as "xp reset" plus it removes the list of mobs killed

]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^You receive (\d+) experience points?\.$"
   regexp="y"
   script="mobdied"
   sequence="100"
  >
   </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   script="xp_alias"
   match="^xp( reset| reset all)?$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
local MAXAVERAGE = 5 -- max to keep for averages

local xp_table = {}
local mobs = {}  -- table of mobs killed

require "commas"



local function plural (count)
  if count ~= 1 then
    return "s"
  else
    return ""
  end -- if
  
end -- function plural

function show_calcs (xptogo)

  stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
  
  if not stats then return end
      
  level = tonumber (stats.level)
  xptogo = xptogo or tonumber (stats.to_level)

  local tablesize = #xp_table
   
   -- work out average
   local total = 0
   for _, v in ipairs (xp_table) do
     total = total + v.xpgain
   end -- for loop
   
   local av_xp = total / tablesize
   
   if tablesize <= 1 then
     return
   end

   local elapsed = xp_table [#xp_table].time - xp_table [1].time  -- time it took to do those kills
    
   kills = math.ceil (xptogo / av_xp) 
   local time_to_go = (xptogo / av_xp) * elapsed / (tablesize  - 1)
   local xp_per_hour = av_xp / elapsed * 60 * 60 * (tablesize  - 1)
   
   if xp_per_hour < 1 then
     return
   end -- if
   
   ColourNote ("magenta", "",
          string.format ("To level: %s XP (%s) %i avg kill%s. (%s XP/hour)",
                        commas (xptogo),
                        convert_time (time_to_go),
                        kills,
                        plural (kills),
                        commas (string.format ("%i", xp_per_hour))
                          ))  -- blue
          
end -- show_calcs

function mobdied (name, line, wildcards)

  stats = GetPluginVariableList("8a710e0783b431c06d61a54c")
  
  if not stats then return end
    
  level = tonumber (stats.level)
  xpgain = tonumber (wildcards [1])
  xptogo = tonumber (stats.to_level) - xpgain
  mob = stats.last_enemy
  
  if not mob then return end
  
  -- remember mob count
  
  mobs [mob] = (mobs [mob] or 0) + 1
  
  local kills = math.ceil (xptogo / xpgain)  -- how many such kills that is
  
  if xptogo <= 0 then
   return
  end -- if levelling right now!
  
  if last_kill_time then
   secs_since_last_kill = os.time () - last_kill_time   
  end -- not first kill
  
  last_kill_time = os.time ()-- remember for next time
  
                     
  -- remember details
  local thiskill = {
    mob = mob,
    xpgain = xpgain,
    time = last_kill_time,
  } -- end of thiskill table               
  
  if #xp_table >= MAXAVERAGE then
   table.remove (xp_table, 1) -- remove oldest one
  end -- of table full
  
  table.insert (xp_table, thiskill) -- new item
  show_calcs (xptogo)
 
end -- trigger: mobdied function
                 

function xp_alias (name, line, wildcards)

   msg = trim ( string.lower (wildcards [1] or ""))
   
   if msg == "reset all" then
     mobs = {}
     Note ("XP gain mob history reset.")
   end -- if reset all
   
   if msg == "reset" or msg == "reset all" then
     xp_table = {}
     last_xp_amount = nil
     Note ("XP gain calculations reset.")
     return
   end -- if reset

   Tell ("Type ")
   Hyperlink  ("xp reset", "", "", "yellow", "")
   Tell (" to reset calculations, ")
   Hyperlink  ("xp reset all", "", "", "yellow", "")
   Note (" to reset everything.")

   -- if any mobs killed, show name of mob and number killed, for each different type
   if next (mobs) then
     local t = {}
     local total = 0
     
     -- make list of mob names and number we killed
     for k, v in pairs (mobs) do
       table.insert (t, string.format ("(%s) x%i", k, v))
       total = total + v
     end -- for
     
     -- alphabetic order
     table.sort (t)
     
     ColourNote ("Teal", "", "Killed: " .. table.concat (t, ", "))
     Note (string.format ("%i mob%s killed, %i different mob type%s", 
            total, plural (total), 
            #t, plural (#t)))
   else
     Note ("No mobs killed.")
   end -- something in mobs table

    show_calcs ()
 end -- xp_alias



]]>
</script>


</muclient>



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


14,340 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 HostDash]