Jump to content

[Lua]Npc показывающий боссов и информацию о них


Go-piratia

Recommended Posts

--[[

							*###########################################################################*
							#                              -Boss NPC by 7n6.-                           #
							#       If used please give credit or I will break your server Kappa.       #
							#                  (But seriously don't remove credits...)                  #
							*###########################################################################*
	

	
	
	
*******************************************************************************************************************************	
###############################################################################################################################
*******************************************************************************************************************************	
	MissionSdk.lua : ActionsProc :
	
		elseif actions[i].func == BossRecord.Reload then
			local ret = BossRecord.Reload(character)	

*******************************************************************************************************************************	
##################################################Installation#################################################################
*******************************************************************************************************************************	
	This extension requires hook.lua and serialize.lua.
	Add the above statement to actionsproc in missionsdk.lua.
	Add an npc with the BossRecordNpc function to any map, make sure to add its name to the BossRecord.Name table.
	Specify the savepath for the savefile in BossRecord.SavePath 
*******************************************************************************************************************************	
##################################################Adding more bosses###########################################################
*******************************************************************************************************************************	
	
	BossRecord.Tracked holds all the bosses being tracked.
	EG: 
		[885] = {Name = 'Black Dragon SS' , Respawn = 60},
			885 is the ID of the mob
			Black Dragon SS is the name of the mob
			60 is the respawn time (in seconds) of the mob.
*******************************************************************************************************************************	
##################################################Notes########################################################################
*******************************************************************************************************************************	

	If there is more than one of a boss, the system will not work.
	This is becuase the killing of the second one would reset the timer.
	I will fix this at some point but it is a low priority.
	
	When you are going to close the server, use &lua BossRecord.Clear() before closing it.
	Originaly this was hooked to Stop(), but due to overflow issues after updateall it isnt anymore.
]]

--*******************************************************************************************************************************--	
--##################################################Config#######################################################################--
--*******************************************************************************************************************************--	



--BossRecord Object
BossRecord = {}
--Save path for the save file
BossRecord.SavePath = GetResPath("script/New Extension/Data/BossLog.txt")
--Initial page
BossRecord.MessagePage = 1
--Page that begins the list
BossRecord.ListPage = 2
--Messages in the npc
BossRecord.Messages = {
	"Showing Stats for ",
	"Last killed by:   ",
	"Last killed at:   ",
	"Next respawn at:  ",
	"Next Page",
	"Back",
	"--------",
	"Hello, which mob do you want to check?",
	"I can check boss respawn times for you!",
}
--table of all boss npc names. Required for the reload function to work.
BossRecord.Name = {
	"Boss NPC"
}
--Prevents overflow when server is closing.
--Makes the clear function only run once
BossRecord.ShutDown = false

--Table of all mobs being tracked.
BossRecord.Tracked = {
	[789] = {Name = 'Black Dragon' , Respawn = (60*60*24)},
	[805] = {Name = 'Barborosa' , Respawn = (60*60*3)},
	[807] = {Name = 'Deathsoul Commander' , Respawn = (60*60*3)},
	
	[1109] = {Name = 'Fury Kara' , Respawn = (60*60*24)},
	[1105] = {Name = 'Firm Guard' , Respawn = (60*60*24)},
	[1117] = {Name = 'Morpheus Abyss Demon' , Respawn = (60*60*24)},
	[1113] = {Name = 'Vicous Relic Protector' , Respawn = (60*60*24)},
	
	[776] = {Name = 'Fox Sage' , Respawn = (60*30)},
	[855] = {Name = 'Aberrance Blood Pollywog' , Respawn = (60*30)},
	
	[757] = {Name = 'Pirate Captain 008' , Respawn = (60*60)},
	[786] = {Name = 'Lizardman Warrior Commander' , Respawn = (60*30)},
	[788] = {Name = 'Evil Tribal Chieftian' , Respawn = (60*30)},
}

--*******************************************************************************************************************************--	
--##################################################NPC functions################################################################--
--*******************************************************************************************************************************--	

--NPC function
function BossRecordNpc()
	BossRecord.RefreshTrigger()
	Talk(BossRecord.MessagePage,BossRecord.Messages[9])
	Text(BossRecord.MessagePage,"View Boss List",JumpPage,BossRecord.ListPage)
	Talk(BossRecord.ListPage,BossRecord.Messages[8])
	BossRecord.GenerateList()
end

--Creates the trigger to reload the npc
function BossRecord.RefreshTrigger()
		InitTrigger()
			TriggerAction( 1, BossRecord.Reload)
			TriggerAction( 1, JumpPage,1)
		Start( GetMultiTrigger(), 1)
end

--Generates the pages listing the bosses.
--7 per page
function BossRecord.GenerateList()
	local page = BossRecord.ListPage
	local count = 0
	local total = 0
	for i,v in pairs(BossRecord.Tracked) do
		total = total + 1
	end
	local pages = math.ceil(total/7) + 2
	local Table = table.load(BossRecord.SavePath,"r")
	for i,v in pairs(BossRecord.Tracked) do
		if count == 7 then
			Text(page,BossRecord.Messages[5],JumpPage,page + 1)
			page = page + 1
			Talk(page,BossRecord.Messages[8])
			count = 0
		end
		local Status = BossRecord.GetStatus(i)
		Text(page,v.Name.." "..Status,JumpPage,pages)
		BossRecord.GeneratePage(pages,i,page,Status)
		pages = pages + 1
		count = count + 1
	end
