Jump to content
Yie

Killed by

Recommended Posts

3 hours ago, Yie said:

How can i create a function when the boss died that announces who killed it. Thanks

resource\script\calculate\exp_and_level.lua

 

search for:

function GetExp_New(dead , atk  ) 

Under this:

function GetExp_New(dead , atk  ) 
	if ValidCha(atk) == 0  then 
		LG ( "exp_atker=NIL" , "function GetExp_New : atker = nil " ) 
		return 
	end 
	local a = Check_Combat_Mod(dead , atk ) 
	if a==1 then 
	GetExp_PKM( dead , atk ) --[[player kill monster]]--
	elseif a==2 then 
	GetExp_MKP(dead , atk) --[[monster kill player]]--
	elseif a==3 then 
	GetExp_PKP(dead , atk) --[[player kill player]]--
	elseif a==4 then 
	GetExp_Noexp(dead , atk) --[[monster kill monster]]--
	else 
	end 

Add the following:

    local id = GetChaID(dead) -- Retrieve ID of killed monster
    local monstername = GetChaDefaultName(dead) -- Retrieve name of killed monster
    local cha_name = GetChaDefaultName ( atk ) -- Retrieve name of the player killed the monster

    if id ==973 then -- Check for monster ID ( characterinfo.txt ID )
        GMNotice(string.format('<%s> has killed, <%s> !!', cha_name, monstername)); -- Announce a GMNotice
	-- ( Requires GameServer and GroupServer with enabled GMNotice function, otherwise use the normal Notice Function )
		Notice("<".cha_name."> has killed, <".monstername."> !!")
    end

Goodluck.

Share this post


Link to post
Share on other sites
33 minutes ago, cpworkerz said:

resource\script\calculate\exp_and_level.lua

 

search for:


function GetExp_New(dead , atk  ) 

Under this:


function GetExp_New(dead , atk  ) 
	if ValidCha(atk) == 0  then 
		LG ( "exp_atker=NIL" , "function GetExp_New : atker = nil " ) 
		return 
	end 
	local a = Check_Combat_Mod(dead , atk ) 
	if a==1 then 
	GetExp_PKM( dead , atk ) --[[player kill monster]]--
	elseif a==2 then 
	GetExp_MKP(dead , atk) --[[monster kill player]]--
	elseif a==3 then 
	GetExp_PKP(dead , atk) --[[player kill player]]--
	elseif a==4 then 
	GetExp_Noexp(dead , atk) --[[monster kill monster]]--
	else 
	end 

Add the following:


    local id = GetChaID(dead) -- Retrieve ID of killed monster
    local monstername = GetChaDefaultName(dead) -- Retrieve name of killed monster
    local cha_name = GetChaDefaultName ( atk ) -- Retrieve name of the player killed the monster

    if id ==973 then -- Check for monster ID ( characterinfo.txt ID )
        GMNotice(string.format('<%s> has killed, <%s> !!', cha_name, monstername)); -- Announce a GMNotice
	-- ( Requires GameServer and GroupServer with enabled GMNotice function, otherwise use the normal Notice Function )
		Notice("<".cha_name."> has killed, <".monstername."> !!")
    end

Goodluck.

Thanks alot!

  • Like 1

Share this post


Link to post
Share on other sites

Hello @Yie and @cpworkerz,

 

one more solution:

 

Add this script to file functions.lua

-- Player killed monster event
GetExp_PKM__Original = GetExp_PKM
GetExp_PKM = function(monster, role)
	
	-- Call original function GetExp_PKM()
	GetExp_PKM__Original(monster, role)
	
	-- Get ID of the killed monster
	local mob_id = GetChaID(monster)
	
	-- Check the monster ID
	if (mob_id == 789) then -- Black Dragon
		
		-- Show a message
		Notice( string.format("%s has killed %s!", GetChaDefaultName(role), GetChaDefaultName(monster)) )
		
	end
	
end

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Adding onto what @V3ct0r said using hooks, this is a somewhat better version of his which allows more simplistic usage without adding more conditions within the function, just new variables.

BossKillNotice = {}
BossKillNotice[789] = '[&MONSTER&] was killed by [&PLAYER&]!'

OriginalGetExp_PKM = GetExp_PKM
GetExp_PKM = function(Monster, Player)
	OriginalGetExp_PKM(Monster, Player)                 -- Call original function GetExp_PKM()
	local MonsterID = GetChaID(Monster)                 -- Get ID of the killed monster.
	local MonsterName = GetChaDefaultName(Monster)      -- Get monster name.
    local PlayerName = GetChaDefaultName(Player)        -- Get player name.

    if not BossKillNotice[MonsterID] then
        return                                          -- No point in continuing function if a notice is not declared for this ID.
    end
    local Message = BossKillNotice[MonsterID]
    Message = Message:gsub('&MONSTER&', MonsterName)    -- Replace placeholder with actual monster name.
    Message = Message:gsub('&PLAYER&', PlayerName)      -- Replace placeholder with actual player name.
    Notice(Message)
end

Essentially just add a new variable under "BossKillNotice" as the example shown. The "&MONSTER&" and "&PLAYER&" are placeholders, meaning you can move them aroiund for more creative notices at your liking.

 

For example, this shows the monster was killed by the player:

BossKillNotice[789] = '[&MONSTER&] was killed by [&PLAYER&]!'

You can also do the player killed the monster:

BossKillNotice[789] = '[&PLAYER&] killed [&MONSTER&]!'

And the "[789]" correspond to the monster ID, so to add a new notice, just change the ID. Like this:

BossKillNotice[989] = '[&MONSTER&] was killed by [&PLAYER&]!'



This should be compatible with all lua versions I think.

Edited by Angelix
  • Thanks 1

Share this post


Link to post
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.   Restore formatting

  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.


×
×
  • Create New...