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

Solved Kill monster, spawn new monster not working.

juansanchez

Intermediate OT User
Joined
Apr 2, 2015
Messages
217
Reaction score
130
Hey guys, i have a problem with a script i found here in the forum made by @Xikini .

Code:
[LIST=1]
[*]local creatureName = 'cave rat' -- creaturename (must be lowercase letters)
[*]local newCreature = 'rat'
[*]local creatureSay = 'I am saying something'
[*]

[*]function onKill(cid, target, damage, flags)
[*]   if isPlayer(target) then
[*]     return false
[*]   end
[*]   local name = getCreatureName(target):lower()
[*]   if name ~= creatureName then
[*]     return false
[*]   end
[*]   local position = getCreaturePosition(target)
[*]

[*]   -- player says something
[*]   -- doCreatureSay(cid, ''.. creatureSay ..'', TALKTYPE_ORANGE_1)
[*]

[*]   -- creature says something
[*]   doCreatureSay(cid, ''.. creatureSay ..'', TALKTYPE_ORANGE_1, false, 0, position)
[*]

[*]   -- create monster near the corpse (no delay)
[*]   doCreateMonster(newCreature, position)
[*]

[*]   -- create monster on the corpse (very small delay, that may or may not be noticeable to the player, however is noticeable with god on local connection)
[*]   -- addEvent(doCreateMonster, 0, newCreature, position)
[*]   return true
[*]end
[/LIST]

So basically what it does is, you kill a certain monster, when that monster dies, another spawns. I'm using it for a quest, where you need to kill the first boss and after that the actual boss spawns. I believe is similar to Zalomon on Wrath of the Emperror, but i'm not sure, i never did that quest.

I registered it on login.lua.
I added the script to the monster.xml, did everything right. However when i kill the monster nothing happens, no errors, doesn't spawn the second boss, nothing. I did try to use an onDeath function but whenever a player died on my server, anywhere on the map, the boss would spawn next to the player and stay there.

This is the one i tried using:
Code:
function onDeath(cid)
doSendMagicEffect(getThingPos(cid), 36)
return doCreateMonster('Satan', getThingPos(cid))
end

Can anyone help me? Maybe tell me what i did wrong?

I'm using TFS 0.3.6
 
Hey guys, i have a problem with a script i found here in the forum made by @Xikini .

Code:
[LIST=1]
[*]local creatureName = 'cave rat' -- creaturename (must be lowercase letters)
[*]local newCreature = 'rat'
[*]local creatureSay = 'I am saying something'
[*]

[*]function onKill(cid, target, damage, flags)
[*]   if isPlayer(target) then
[*]     return false
[*]   end
[*]   local name = getCreatureName(target):lower()
[*]   if name ~= creatureName then
[*]     return false
[*]   end
[*]   local position = getCreaturePosition(target)
[*]

[*]   -- player says something
[*]   -- doCreatureSay(cid, ''.. creatureSay ..'', TALKTYPE_ORANGE_1)
[*]

[*]   -- creature says something
[*]   doCreatureSay(cid, ''.. creatureSay ..'', TALKTYPE_ORANGE_1, false, 0, position)
[*]

[*]   -- create monster near the corpse (no delay)
[*]   doCreateMonster(newCreature, position)
[*]

[*]   -- create monster on the corpse (very small delay, that may or may not be noticeable to the player, however is noticeable with god on local connection)
[*]   -- addEvent(doCreateMonster, 0, newCreature, position)
[*]   return true
[*]end
[/LIST]

So basically what it does is, you kill a certain monster, when that monster dies, another spawns. I'm using it for a quest, where you need to kill the first boss and after that the actual boss spawns. I believe is similar to Zalomon on Wrath of the Emperror, but i'm not sure, i never did that quest.

I registered it on login.lua.
I added the script to the monster.xml, did everything right. However when i kill the monster nothing happens, no errors, doesn't spawn the second boss, nothing. I did try to use an onDeath function but whenever a player died on my server, anywhere on the map, the boss would spawn next to the player and stay there.

This is the one i tried using:
Code:
function onDeath(cid)
doSendMagicEffect(getThingPos(cid), 36)
return doCreateMonster('Satan', getThingPos(cid))
end

Can anyone help me? Maybe tell me what i did wrong?

I'm using TFS 0.3.6
Dunno. I don't see anything wrong with it. lol

I've removed the unnecessary bits. Try reinstalling it.