end

--Returns the status of the boss (dead or alive)
function BossRecord.GetStatus(i)
	local Table = table.load(BossRecord.SavePath,"r")
	local Status = "Alive"
		if Table[i] ~= nil and Table[i].Respawn ~= BossRecord.Messages[7] then
			if BossRecord.SystemTimeNow() < Table[i].Respawn then
				 Status = "Dead"
			end
		end
	return Status
end

--Generates the stat pages of the boss
function BossRecord.GeneratePage(page,i,backPage,Status)
	local Table = table.load(BossRecord.SavePath,"r")
	local firstLine = BossRecord.PadString(BossRecord.Messages[1]..BossRecord.Tracked[i].Name)
	local secondLine = BossRecord.PadString(BossRecord.Messages[2]..Table[i].KilledBy)
	local thirdLine = BossRecord.PadString(BossRecord.Messages[3]..BossRecord.ConvertTime(Table[i].Time))
	local fourthLine = BossRecord.PadString(BossRecord.Messages[4]..BossRecord.ConvertTime(Table[i].Respawn))
	if Status == "Alive" then
		fourthLine = BossRecord.PadString(BossRecord.Messages[4].."Alive")
	end
	Talk(page,firstLine..secondLine..thirdLine..fourthLine)
	Text(page,BossRecord.Messages[6],JumpPage,backPage)
end

--*******************************************************************************************************************************--	
--##################################################Mob Functions################################################################--
--*******************************************************************************************************************************--	

--Function runs when a mob dies.
--If it is being tracked, records time and killer.
function BossRecord.CheckDead(mob,role)
	local ID = GetChaTypeID(mob)
	if BossRecord.Tracked[ID] ~= nil then
		local Table = table.load(BossRecord.SavePath,"r")
		Table[ID] ={
			KilledBy = GetChaDefaultName(role),
			Time = BossRecord.SystemTimeNow(),
			Respawn = BossRecord.SystemTimeNow() + BossRecord.Tracked[GetChaTypeID(mob)].Respawn
		}
		table.save(Table,BossRecord.SavePath,"w")
	end
end

--*******************************************************************************************************************************--	
--##################################################Time functions###############################################################--
--*******************************************************************************************************************************--	

--Returns the standard unix time
function BossRecord.SystemTimeNow()
	local TimeNow = os.date("*t")
	local Value = os.time{day = TimeNow.day ,month = TimeNow.month,year = TimeNow.year,hour = TimeNow.hour, min = TimeNow.min,sec = TimeNow.sec}
	return Value
end

--Converts time into a readable format.
function BossRecord.ConvertTime(Time)
	if Time == BossRecord.Messages[7] then
		return Time
	end
	return os.date("%c",Time)
end


--*******************************************************************************************************************************--	
--##################################################System functions#############################################################--
--*******************************************************************************************************************************--	

--Reloads the npc, updates display
function BossRecord.Reload()
	for i,v in pairs(BossRecord.Name) do
		NpcInfoReload(v,BossRecordNpc)
	end
end

--Pads string to 42 chars.
function BossRecord.PadString(str)
	local Len = string.len(str)
	local Lines = math.ceil(Len/42)
	if Len == 42 then
		return str
	end
	if Len < 42 then
		for i = 1,42-Len do
			str = str.." "
		end
	end
	return str
end

--Ensures the mobs are declared in the table
function BossRecord.Initial()
	local CheckTable = io.open(BossRecord.SavePath,"r")
	if CheckTable~=nil then 
		io.close(CheckTable) 
	else 
		table.save({},BossRecord.SavePath,"w")
	end
	local Table = table.load(BossRecord.SavePath,"r")
	for i,v in pairs(BossRecord.Tracked) do
		if Table[i] == nil then
			Table[i] = {
				KilledBy = BossRecord.Messages[7],
				Time = BossRecord.Messages[7],
				Respawn = BossRecord.Messages[7],
			}
		end
	end
	table.save(Table,BossRecord.SavePath,"w")
end
BossRecord.Initial()

--Function called on server close.
--Clears all data, as mobs respawn.
--Is not called on updateall, as it doesnt force respawns.
function BossRecord.Clear()
	if BossRecord.ShutDown == false then
		local Table = table.load(BossRecord.SavePath,"r")
		for i,v in pairs(Table) do
			Table[i] = {
				KilledBy = BossRecord.Messages[7],
				Time = BossRecord.Messages[7],
				Respawn = BossRecord.Messages[7],
			}
		end
		table.save(Table,BossRecord.SavePath,"w")
		BossRecord.ShutDown = true
	end
end
--*******************************************************************************************************************************--	
--##################################################Hooks########################################################################--
--*******************************************************************************************************************************--	
--Hooks
--Hook:AddPreHook("Stop",BossRecord.Clear) --Disabled due to issue
Hook:AddPreHook("GetExp_PKM",BossRecord.CheckDead)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Chat

Chat

Please enter your display name

×
×
  • Create New...