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

Lua Monster disappear after a minute

Joined
Apr 11, 2015
Messages
87
Reaction score
5
0.4

Hello guys and good morning.
I was trying to do some simple scripts, but one of them i can't solve.
I want a script that, when the monster get created by doSummonCreature, it will disappear after a minute. I was trying to do by creaturescript and then use this in the monster.xml

<script>
<event name="event name"/>
</script>

But the script can't identify the monster it seems. I'm sure what I was doing was very wrong, so I will not post what I did here xD
If anyone can help me, i will be grateful.
Thanks
 
Solution
@Xikini Sure, its this one:
Lua:
function onKill(cid, target)
    local monsters = {
        ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
       
    }
    function doRemoveCorpse(pos, creature)
        for i = 0, 255 do
            pos.stackpos = i
            tile = getTileThingByPos(pos)
            if tile.uid > 0 and isCorpse(tile.uid) then
                doRemoveItem(tile.uid)
            end
        end
    doSummonCreature(creature, pos)  
    end
    if isPlayer(cid) and isMonster(target) then
        local var = monsters[getCreatureName(target)]
        if var then
            if var.chance >= math.random(1, 100) then...

mrianuraa

Member
Joined
Dec 5, 2019
Messages
48
Reaction score
15
0.4

Hello guys and good morning.
I was trying to do some simple scripts, but one of them i can't solve.
I want a script that, when the monster get created by doSummonCreature, it will disappear after a minute. I was trying to do by creaturescript and then use this in the monster.xml

<script>
<event name="event name"/>
</script>

But the script can't identify the monster it seems. I'm sure what I was doing was very wrong, so I will not post what I did here xD
If anyone can help me, i will be grateful.
Thanks
addEvent with minute delay and creatureID as an argument ?
 
OP
M
Joined
Apr 11, 2015
Messages
87
Reaction score
5
Yes, i tried to use something like this:

addEvent(doRemoveCreature, 6 * 1000, getCreatureByName("Orc"))

But i don't think my server recognizes getCreatureByName.
Can you give me an example?
 

mrianuraa

Member
Joined
Dec 5, 2019
Messages
48
Reaction score
15
And what if the player stack with the monster? 🤭

@Matheus Vieira
Don't you have the reference to the creature that is being summoned? It seems like an obvious choice.
Paste your logic that summons the monster, I have almost no experience with these outdated engines.
man, It was just and example how to get creature ID not a solutoin for this easy problem ...
 

4Nathu4

valoria.online
Joined
Oct 27, 2009
Messages
225
Solutions
8
Reaction score
126
GitHub
4mrcn4
man, It was just and example how to get creature ID not a solutoin for this easy problem ...
Hence you posted this flawed solution in this thread, why don't you guide him instead of suggesting something that is abusable?
 
Last edited:
OP
M
Joined
Apr 11, 2015
Messages
87
Reaction score
5
@4Nathu4 Ok, so I have a script here that, when the monster dies, it summons another one. If the player kills the monster and then the script summon another, the player can bring this monster anywhere, since it will not disappear.

