Advertisement
Arthur57980

Untitled

Jul 15th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. function explode(div,str) -- credit: http://richard.warburton.it
  2. if (div=='') then return false end
  3. local pos,arr = 0,{}
  4. -- for each divider found
  5. for st,sp in function() return string.find(str,div,pos,true) end do
  6. table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
  7. pos = sp + 1 -- Jump past current divider
  8. end
  9. table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
  10. return arr
  11. if (div=='') then return false end
  12. local pos,arr = 0,{}
  13. -- for each divider found
  14. for st,sp in function() return string.find(str,div,pos,true) end do
  15. table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
  16. pos = sp + 1 -- Jump past current divider
  17. end
  18. table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
  19. return arr
  20. end
  21. function xpPointsToLevels(points)
  22. local pts = tonumber(points)
  23. if (pts < 0) then return 0 end
  24. if (pts <= 272) then return math.floor(pts/17)
  25. elseif (pts > 272 and pts <= 887) then return math.floor((1/6)*(59+math.sqrt(-5159+(24*pts))))
  26. else return math.floor((1/14)*(303+math.sqrt(-32511+(56*pts)))) end
  27. local pts = tonumber(points)
  28. if (pts < 0) then return 0 end
  29. if (pts <= 272) then return math.floor(pts/17)
  30. elseif (pts > 272 and pts <= 887) then return math.floor((1/6)*(59+math.sqrt(-5159+(24*pts))))
  31. else return math.floor((1/14)*(303+math.sqrt(-32511+(56*pts)))) end
  32. end
  33. rednet.open("back")
  34. @@ -41,22 +41,23 @@ text.setZIndex(101)
  35. while true do
  36. e,a,b,c = os.pullEvent()
  37. -- print(textutils.serialize({e,a,b,c}))
  38. if (e == "rednet_message" and string.match(b, "azenet:xp:")) then
  39. local m = explode(':', b)
  40. text.setText(xpPointsToLevels(m[3]).." niveaux")
  41. actualPercentage.setWidth(math.floor((tonumber(m[3])/1980)*(w+4)))
  42. elseif (e == "rednet_message" and b == "azenet:closexp") then
  43. text.setColor(0xff1313)
  44. elseif (e == "rednet_message" and b == "azenet:openxp") then
  45. text.setColor(0x61903b)
  46. elseif (e == "chat_command" and b == "azenet" and a == "stopXP") then
  47. rednet.broadcast("azenet:closexp")
  48. text.setColor(0xff1313)
  49. elseif (e == "chat_command" and b == "azenet" and a == "startXP") then
  50. rednet.broadcast("azenet:openxp")
  51. text.setColor(0x61903b)
  52. end
  53. e,a,b,c = os.pullEvent()
  54. if (e == "rednet_message" and string.match(b, "azenet:xp:")) then
  55. local m = explode(':', b)
  56. text.setText(xpPointsToLevels(m[3]).." niveaux")
  57. actualPercentage.setWidth(math.floor((tonumber(m[3])/1980)*(w+4)))
  58. elseif (e == "rednet_message" and b == "azenet:closexp") then
  59. text.setColor(0xff1313)
  60. elseif (e == "rednet_message" and b == "azenet:openxp") then
  61. text.setColor(0x61903b)
  62. elseif (e == "chat_command" and b == "azenet" and a == "stopXP") then
  63. rednet.broadcast("azenet:closexp")
  64. text.setColor(0xff1313)
  65. elseif (e == "chat_command" and b == "azenet" and a == "startXP") then
  66. rednet.broadcast("azenet:openxp")
  67. text.setColor(0x61903b)
  68. elseif (e == "chat_command" and b == "azenet" and (a == "open" or a == "close")) then
  69. rednet.send(58, a)
  70. end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement