• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved DeathBroadcast

Ghazer

Member
Joined
Mar 13, 2009
Messages
350
Reaction score
6
Hello I have that script but dont found... can check this please?
Code:
local config = {
   affected = 10, -- how many players (deathAssits) from table deathList should this script be executed for?

   killStorageValue = 3943,
   deathStorageValue = 3944,

   -- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
   rewardItem = {
      use = false,
      itemid = 2152,
      minLevel = false, -- false if you don't want any level req
      minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
   },

   killMessage = {
      use = true,
      text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
      messageClass = MESSAGE_STATUS_CONSOLE_BLUE
   },

   broadcastMessage = {
      use = true,
      minLevel = false, -- false if you don't want any level req
      minLevelDiff = false, -- false if you don't want any level diff req (negative numbers allowed).
      text = "|KILLERNAME| [|KILLERLEVEL|] just killed |TARGETNAME| [|TARGETLEVEL|]!",
      messageClass = MESSAGE_STATUS_WARNING
   },

   killerAnimation = {
      use = true,
      text = "Frag!", -- Only 9 letters! No "commands" here.
      color = 144
   },

   targetAnimation = {
      use = true,
      text = "Owned!", -- Only 9 letters! No "commands" here.
      color = 180
   }
}

function onDeath(cid, corpse, deathList)
   for i = 1, math.min(config.affected, getConfigInfo('deathAssistCount')) do
      local killer = deathList[i]
      if(isPlayer(killer) == TRUE) then
         local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
         local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
      
         local killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
         local killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
      
         setPlayerStorageValue(killer, config.killStorageValue, targetKills)
         setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)

         local killerLevel = getPlayerLevel(killer)
         local targetLevel = getPlayerLevel(cid)
         local levelDiff = targetLevel - killerLevel

         local values = {
            ["KILLERKILLS"]        = killerKills,
            ["KILLERDEATHS"]        = killerDeaths,
            ["KILLERNAME"]          = getCreatureName(killer),
            ["KILLERLEVEL"]        = killerLevel,
         
            ["TARGETKILLS"]        = targetKills,
            ["TARGETDEATHS"]        = targetDeaths,
            ["TARGETNAME"]          = getCreatureName(cid),
            ["TARGETLEVEL"]        = targetLevel
         }

         function formateString(str)
            return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
         end
      
         if(config.rewardItem.use and (not config.rewardItem.minLevel or targetLevel >= config.rewardItem.minLevel) and (not config.rewardItem.minLevelDiff or levelDiff >= config.rewardItem.minLevelDiff)) then
            local uid = doPlayerAddItem(killer, config.rewardItem.itemid, 5)
         end
         if(config.killMessage.use) then
            doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
         end
         if(config.broadcastMessage.use and (not config.broadcastMessage.minLevel or getPlayerLevel(cid) >= config.broadcastMessage.minLevel) and (not config.broadcastMessage.minLevelDiff or levelDiff >= config.broadcastMessage.minLevelDiff)) then
            broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
         end
         if(config.killerAnimation.use) then
            doSendAnimatedText(getCreaturePosition(killer), config.killerAnimation.text, config.killerAnimation.color)
         end
         if(config.targetAnimation.use) then
            doSendAnimatedText(getCreaturePosition(cid), config.targetAnimation.text, config.targetAnimation.color)
         end
      end
   end

   return true
end


ERROR:
Code:
[2/9/2012 20:29:36] [Error - CreatureScript Interface] 
[2/9/2012 20:29:36] data/creaturescripts/scripts/deathBroadcast.lua:onDeath
[2/9/2012 20:29:36] Description: 
[2/9/2012 20:29:36] data/creaturescripts/scripts/deathBroadcast.lua:46: bad argument #3 to 'max' (number expected, got nil)
[2/9/2012 20:29:36] stack traceback:
[2/9/2012 20:29:36] 	[C]: in function 'max'
[2/9/2012 20:29:36] 	data/creaturescripts/scripts/deathBroadcast.lua:46: in function <data/creaturescripts/scripts/deathBroadcast.lua:42>

[2/9/2012 20:29:45] [Error - CreatureScript Interface] 
[2/9/2012 20:29:45] data/creaturescripts/scripts/deathBroadcast.lua:onDeath
[2/9/2012 20:29:45] Description: 
[2/9/2012 20:29:45] data/creaturescripts/scripts/deathBroadcast.lua:46: bad argument #3 to 'max' (number expected, got nil)
[2/9/2012 20:29:45] stack traceback:
[2/9/2012 20:29:45] 	[C]: in function 'max'
[2/9/2012 20:29:45] 	data/creaturescripts/scripts/deathBroadcast.lua:46: in function <data/creaturescripts/scripts/deathBroadcast.lua:42>


