start


SUBMITTED BY: Guest

DATE: Sept. 17, 2012, 4:56 p.m.

FORMAT: Text only

SIZE: 2.4 kB

HITS: 2984

  1. --[[
  2. Script: Start Lib v0.2
  3. Author: SurfaceS
  4. Goal : save the start values
  5. Required libs : none
  6. Exposed variables : start, file_exists
  7. USAGE :
  8. Load the libray from your script
  9. Add start.OnLoad() to your script/library OnLoad() function
  10. v0.1 initial release
  11. v0.1b added system clock (lol is based on day)
  12. v0.2 BoL Studio Version
  13. ]]
  14. if start ~= nil then return end
  15. -- need to be moved some day in a lib
  16. if file_exists == nil then
  17. function file_exists(path)
  18. local file = io.open(path, "rb")
  19. if file then file:close() end
  20. return file ~= nil
  21. end
  22. end
  23. if LIB_PATH == nil then LIB_PATH = debug.getinfo(1).source:sub(debug.getinfo(1).source:find(".*\\")):sub(2) end
  24. start = {
  25. configFile = LIB_PATH.."start.cfg",
  26. save = {},
  27. gameStarted = false,
  28. }
  29. function start.OnLoad()
  30. if start.tick ~= nil then return end
  31. -- init values
  32. start.window = {W=tonumber((WINDOW_W ~= nil and WINDOW_W or 0)),H=tonumber((WINDOW_H ~= nil and WINDOW_H or 0))}
  33. start.tick = tonumber(GetTickCount())
  34. start.osTime = os.time(t)
  35. start.teamEnnemy = tonumber((TEAM_ENEMY ~= nil and TEAM_ENEMY or 0))
  36. if file_exists(start.configFile) then dofile(start.configFile) end
  37. for i = 1, objManager.maxObjects, 1 do
  38. local object = objManager:getObject(i)
  39. if object ~= nil and object.type == "obj_AI_Minion" and string.find(object.name,"Minion_T") then
  40. start.gameStarted = true
  41. break
  42. end
  43. end
  44. if start.save.osTime ~= nil and (start.save.osTime > (start.osTime - 120) or start.gameStarted) then
  45. start.window.W = start.save.window.W
  46. start.window.H = start.save.window.H
  47. start.tick = start.save.tick
  48. start.teamEnnemy = start.save.teamEnnemy
  49. else
  50. start.file = io.open(start.configFile, "w")
  51. if start.file then
  52. start.file:write("start.save.osTime = "..start.osTime.."\n")
  53. start.file:write("start.save.window = { W="..start.window.W..", H="..start.window.H.." }\n")
  54. start.file:write("start.save.tick = "..start.tick.."\n")
  55. start.file:write("start.save.teamEnnemy = "..start.teamEnnemy.."\n")
  56. start.file:close()
  57. end
  58. start.file = nil
  59. end
  60. start.save = nil
  61. start.gameStarted = nil
  62. start.configFile = nil
  63. end

comments powered by Disqus