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

On kill this creature > do this tfs 1.4.2

eardrums

Member
Joined
May 27, 2010
Messages
94
Solutions
1
Reaction score
10
hello,

So I'm trying to make a script that when you kill a creature it does something.
could be changing a players storage value or sending a message to the player.

I've never messed around with the creaturescripts before, so I would love someone tell me where to put the files exactly and what to put in the creaturescripts.xml

I literally just want something as simple as this. let me know what im missing. thanks!

Lua:
function onKill(cid, target)
    if target:getName() == "dragon" then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "it worked")
    end
end
 
Solution
okay @Xikini

i used the script and it worked. but then as i was testing other things i got the message after killing anything xd. so now anything i kill sends the message. no matter what monster i kill lol
how do i fix this and make it just 1 monster
That's where if statements come in. :)

Lua:
function killEvent.onKill(player, target)
    if target:getName():lower() == "dragon" then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You've killed a " .. target:getName() .. ".")
    end
    return true
end
Lua:
local config = {
    ['Dragon'] = {effect = 10, text = 'You killed a dragon'},
    ['Demon'] = {effect = 10, text = 'You killed a dragon'}
}
  
local killMonster = CreatureEvent("effectOnKill")

function killMonster.onKill(creature, target)
    local monster = config[target:getName()]
    if monster then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, monster.text)
        --creature:sendTextMessage(MESSAGE_INFO_DESCR, 'You have killed a' ..target:getName()..'.'
        target:getPosition():sendMagicEffect(monster.effect)
    end
    return true
end

killMonster:type("kill")
killMonster:register()

local killMonsterLogin = CreatureEvent("killMonsterLogin")

function killMonsterLogin.onLogin(player)
    player:registerEvent("effectOnKill")
    return true
end

killMonsterLogin:register()

Here a simple revscript :D I did not test it but it should work
 
Last edited:
i got this error.
crerror.png


i put this line in the xml file

<event type="death" name="death" script="solum/quests/the mystery plague/kill test.lua" />
 
I did that but nothing happened. When I kill a dragon nothing happens.
only thing i did is put the script in the data/scripts/creaturescripts/monsters

I guess there is something im missing?
 
I did that but nothing happened. When I kill a dragon nothing happens.
only thing i did is put the script in the data/scripts/creaturescripts/monsters

I guess there is something im missing?
After reloading with that script u need relog, as it registers onLogin
 
its the dragon kill file. this is the right location right?
View attachment 77300
anywhere in data/scripts is fine.
The path you show here, is fine.

Ensure it's a .lua file and not a .txt or some other file extension.

You can try this simple code.
All in 1 file.
Lua:
local killEvent = CreatureEvent("newOnKillEvent") -- must match, and be unique string
killEvent:type("kill")

function killEvent.onKill(player, target)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You've killed a " .. target:getName() .. ".")
    return true
end

killEvent:register()


local loginEvent = CreatureEvent("registerOnKill") -- must be unique string
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("newOnKillEvent") -- must match, and be unique string
    return true
end

loginEvent:register()
 
okay @Xikini

i used the script and it worked. but then as i was testing other things i got the message after killing anything xd. so now anything i kill sends the message. no matter what monster i kill lol
how do i fix this and make it just 1 monster
Post automatically merged:

Lua:
local killEvent = CreatureEvent("KillInfectedMan") -- must match, and be unique string
killEvent:type("kill")

function killEvent.onKill(player, target)

if player:getStorageValue(30001) == 4 and
   player:getStorageValue(30006) == -1 then
    
    player:sendTextMessage(MESSAGE_STATUS_WARNING, "It's sad but it had to be done.")
    player:setStorageValue(30006, 1)
    
    elseif player:getStorageValue(30006) == 1 then
    
    player:setStorageValue(30001, 5)
    player:sendTextMessage(MESSAGE_STATUS_WARNING, "It's sad but it had to be done.")
    return true
end

killEvent:register()


local loginEvent = CreatureEvent("KillInfectedMann") -- must be unique string
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("KillInfectedMan") -- must match, and be unique string
    return true
end

loginEvent:register()
 
okay @Xikini

i used the script and it worked. but then as i was testing other things i got the message after killing anything xd. so now anything i kill sends the message. no matter what monster i kill lol
how do i fix this and make it just 1 monster
That's where if statements come in. :)

Lua:
function killEvent.onKill(player, target)
    if target:getName():lower() == "dragon" then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You've killed a " .. target:getName() .. ".")
    end
    return true
end
 
Solution
Lua:
local config = {
    ['Dragon'] = {effect = 10, text = 'You killed a dragon'},
    ['Demon'] = {effect = 10, text = 'You killed a dragon'}
}
  
local killMonster = CreatureEvent("effectOnKill")

function killMonster.onKill(creature, target)
    local monster = config[target:getName()]
    if monster then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, monster.text)
        target:getPosition():sendMagicEffect(monster.effect)
    end
    return true
end

killMonster:type("kill")
killMonster:register()

local killMonsterLogin = CreatureEvent("killMonsterLogin")

function killMonsterLogin.onLogin(player)
    player:registerEvent("effectOnKill")
    return true
end

killMonsterLogin:register()

Here a simple revscript :D I did not test it but it should work

It didnt work because of
Lua:
local killMonsterLogin = CreatureEvent("register")
I edited it now its working
 
Back
Top