• 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!

CreatureEvent Advanced Broadcast Deaths (including item reward [optional])

Alindane

Banned User
Joined
Apr 25, 2009
Messages
82
Reaction score
1
All credits goes to Colandus.

This code will broadcast deaths and increase a players frags for each kill (this does not affect red skull/ban frags).

- data/creaturescripts

In creaturescripts.xml add:
Code:
<event type="death" name="DeathBroadcast" script="deathBroadcast.lua"/>

- data/creaturescripts/scripts

In login.lua add:
Lua:
registerCreatureEvent(cid, "DeathBroadcast")

Create a new file, name it deathBroadcast.lua, in it write:
Lua:
local config = {
        killStorageValue = 3943,
        deathStorageValue = 3944,

        -- commands for the texts (those inside of ||, example: |KILLS| to show skills): KILLS, KILLERNAME, TARGETNAME
        rewardItem = {
                use = true,
                itemid = 8698,
                minLevel = 100, -- false if you don't want any level req
                minLevelDiff = 20, -- false if you don't want any level diff req (negative numbers allowed).
                text = "This is a gift to |KILLERNAME| [|KILLERLEVEL|] for killing |TARGETNAME| [|TARGETLEVEL|]"
        },
       
        killMessage = {
                use = true,
                text = "You owned |TARGETNAME|! You have now |KILLERKILLS| kills!",
                messageClass = MESSAGE_STATUS_CONSOLE_BLUE
        },
       
        broadcastMessage = {
                use = true,
                minLevel = 100, -- false if you don't want any level req
                minLevelDiff = 0, -- 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 = 215
        },
       
        targetAnimation = {
                use = true,
                text = "Owned!", -- Only 9 letters! No "commands" here.
                color = 215
        }
}

function onDeath(cid, corpse, killer)
        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, 1)
                        doSetItemSpecialDescription(uid, formateString(config.rewardItem.text))
                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
       
        return TRUE
end


Enjoy! :)
 
Last edited:
[21/05/2009 16:40:23] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/deathBroadcast.lua)
[21/05/2009 16:40:23] data/creaturescripts/scripts/deathBroadcast.lua:55: '}' expected (to close '{' at line 49) near '='
[21/05/2009 16:40:23] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/playerpreparedeath.lua)
[21/05/2009 16:40:23] cannot open data/creaturescripts/scripts/playerpreparedeath.lua: No such file or directory
 
It seems nice. but I can't get it to work:

[21/05/2009 16:40:23] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/deathBroadcast.lua)
[21/05/2009 16:40:23] data/creaturescripts/scripts/deathBroadcast.lua:55: '}' expected (to close '{' at line 49) near '='
 
Been looking for a script like this for a while, thanks a lot ;)

+Rep for you and Colandus.

The only thing I think is wrong (mistake) on the script, is the fact that the player who gets the trophy is the killed player, not the killer xD Or is that how it is supposed to be?

Also, is it possible that anyone could make it so:

1) You'll only get the trophy if the player you killed is higher lvl than you.

2) The kill will only get broadcasted if the killed player(s) are higher than a certain X lvl.

Sorry for the abuse :p
Thanks again.

Cheers.
 
I don't know why but when i kill a player don't broadcast nothing :(
(sorry for bad english :D)
I really need ths script ! :(
I'm using TFS 0.2. [8.42]
Mystic Spirit.......
It doesn't show any errors!
 
Last edited:
You need to change "minLevel" and/or "minLevelDiff", because the current settings won't let it broadcast if you kill someone below your level or if you are below level 100.
 
It should work always this way:
Lua:
        broadcastMessage = {
                use = true,
                minLevel = 0, -- false/0 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
        },
 
Man, i have used one player level 130 and one level 145.
Player level 130 killed 145 and later 145 killed player level 130.
It doesn't show any Broadcast :( :x'
 
[26/07/2009 21:20:14] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/deathBroadcast.lua)
[26/07/2009 21:20:14] data/creaturescripts/scripts/deathBroadcast.lua:11: '}' expected (to close '{' at line 6) near 'is'


:~
 
Back
Top