data/creaturescripts/creaturescripts.xml
XML:
<event type="kill" name="onKill_spawn_other_monster" event="script" value="onKill_spawn_other_monster.lua"/>
data/creaturescripts/scripts/login.lua [near the bottom, with the other registered events]
Lua:
registerCreatureEvent(cid, "onKill_spawn_other_monster")
data/creaturescripts/scripts/onKill_spawn_other_monster.lua
Lua:
local creatureName = "cave rat"
local newCreature = "rat"
local creatureSay = "I am saying something"

function onKill(cid, target, damage, flags)
    if isPlayer(target) then
        return false
    end
   
    local name = getCreatureName(target):lower()
    if name ~= creatureName:lower() then
        return false
    end
   
    local position = getCreaturePosition(target)
    doCreatureSay(cid, creatureSay, TALKTYPE_ORANGE_1, false, 0, position)
    addEvent(doCreateMonster, 0, newCreature, position)
    return true
end
 
using ondeath is ideal because onkill executes for each player that attacked the target
register an ondeath script to the monster xml file using
XML:
<script>
    <event name="some event name"/>
</script>
 
Dunno. I don't see anything wrong with it. lol

I've removed the unnecessary bits. Try reinstalling it.

data/creaturescripts/creaturescripts.xml
XML:
<event type="kill" name="onKill_spawn_other_monster" event="script" value="onKill_spawn_other_monster.lua"/>
data/creaturescripts/scripts/login.lua [near the bottom, with the other registered events]
Lua:
registerCreatureEvent(cid, "onKill_spawn_other_monster")
data/creaturescripts/scripts/onKill_spawn_other_monster.lua
Lua:
local creatureName = "cave rat"
local newCreature = "rat"
local creatureSay = "I am saying something"

function onKill(cid, target, damage, flags)
    if isPlayer(target) then
        return false
    end
 
    local name = getCreatureName(target):lower()
    if name ~= creatureName:lower() then
        return false
    end
 
    local position = getCreaturePosition(target)
    doCreatureSay(cid, creatureSay, TALKTYPE_ORANGE_1, false, 0, position)
    addEvent(doCreateMonster, 0, newCreature, position)
    return true
end

I tried reinstaling like you said, nothing happend.

q7bKDR7.jpg


QnM871b.jpg


YZeXF4C.jpg


And is it necessary to add this on the monster.xml? I tried with and without it.

tdjMdBY.jpg




using ondeath is ideal because onkill executes for each player that attacked the target
register an ondeath script to the monster xml file using
XML:
<script>
    <event name="some event name"/>
</script>

The onDeath one created the Boss whenever a player died anywhere on the map.
 
The onDeath one created the Boss whenever a player died anywhere on the map.
If you install the onDeath script only in the monster, and do not register it in login.lua, it would only work for the monster.

Depending on what you are trying to accomplish.. onKill/onPrepareDeath/onDeath will all do slightly different things.

-----
Let's troubleshoot the original script, because that it what you asked for.
When using onKill, the script portion inside the monster file is not necessary.

The easiest way to troubleshoot a script is to simply start printing values. (this really should be your first step with any script you are having trouble with)
We can find out if the values found are incorrect, or if there is some logic error in the script somewhere.

So, here's the same script with a bunch of prints.
After killing the monster, check your console for what prints.

// If nothing is appearing in the console after killing a monster, that means the script errored while the server was starting.
// I would suggest not to use /reload as it's not always 100% reliable. But if you do, make sure to relog the character you are testing on, before testing.

If you're not sure how the information is useful, feel free to post a screenshot of your console.
Lua:
local creatureName = "cave rat"
local newCreature = "rat"
local creatureSay = "I am saying something"

function onKill(cid, target, damage, flags)
    print("Script starting..")
    if isPlayer(target) then
        print("Script ended. Target killed was a player.")
        return false
    end
 
    local name = getCreatureName(target):lower()
    print("targets name: " .. name .. " | checking against: " .. creatureName .. "")
    if name ~= creatureName:lower() then
        print("Script ended. targets name does not match intended criteria.")
        return false
    end
 
    local position = getCreaturePosition(target)
    print("targets position: {x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z .. "}")
    print("placing orange text '" .. creatureSay .. "' at targets position.")
    doCreatureSay(cid, creatureSay, TALKTYPE_ORANGE_1, false, 0, position)
    print("creating monster " .. newCreature .. " at targets position")
    addEvent(doCreateMonster, 0, newCreature, position)
    print("Script ended. Monster should spawn directly after this message appears in console.")
    return true
end
 
Last edited:
If you install the onDeath script only in the monster, and do not register it in login.lua, it would only work for the monster.

Depending on what you are trying to accomplish.. onKill/onPrepareDeath/onDeath will all do slightly different things.

-----
Let's troubleshoot the original script, because that it what you asked for.
When using onKill, the script portion inside the monster file is not necessary.

The easiest way to troubleshoot a script is to simply start printing values. (this really should be your first step with any script you are having trouble with)
We can find out if the values found are incorrect, or if there is some logic error in the script somewhere.

So, here's the same script with a bunch of prints.
After killing the monster, check your console for what prints.

// If nothing is appearing in the console after killing a monster, that means the script errored while the server was starting.
// I would suggest not to use /reload as it's not always 100% reliable. But if you do, make sure to relog the character you are testing on, before testing.

If you're not sure how the information is useful, feel free to post a screenshot of your console.
Lua:
local creatureName = "cave rat"
local newCreature = "rat"
local creatureSay = "I am saying something"

function onKill(cid, target, damage, flags)
    print("Script starting..")
    if isPlayer(target) then
        print("Script ended. Target killed was a player.")
        return false
    end
 
    local name = getCreatureName(target):lower()
    print("targets name: " .. name .. " | checking against: " .. creatureName .. "")
    if name ~= creatureName:lower() then
        print("Script ended. targets name does not match intended criteria.")
        return false
    end
 
    local position = getCreaturePosition(target)
    print("targets position: {x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z .. "}")
    print("placing orange text '" .. creatureSay .. "' at targets position.")
    doCreatureSay(cid, creatureSay, TALKTYPE_ORANGE_1, false, 0, position)
    print("creating monster " .. newCreature .. " at targets position")
    addEvent(doCreateMonster, 0, newCreature, position)
    print("Script ended. Monster should spawn directly after this message appears in console.")
    return true
end

You already helped me. I was registering the onDeath on the login.lua, that caused the monster to spawn when players died. I fixed it by removing the login.lua part and removing the script part on the monster.xml.

I did try to use the onKill, login out and then back in helped. However this happend:

XM6UVxE.jpg


And:
Code:
targets name: rat | checking against: cave rat
Script ended. targets name does not match intended criteria.
 
You already helped me. I was registering the onDeath on the login.lua, that caused the monster to spawn when players died. I fixed it by removing the login.lua part and removing the script part on the monster.xml.

I did try to use the onKill, login out and then back in helped. However this happend:

XM6UVxE.jpg


And:
Code:
targets name: rat | checking against: cave rat
Script ended. targets name does not match intended criteria.
Got it.
change both return false's to return true's.
 
I have this one and its working for me

Lua:
function onDeath(cid, corpse, deathList, pos)
local monstName = "Bones" -- NAME OF MONSTER TO SUMMON
local text = "Vengance!"
if isMonster(cid) then
      doSummonCreature (monstName, getCreaturePosition(cid))
      doSendAnimatedText (getCreaturePosition(cid), text, 215)
end
return TRUE
end
xml creaturescripts

XML:
<event type="death" name="xname" event="script" value="script.lua"/>
dont forget to add the event to monster

----------------EDIT-----------------------
remove the line 5 or add the at the < > xd
 
I have this one and its working for me

Lua:
function onDeath(cid, corpse, deathList, pos)
local monstName = "Bones" -- NAME OF MONSTER TO SUMMON
local text = "Vengance!"
if isMonster(cid) then
      doSummonCreature (monstName, getCreaturePosition(cid))
      doSendAnimatedText (getCreaturePosition(cid), text, 215)
end
return TRUE
end
xml creaturescripts

XML:
<event type="death" name="xname" event="script" value="script.lua"/>
dont forget to add the event to monster

----------------EDIT-----------------------

remove the line 5 or add the at the < > xd
Wouldn't this summon infinite monsters basically? lol
Everytime a monster dies with this script attached, a monster would spawn.

I guess just make sure only your intended monsters have it installed and it'd be fine.
xP
 
Wouldn't this summon infinite monsters basically? lol
Everytime a monster dies with this script attached, a monster would spawn.

I guess just make sure only your intended monsters have it installed and it'd be fine.
xP
It would, I suggest to register the event explicitly into unique monster.
 
it "works" except it won't in a real situation with multiple players
as i said, use onDeath instead of onKill because it will spawn a monster for each person that hits the monster and kills it.
use onDeath params and register it to the monster's xml file with:
XML:
<script>
    <event name="xxx"/>
</script>
do not register it to login.lua because that would register the death script to all players and that's not what you need
 
Back
Top Bottom