Lua:
function onKill(cid, target)
    local monsters = {
        ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
        
    }
    function doRemoveCorpse(pos, creature)
        for i = 0, 255 do
            pos.stackpos = i
            tile = getTileThingByPos(pos)
            if tile.uid > 0 and isCorpse(tile.uid) then
                doRemoveItem(tile.uid)
            end
        end
    doSummonCreature(creature, pos)   
    end
    if isPlayer(cid) and isMonster(target) then
        local var = monsters[getCreatureName(target)]
        if var then
            if var.chance >= math.random(1, 100) then
                addEvent(doRemoveCorpse, 0, getThingPos(target), var.next)
                doCreatureSay(target, var.msg[math.random(1, #var.msg)], TALKTYPE_ORANGE_1)
            end
        end
    end
    return true
end
 

4Nathu4

valoria.online
Joined
Oct 27, 2009
Messages
225
Solutions
8
Reaction score
126
GitHub
4mrcn4
Lua:
local monsters = {
    ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
}

local function doRemoveCorpse(pos)
    for i = 0, 255 do
        pos.stackpos = i
        local thing = getTileThingByPos(pos)
        if thing.uid > 0 and isCorpse(thing.uid) then
            doRemoveItem(thing.uid)
            --break
        end
    end
end

function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        local monster = monsters[getCreatureName(target)]
        if monster then
            if monster.chance >= math.random(1, 100) then
                local summon = doSummonCreature(monster.next, pos)
                doRemoveCorpse(getThingPos(target))
                doCreatureSay(target, monster.msg[math.random(1, #monster.msg)], TALKTYPE_ORANGE_1)
                addEvent(doRemoveThing, 60*1000, summon.uid)
            end
        end
    end
    return true
end
Try with this, I'm not sure if doSummonCreature returns a reference in your engine, since i couldnt find it in otx's luascript.cpp
 
Last edited:
OP
M
Joined
Apr 11, 2015
Messages
87
Reaction score
5
@Xikini Sure, its this one:
Lua:
function onKill(cid, target)
    local monsters = {
        ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
        
    }
    function doRemoveCorpse(pos, creature)
        for i = 0, 255 do
            pos.stackpos = i
            tile = getTileThingByPos(pos)
            if tile.uid > 0 and isCorpse(tile.uid) then
                doRemoveItem(tile.uid)
            end
        end
    doSummonCreature(creature, pos)   
    end
    if isPlayer(cid) and isMonster(target) then
        local var = monsters[getCreatureName(target)]
        if var then
            if var.chance >= math.random(1, 100) then
                addEvent(doRemoveCorpse, 0, getThingPos(target), var.next)
                doCreatureSay(target, var.msg[math.random(1, #var.msg)], TALKTYPE_ORANGE_1)
            end
        end
    end
    return true
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
@Xikini Sure, its this one:
Lua:
function onKill(cid, target)
    local monsters = {
        ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
       
    }
    function doRemoveCorpse(pos, creature)
        for i = 0, 255 do
            pos.stackpos = i
            tile = getTileThingByPos(pos)
            if tile.uid > 0 and isCorpse(tile.uid) then
                doRemoveItem(tile.uid)
            end
        end
    doSummonCreature(creature, pos)  
    end
    if isPlayer(cid) and isMonster(target) then
        local var = monsters[getCreatureName(target)]
        if var then
            if var.chance >= math.random(1, 100) then
                addEvent(doRemoveCorpse, 0, getThingPos(target), var.next)
                doCreatureSay(target, var.msg[math.random(1, #var.msg)], TALKTYPE_ORANGE_1)
            end
        end
    end
    return true
end
Lua:
local monsters = {
    ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}    
}

local function removeCreature(cid)
    if isCreature(cid) then
        doRemoveCreature(cid)
    end
end

local function doRemoveCorpse(pos, creature)
    for i = 0, 255 do
        pos.stackpos = i
        tile = getTileThingByPos(pos)
        if tile.uid > 0 and isCorpse(tile.uid) then
            doRemoveItem(tile.uid)
        end
    end
    local summon = doSummonCreature(creature, pos)
    addEvent(removeCreature, 60000, summon) -- 60000 is 1 minute
end

function onKill(cid, target)
    if isPlayer(cid) and isMonster(target) then
        local var = monsters[getCreatureName(target)]
        if var then
            if var.chance >= math.random(1, 100) then
                addEvent(doRemoveCorpse, 0, getThingPos(target), var.next)
                doCreatureSay(target, var.msg[math.random(1, #var.msg)], TALKTYPE_ORANGE_1)
            end
        end
    end
    return true
end
 
Solution

4Nathu4

valoria.online
Joined
Oct 27, 2009
Messages
225
Solutions
8
Reaction score
126
GitHub
4mrcn4
Lua:
local monsters = {
    ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
}

local function doRemoveCorpse(pos, creature)
    for i = 0, 255 do
        pos.stackpos = i
        tile = getTileThingByPos(pos)
        if tile.uid > 0 and isCorpse(tile.uid) then
            doRemoveItem(tile.uid)
        end
    end
    local summon = doSummonCreature(creature, pos)
    addEvent(removeCreature, 60000, summon) -- 60000 is 1 minute
end
@Xikini You are passing creature argument, which is indeed a var.next to a doRemoveCorpse, in which it's accessible, and your logic is actually summoning and removing the creature.
Lua:
tile = getTileThingByPos(pos)
if tile.uid > 0 and isCorpse(tile.uid) then
    doRemoveItem(tile.uid)
end
also, that's not a tile (not a biggie) and it should be local (biggie)

Other than it's kinda messed up, it's exactly the same code that I edited - how came mine errored? These outdated engines are not my thing 🌴
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
Lua:
local monsters = {
    ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}}
}

local function doRemoveCorpse(pos, creature)
    for i = 0, 255 do
        pos.stackpos = i
        tile = getTileThingByPos(pos)
        if tile.uid > 0 and isCorpse(tile.uid) then
            doRemoveItem(tile.uid)
        end
    end
    local summon = doSummonCreature(creature, pos)
    addEvent(removeCreature, 60000, summon) -- 60000 is 1 minute
end
@Xikini You are passing creature argument, which is indeed a var.next to a doRemoveCorpse, in which it's accessible, and your logic is actually summoning and removing the creature.
Lua:
tile = getTileThingByPos(pos)
if tile.uid > 0 and isCorpse(tile.uid) then
    doRemoveItem(tile.uid)
end
also, that's not a tile (not a biggie) and it should be local (biggie)

Other than it's kinda messed up, it's exactly the same code that I edited - how came mine errored? These outdated engines are not my thing 🌴
Calm down lol.

I only added what op asked for. I didn't alter his original code, since that isn't what he wanted.

If we wanted to do this correctly, I'd simply make this an onDeath trigger, so we remove only the corpse of the summon, instead of all corpses on the tile.

regardless, you'd want to remove the corpses from the top down, instead of the bottom up, since you'd miss a few items the way it's currently setup.
--
I didn't have the time earlier to read through the entire thread and was face palming because it was an easy request, yet there was already 10+ replies.

The issue with your script is fairly simple to correct though.
You have doSummonCreature(pos, monster.next)
Which should be doSummonCreature(monster.next, pos)

which doesn't throw an error for not summoning, but your addEvent which relied upon that creature summoning error'd instead.
addEvent(doRemoveThing, 60*1000, summon.uid)

Without testing, I'm fairly certain the scripts reads it like this.. summon.uid.uid because of old tfs logic.
So it's kind of a 3-fold issue.

Summon didn't spawn, so can't find it.
If summon did spawn, it can't find it, because of the uid.uid issue
and if the summon died before the addEvent went off, it'd throw an error because the summon no longer exists.

--
Anyway, here's the updated code based on how I'd do it.
Lua:
local monsters = {
    ["Orc"] = {chance = 5, next = "Orc2", msg = {"Test"}, removalDelay = 60000}
}

local function removeCreature(cid)
    if isCreature(cid) then
        doRemoveCreature(cid)
    end
end

local function createTemporaryMonster(creatureName, position, removalDelay)
    removalDelay = removalDelay or 60000 -- default to 60 seconds
    local monster = doCreateMonster(creatureName, position)
    addEvent(removeCreature, removalDelay, monster)
end

function onDeath(cid, corpse, deathList)
    local monsterIndex = monsters[getCreatureName(cid)]
    if monsterIndex then
        if monsterIndex.chance <= math.random(100) then
            local position = getThingPosition(cid)
            addEvent(createTemporaryMonster, 0, monsterIndex.next, position, monsterIndex.removalDelay) -- require a nominal delay, so that creature can fully die and newly spawned creature takes it's place
            doRemoveItem(corpse.uid) -- uid is required here, since it's an item.
            doCreatureSay(cid, monsterIndex.msg[math.random(#monsterIndex.msg)], TALKTYPE_ORANGE_1)
        end
    end
    return true
end
 

4Nathu4

valoria.online
Joined
Oct 27, 2009
Messages
225
Solutions
8
Reaction score
126
GitHub
4mrcn4
Calm down lol
You are the one losing temper here, mate.
If we wanted to do this correctly,
I'm pretty sure he did, but he didn't know better

New script
Aaand that's the way I like it.
There were very low-hanging fruits there, even without a complete overhaul - and I didn't try to be mean - but if you post scripts like the first one, be ready to face the critique, as far as I can tell it was pretty constructive.

Like I mentioned in my previous post, I wasn't able to find the method that the OP used (i never used an outdated engine and I wasn't around when they were a thing) and must have overseen the order of the arguments, thanks for your explanation :)
 
Last edited:
Top