PD: The OTX Server Version: (2.32 - 1303) -

- - - Updated - - -

BUMP, anyone can update that script? I use OTX 2
 
Summ, with that one you gonna get the same error that users have been reporting on this thread..
When X players have 0 kills, storage returns 'false' or 'nil' so you get an error on console:

Code:
[11/11/2012 07:58:55] data/creaturescripts/scripts/deathBroadcast.lua:line: bad argument #2 to 'min' (number expected, got nil)

You should change this lines:
LUA:
	local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
	local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
 
	local killerKills = 0
	local killerDeaths = 0
    if isPlayer(killer) then
		killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
		killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
 
		setPlayerStorageValue(killer, config.killStorageValue, targetKills)
	end
For this ones:
LUA:
	local targetKills = math.max(0, (getPlayerStorageValue(cid, config.killStorageValue) or 0)) + 1
	local targetDeaths = math.max(0, (getPlayerStorageValue(cid, config.deathStorageValue)or 0)) + 1

	if isPlayer(killer) then
		killerKills = math.max(0, (getPlayerStorageValue(killer, config.killStorageValue) or 0)) + 1
		killerDeaths = math.max(0, (getPlayerStorageValue(killer, config.deathStorageValue) or 0)) + 1 
		setPlayerStorageValue(killer, config.killStorageValue, targetKills)
	end
 
LUA:
local config = {
	killStorageValue = 3943,
	deathStorageValue = 3944,
	-- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
 
 
	killMessage = {
		use = true,
		text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
		messageClass = MESSAGE_STATUS_CONSOLE_BLUE
	},
 
	broadcastMessage = {
		use = true,
		text = "|KILLERNAME| [|KILLERLEVEL|] just killed |TARGETNAME| [|TARGETLEVEL|]!",
		messageClass = MESSAGE_STATUS_WARNING
	},
 
	killerAnimation = {
		use = true,
		text = "Frag!", -- Only 9 letters! No "commands" here.
		color = 215
	},
 
	targetAnimation = {
		use = true,
		text = "Owned!", -- Only 9 letters! No "commands" here.
		color = 215
	}
}
 
 
function onDeath(cid, corpse, killer)
	local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
	local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
 
	local killerKills = 0
	local killerDeaths = 0
    if isPlayer(killer) then
		killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
		killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
	
		setPlayerStorageValue(killer, config.killStorageValue, targetKills)
	end
	
	setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)
 
	local values = {
		["KILLERKILLS"] = killerKills,
		["KILLERDEATHS"] = killerDeaths,
		["KILLERNAME"] = getCreatureName(killer),
		["KILLERLEVEL"] = (isPlayer(killer) and getPlayerLevel(killer) or 0),
 
		["TARGETKILLS"] = targetKills,
		["TARGETDEATHS"] = targetDeaths,
		["TARGETNAME"] = getCreatureName(cid),
		["TARGETLEVEL"] = getPlayerLevel(cid)
	}
 
	function formateString(str)
		return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
	end
 
	if(config.killMessage.use) then
		doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
	end
	if(config.broadcastMessage.use) then
		broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
	end
 
	return TRUE
end

Thanks! That script works, although I get an error when monster kills the player (it broadcasts though...)

Code:
[19/11/2012 16:37:55] Test One has logged in.
[19/11/2012 16:38:31] God Zie has logged in.

[19/11/2012 16:38:41] Lua Script Error: [CreatureScript Interface] 
[19/11/2012 16:38:41] data/creaturescripts/scripts/deathBroadcast.lua:onDeath
[19/11/2012 16:38:41] LuaScriptInterface::luaDoPlayerSendTextMessage(). Player not found
[19/11/2012 16:38:41] stack traceback:
[19/11/2012 16:38:41] 	[C]: in function 'doPlayerSendTextMessage'
[19/11/2012 16:38:41] 	data/creaturescripts/scripts/deathBroadcast.lua:65: in function <data/creaturescripts/scripts/deathBroadcast.lua:33>
[19/11/2012 16:38:41] > Broadcasted message: "Behemoth [0] just killed Test One [10]!".
[19/11/2012 16:38:41] Test One has logged out.
[19/11/2012 16:38:49] Test One has logged in.
[19/11/2012 16:39:19] > Broadcasted message: "God Zie [742] just killed Test One [9]!".
[19/11/2012 16:39:19] Test One has logged out.
 
LUA:
local config = {
	killStorageValue = 3943,
	deathStorageValue = 3944,
	-- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
 
 
	killMessage = {
		use = true,
		text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
		messageClass = MESSAGE_STATUS_CONSOLE_BLUE
	},
 
	broadcastMessage = {
		use = true,
		text = "|KILLERNAME| [|KILLERLEVEL|] just killed |TARGETNAME| [|TARGETLEVEL|]!",
		messageClass = MESSAGE_STATUS_WARNING
	},
 
	killerAnimation = {
		use = true,
		text = "Frag!", -- Only 9 letters! No "commands" here.
		color = 215
	},
 
	targetAnimation = {
		use = true,
		text = "Owned!", -- Only 9 letters! No "commands" here.
		color = 215
	}
}
 
 
function onDeath(cid, corpse, killer)
	local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
	local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
 
	local killerKills = 0
	local killerDeaths = 0
    if isPlayer(killer) then
		killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
		killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
 
		setPlayerStorageValue(killer, config.killStorageValue, targetKills)
	end
 
	setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)
 
	local values = {
		["KILLERKILLS"] = killerKills,
		["KILLERDEATHS"] = killerDeaths,
		["KILLERNAME"] = getCreatureName(killer),
		["KILLERLEVEL"] = (isPlayer(killer) and getPlayerLevel(killer) or 0),
 
		["TARGETKILLS"] = targetKills,
		["TARGETDEATHS"] = targetDeaths,
		["TARGETNAME"] = getCreatureName(cid),
		["TARGETLEVEL"] = getPlayerLevel(cid)
	}
 
	function formateString(str)
		return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
	end
 
	if(config.killMessage.use) and isPlayer(killer) then
		doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
	end
	if(config.broadcastMessage.use) then
		broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
	end
 
	return TRUE
end
 
LUA:
local config = {
	killStorageValue = 3943,
	deathStorageValue = 3944,
	-- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
 
 
	killMessage = {
		use = true,
		text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
		messageClass = MESSAGE_STATUS_CONSOLE_BLUE
	},
 
	broadcastMessage = {
		use = true,
		text = "|KILLERNAME| [|KILLERLEVEL|] just killed |TARGETNAME| [|TARGETLEVEL|]!",
		messageClass = MESSAGE_STATUS_WARNING
	},
 
	killerAnimation = {
		use = true,
		text = "Frag!", -- Only 9 letters! No "commands" here.
		color = 215
	},
 
	targetAnimation = {
		use = true,
		text = "Owned!", -- Only 9 letters! No "commands" here.
		color = 215
	}
}
 
 
function onDeath(cid, corpse, killer)
	local targetKills = math.max(0, getPlayerStorageValue(cid, config.killStorageValue)) + 1
	local targetDeaths = math.max(0, getPlayerStorageValue(cid, config.deathStorageValue)) + 1
 
	local killerKills = 0
	local killerDeaths = 0
    if isPlayer(killer) then
		killerKills = math.max(0, getPlayerStorageValue(killer, config.killStorageValue)) + 1
		killerDeaths = math.max(0, getPlayerStorageValue(killer, config.deathStorageValue)) + 1
 
		setPlayerStorageValue(killer, config.killStorageValue, targetKills)
	end
 
	setPlayerStorageValue(cid, config.deathStorageValue, targetDeaths)
 
	local values = {
		["KILLERKILLS"] = killerKills,
		["KILLERDEATHS"] = killerDeaths,
		["KILLERNAME"] = getCreatureName(killer),
		["KILLERLEVEL"] = (isPlayer(killer) and getPlayerLevel(killer) or 0),
 
		["TARGETKILLS"] = targetKills,
		["TARGETDEATHS"] = targetDeaths,
		["TARGETNAME"] = getCreatureName(cid),
		["TARGETLEVEL"] = getPlayerLevel(cid)
	}
 
	function formateString(str)
		return(str:gsub("|([A-Z]+)|", (function(a) return values[a] end)))
	end
 
	if(config.killMessage.use) and isPlayer(killer) then
		doPlayerSendTextMessage(killer, config.killMessage.messageClass, formateString(config.killMessage.text))
	end
	if(config.broadcastMessage.use) then
		broadcastMessage(formateString(config.broadcastMessage.text), config.broadcastMessage.messageClass)
	end
 
	return TRUE
end

THANK YOU! Works perfect! :D
 
Back
Top