Advertisement
7n6

monster respawn npc (very old)

7n6
Dec 22nd, 2016
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.70 KB | None | 0 0
  1. --[[
  2.  
  3.                             *###########################################################################*
  4.                             #                              -Boss NPC by 7n6.-                           #
  5.                             #       If used please give credit or I will break your server Kappa.       #
  6.                             #                  (But seriously don't remove credits...)                  #
  7.                             *###########################################################################*
  8.    
  9.  
  10.    
  11.    
  12.    
  13. *******************************************************************************************************************************
  14. ###############################################################################################################################
  15. *******************************************************************************************************************************
  16.     MissionSdk.lua : ActionsProc :
  17.    
  18.         elseif actions[i].func == BossRecord.Reload then
  19.             local ret = BossRecord.Reload(character)   
  20.  
  21. *******************************************************************************************************************************
  22. ##################################################Installation#################################################################
  23. *******************************************************************************************************************************
  24.     This extension requires hook.lua and serialize.lua.
  25.     Add the above statement to actionsproc in missionsdk.lua.
  26.     Add an npc with the BossRecordNpc function to any map, make sure to add its name to the BossRecord.Name table.
  27.     Specify the savepath for the savefile in BossRecord.SavePath
  28. *******************************************************************************************************************************
  29. ##################################################Adding more bosses###########################################################
  30. *******************************************************************************************************************************
  31.    
  32.     BossRecord.Tracked holds all the bosses being tracked.
  33.     EG:
  34.         [885] = {Name = 'Black Dragon SS' , Respawn = 60},
  35.             885 is the ID of the mob
  36.             Black Dragon SS is the name of the mob
  37.             60 is the respawn time (in seconds) of the mob.
  38. *******************************************************************************************************************************
  39. ##################################################Notes########################################################################
  40. *******************************************************************************************************************************
  41.  
  42.     If there is more than one of a boss, the system will not work.
  43.     This is becuase the killing of the second one would reset the timer.
  44.     I will fix this at some point but it is a low priority.
  45.    
  46.     When you are going to close the server, use &lua Stop()
  47. ]]
  48.  
  49. --*******************************************************************************************************************************--
  50. --##################################################Config#######################################################################--
  51. --*******************************************************************************************************************************--
  52.  
  53.  
  54.  
  55. --BossRecord Object
  56. BossRecord = {}
  57. --Save path for the save file
  58. BossRecord.SavePath = GetResPath("script/New Extension/Data/BossLog.txt")
  59. --Initial page
  60. BossRecord.MessagePage = 1
  61. --Page that begins the list
  62. BossRecord.ListPage = 2
  63. --Messages in the npc
  64. BossRecord.Messages = {
  65.     "Showing Stats for ",
  66.     "Last killed by:   ",
  67.     "Last killed at:   ",
  68.     "Next respawn at:  ",
  69.     "Next Page",
  70.     "Back",
  71.     "--------",
  72.     "Hello, which mob do you want to check?",
  73.     "I can check boss respawn times for you!",
  74. }
  75. --table of all boss npc names. Required for the reload function to work.
  76. BossRecord.Name = {
  77.     "Boss NPC"
  78. }
  79. --Prevents overflow when server is closing.
  80. --Makes the clear function only run once
  81. BossRecord.ShutDown = false
  82.  
  83. --Table of all mobs being tracked.
  84. BossRecord.Tracked = {
  85.     [789] = {Name = 'Black Dragon' , Respawn = (60*60*24)},
  86.     [805] = {Name = 'Barborosa' , Respawn = (60*60*3)},
  87.     [807] = {Name = 'Deathsoul Commander' , Respawn = (60*60*3)},
  88.    
  89.     [1109] = {Name = 'Fury Kara' , Respawn = (60*60*24)},
  90.     [1105] = {Name = 'Firm Guard' , Respawn = (60*60*24)},
  91.     [1117] = {Name = 'Morpheus Abyss Demon' , Respawn = (60*60*24)},
  92.     [1113] = {Name = 'Vicous Relic Protector' , Respawn = (60*60*24)},
  93.    
  94.     [776] = {Name = 'Fox Sage' , Respawn = (60*30)},
  95.     [855] = {Name = 'Aberrance Blood Pollywog' , Respawn = (60*30)},
  96.    
  97.     [757] = {Name = 'Pirate Captain 008' , Respawn = (60*60)},
  98.     [786] = {Name = 'Lizardman Warrior Commander' , Respawn = (60*30)},
  99.     [788] = {Name = 'Evil Tribal Chieftian' , Respawn = (60*30)},
  100. }
  101.  
  102. --Used to adjust timezone from UTC.
  103. --EG 1 = UTC + 1
  104. -- - 1 = UTC - 1
  105. --ETC
  106. BossRecord.TimeZone = 0
  107. --*******************************************************************************************************************************--
  108. --##################################################NPC functions################################################################--
  109. --*******************************************************************************************************************************--
  110.  
  111. --NPC function
  112. function BossRecordNpc()
  113.     BossRecord.RefreshTrigger()
  114.     Talk(BossRecord.MessagePage,BossRecord.Messages[9])
  115.     Text(BossRecord.MessagePage,"View Boss List",JumpPage,BossRecord.ListPage)
  116.     Talk(BossRecord.ListPage,BossRecord.Messages[8])
  117.     BossRecord.GenerateList()
  118. end
  119.  
  120. --Creates the trigger to reload the npc
  121. function BossRecord.RefreshTrigger()
  122.         InitTrigger()
  123.             TriggerAction( 1, BossRecord.Reload)
  124.             TriggerAction( 1, JumpPage,1)
  125.         Start( GetMultiTrigger(), 1)
  126. end
  127.  
  128. --Generates the pages listing the bosses.
  129. --7 per page
  130. function BossRecord.GenerateList()
  131.     local page = BossRecord.ListPage
  132.     local count = 0
  133.     local total = 0
  134.     for i,v in pairs(BossRecord.Tracked) do
  135.         total = total + 1
  136.     end
  137.     local pages = math.ceil(total/7) + 2
  138.     local Table = table.load(BossRecord.SavePath,"r")
  139.     for i,v in pairs(BossRecord.Tracked) do
  140.         if count == 7 then
  141.             Text(page,BossRecord.Messages[5],JumpPage,page + 1)
  142.             page = page + 1
  143.             Talk(page,BossRecord.Messages[8])
  144.             count = 0
  145.         end
  146.         local Status = BossRecord.GetStatus(i)
  147.         Text(page,v.Name.." "..Status,JumpPage,pages)
  148.         BossRecord.GeneratePage(pages,i,page,Status)
  149.         pages = pages + 1
  150.         count = count + 1
  151.     end
  152. end
  153.  
  154. --Returns the status of the boss (dead or alive)
  155. function BossRecord.GetStatus(i)
  156.     local Table = table.load(BossRecord.SavePath,"r")
  157.     local Status = "Alive"
  158.         if Table[i] ~= nil and Table[i].Respawn ~= BossRecord.Messages[7] then
  159.             if BossRecord.SystemTimeNow() < Table[i].Respawn then
  160.                  Status = "Dead"
  161.             end
  162.         end
  163.     return Status
  164. end
  165.  
  166. --Generates the stat pages of the boss
  167. function BossRecord.GeneratePage(page,i,backPage,Status)
  168.     local Table = table.load(BossRecord.SavePath,"r")
  169.     local firstLine = BossRecord.PadString(BossRecord.Messages[1]..BossRecord.Tracked[i].Name)
  170.     local secondLine = BossRecord.PadString(BossRecord.Messages[2]..Table[i].KilledBy)
  171.     local thirdLine = BossRecord.PadString(BossRecord.Messages[3]..BossRecord.ConvertTime(Table[i].Time))
  172.     local fourthLine = BossRecord.PadString(BossRecord.Messages[4]..BossRecord.ConvertTime(Table[i].Respawn))
  173.     if Status == "Alive" then
  174.         fourthLine = BossRecord.PadString(BossRecord.Messages[4].."Alive")
  175.     end
  176.     Talk(page,firstLine..secondLine..thirdLine..fourthLine)
  177.     Text(page,BossRecord.Messages[6],JumpPage,backPage)
  178. end
  179.  
  180. --*******************************************************************************************************************************--
  181. --##################################################Mob Functions################################################################--
  182. --*******************************************************************************************************************************--
  183.  
  184. --Function runs when a mob dies.
  185. --If it is being tracked, records time and killer.
  186. function BossRecord.CheckDead(mob,role)
  187.     local ID = GetChaTypeID(mob)
  188.     if BossRecord.Tracked[ID] ~= nil then
  189.         local Table = table.load(BossRecord.SavePath,"r")
  190.         Table[ID] ={
  191.             KilledBy = GetChaDefaultName(role),
  192.             Time = BossRecord.SystemTimeNow(),
  193.             Respawn = BossRecord.SystemTimeNow() + BossRecord.Tracked[GetChaTypeID(mob)].Respawn
  194.         }
  195.         table.save(Table,BossRecord.SavePath,"w")
  196.     end
  197. end
  198.  
  199. --*******************************************************************************************************************************--
  200. --##################################################Time functions###############################################################--
  201. --*******************************************************************************************************************************--
  202.  
  203. --Returns the standard unix time
  204. function BossRecord.SystemTimeNow()
  205.     local TimeNow = os.date("*t")
  206.     local Value = os.time{day = TimeNow.day ,month = TimeNow.month,year = TimeNow.year,hour = TimeNow.hour, min = TimeNow.min,sec = TimeNow.sec}
  207.     return Value + (3600 * BossRecord.TimeZone)
  208. end
  209.  
  210. --Converts time into a readable format.
  211. function BossRecord.ConvertTime(Time)
  212.     if Time == BossRecord.Messages[7] then
  213.         return Time
  214.     end
  215.     return os.date("%c",Time)
  216. end
  217.  
  218.  
  219. --*******************************************************************************************************************************--
  220. --##################################################System functions#############################################################--
  221. --*******************************************************************************************************************************--
  222.  
  223. --Reloads the npc, updates display
  224. function BossRecord.Reload()
  225.     for i,v in pairs(BossRecord.Name) do
  226.         NpcInfoReload(v,BossRecordNpc)
  227.     end
  228. end
  229.  
  230. --Pads string to 42 chars.
  231. function BossRecord.PadString(str)
  232.     local Len = string.len(str)
  233.     local Lines = math.ceil(Len/42)
  234.     if Len == 42 then
  235.         return str
  236.     end
  237.     if Len < 42 then
  238.         for i = 1,42-Len do
  239.             str = str.." "
  240.         end
  241.     end
  242.     return str
  243. end
  244.  
  245. --Ensures the mobs are declared in the table
  246. function BossRecord.Initial()
  247.     local CheckTable = io.open(BossRecord.SavePath,"r")
  248.     if CheckTable~=nil then
  249.         io.close(CheckTable)
  250.     else
  251.         table.save({},BossRecord.SavePath,"w")
  252.     end
  253.     local Table = table.load(BossRecord.SavePath,"r")
  254.     for i,v in pairs(BossRecord.Tracked) do
  255.         if Table[i] == nil then
  256.             Table[i] = {
  257.                 KilledBy = BossRecord.Messages[7],
  258.                 Time = BossRecord.Messages[7],
  259.                 Respawn = BossRecord.Messages[7],
  260.             }
  261.         end
  262.     end
  263.     table.save(Table,BossRecord.SavePath,"w")
  264. end
  265. BossRecord.Initial()
  266.  
  267. --Function called on server close.
  268. --Clears all data, as mobs respawn.
  269. --Is not called on updateall, as it doesnt force respawns.
  270. function BossRecord.Clear()
  271.     if BossRecord.ShutDown == false then
  272.         local Table = table.load(BossRecord.SavePath,"r")
  273.         for i,v in pairs(Table) do
  274.             Table[i] = {
  275.                 KilledBy = BossRecord.Messages[7],
  276.                 Time = BossRecord.Messages[7],
  277.                 Respawn = BossRecord.Messages[7],
  278.             }
  279.         end
  280.         table.save(Table,BossRecord.SavePath,"w")
  281.         BossRecord.ShutDown = true
  282.     end
  283. end
  284. --*******************************************************************************************************************************--
  285. --##################################################Hooks########################################################################--
  286. --*******************************************************************************************************************************--
  287. --Hooks
  288. StopHook = StopHook or Stop
  289. Hook:AddPreHook("StopHook",BossRecord.Clear)
  290. Hook:AddPreHook("GetExp_PKM",BossRecord.CheckDead)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement