Advertisement
Wildtide

RAltInfo Test

Jun 12th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. ralt_coin = {}
  2.  
  3. local playerDets = Inspect.Unit.Detail("player")
  4. local playerId = playerDets.id
  5. local character = playerDets.name
  6.  
  7. local function format_total(total)
  8.    local string = tostring(total)
  9.    local len = string.len(string)
  10.    
  11.   if len <= 2 then
  12.     -- 2 digits ie silver only
  13.     total = total .. "s"
  14.     elseif len <= 4 then
  15.       -- 4 digits ie gold
  16.       local silver = string.sub(total, (len-1), len)
  17.       local gold = string.sub(total, 1, (len-2))
  18.       total = gold .. "g " .. silver .. "s "
  19.       elseif len > 4 then
  20.         -- 6 digits
  21.       local silver = string.sub(total, (len-1), len)
  22.       local gold = string.sub(total, (len-3), (len-2))
  23.       local plat = string.sub(total, 1, (len-4))
  24.       total = plat .. "p " .. gold .. "g " .. silver .. "s "
  25.   end
  26.  
  27.    return total
  28. end
  29.  
  30.  
  31. local function get_player_coin()
  32.   return Inspect.Currency.Detail("coin").stack
  33. end
  34.  
  35. local function print_total()
  36.   local total = 0
  37.   local count = 0
  38.   for k,v in pairs(ralt_coin) do
  39.     total = total + v
  40.     count = count + 1
  41.   end
  42.  
  43.   total = format_total(total)
  44.  
  45.   print(total .. " (" .. count .. " characters)")
  46. end
  47.  
  48. local function unit_available(unitId)
  49.     if unitId ~= playerId then return end
  50.     -- set variable to coin value
  51.     ralt_coin[character] = get_player_coin()
  52. end
  53.  
  54. local function set_coin()
  55.     ralt_coin[character] = get_player_coin()
  56. end
  57.  
  58. local function print_coin()
  59.     print(get_player_coin())
  60. end
  61.  
  62. -- debug command, check value of ralt_coin
  63. table.insert(Command.Slash.Register("rcoin"), {print_coin, "rAltInfo", "get current characters coin"})
  64. table.insert(Command.Slash.Register("rtotal"), {print_total, "rAltInfo", "print total coin"})
  65.  
  66. -- insert get and set events
  67. table.insert(Event.Unit.Availability.Full, {unit_available, "rAltInfo", "set characters coin"})
  68. table.insert(Event.Currency, {set_coin, "rAltInfo", "set characters coin"})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement