• 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 Killing boss to create teleport.

slavi

#define SLAVI32 _WIN32
Senator
Joined
Sep 9, 2015
Messages
681
Solutions
11
Reaction score
560
GitHub
slavidodo
Hello, I am facing a strange problem.
I made this script to create a teleport somewhere when the boss is died in a range.
The Problem : It's working for one of them and not working on other.
Code:
local questsMonsters =
{
    ["demon lord"] = {start_pos=Position(1202, 3272, 7), end_pos=Position(1212, 3282, 7), tpitem, actionid=25001, tp_pos=Position(1204, 3275, 7), interval=30000},
    ["demon lord"] = {start_pos=Position(7665, 9280, 0), end_pos=Position(7698, 9304, 0), tpitem, actionid=25005, tp_pos=Position(7678, 9296, 0), interval=120000},
}
local f
function onKill(cid, target)
    local player = Player(cid)
    if questsMonsters[target:getName():lower()] then
        local m = questsMonsters[target:getName():lower()]
        if(inRangeOfPos(m.start_pos, player:getPosition(), m.end_pos)) then
            player:say("Teleport has been created, it will be removed after "..(m.interval/1000).." seconds. So go enter it fast", TALKTYPE_MONSTER_SAY, false, player, player:getPosition())
            m.tpitem = Game.createItem(5023, 1, m.tp_pos)
            m.tpitem:setActionId(m.actionid)
            f = m
            addEvent(removeteleport, m.interval)
        end
  
    end
    return true
end

function removeteleport()
    f.tpitem:remove()
end

I think the problem is that because there is two duplicated items in table but I don't know how to fix.
It must be the same monster in 2 places.
Hope you help me.
 
Last edited:
second key overrides the first one.

Just put the values inside table into another table.

And write each key value out in 1 line.. else it looks like a mess.

Code:
local questsMonsters = {
    ["demon lord"] = {
        start_pos = {
            Position(1202, 3272, 7),
            Position(7665, 9280, 0),
        },
        end_pos = {
            Position(1212, 3282, 7),
            Position(7698, 9304, 0),
        },
        tpitem = tpitem, -- ?? dafuck is that suppose to be. (you got something in global and its userdata? you nuts :D)
        actionid = {
            25001,
            25005,
        },
        tp_pos = {
            Position(1204, 3275, 7),
            Position(7678, 9296, 0),
        },
        interval = {
            30000,
            120000,
        },
    },
}
 
I will test it now , but that needs some edits, but thanks for the idea.
tpitem = tpitem, -- ?? dafuck is that suppose to be. (you got something in global?)
tpitem is defined now, because of two players are killing 2 different bosses at same time, someone of them will crash if they used same tpitem.
 
I will test it now , but that needs some edits, but thanks for the idea.

tpitem is defined now, because of two players are killing 2 different bosses at same time, someone of them will crash if they used same tpitem.
huh? It get different UID when its created.
 
In terms of script performance;
I remember when I was using 0.4 back in the days on my Quest OTs custom project, I was able to register creature events from the monster file.

Creaturescript.xml
XML:
<event type="think" name="monsterdeath" event="script" value="monsterdeath.lua"/>

monsterdeath.lua
Lua:
-- How many seconds shall monster stay alive?
seconds = 4

-- Do you want people to be able to loot monster
-- after it dies by this script? 0 = NO, 1 = YES.
loot = 0


function onThink(cid)
    addEvent(fuckmylife,1000*seconds, {cid=cid})
    return true
end
function fuckmylife(cid)
local cid = cid.cid
    if loot > 0 then
        if isCreature(cid) then
            doCreatureAddHealth(cid, -getCreatureHealth(cid))
        return true
        end
    else
        if isCreature(cid) then
            doRemoveCreature(cid)
        return true
        end
    end
    return true
end
(Old code, no idea why I used onThink for this beside bad coding [perhaps there was no onSpawn/Login for creatures back then]).

monster xml file:
XML:
<script>
    <event name="monsterdeath"/>
</script>

Isn't it possible to do something similar in TFS 1.x? That way you can create an onDeath creatureevent for boss monsters and the event will only trigger when actually needed. Instead of looping through a list of monster names on a players onKill event.
 
Last edited:
I remember when I was using 0.4 back in the days on my Quest OTs custom project, I was able to register creature events from the monster file.

Creaturescript.xml
XML:
<event type="think" name="monsterdeath" event="script" value="monsterdeath.lua"/>

monsterdeath.lua
Lua:
-- How many seconds shall monster stay alive?
seconds = 4

-- Do you want people to be able to loot monster
-- after it dies by this script? 0 = NO, 1 = YES.
loot = 0


function onThink(cid)
    addEvent(fuckmylife,1000*seconds, {cid=cid})
    return true
end
function fuckmylife(cid)
local cid = cid.cid
    if loot > 0 then
        if isCreature(cid) then
            doCreatureAddHealth(cid, -getCreatureHealth(cid))
        return true
        end
    else
        if isCreature(cid) then
            doRemoveCreature(cid)
        return true
        end
    end
    return true
end
(Old code, no idea why I used onThink for this beside bad coding [perhaps there was no onSpawn/Login for creatures back then]).

monster xml file:
XML:
<script>
    <event name="monsterdeath"/>
</script>

Isn't it possible to do something similar in TFS 1.x? That way you can create an onDeath creatureevent for boss monsters and the event will only trigger when actually needed.
Oh, that's far away from what i wanted , But nvm i solved it.
I had changed the way the code runes.
 
In terms of script performance;
I remember when I was using 0.4 back in the days on my Quest OTs custom project, I was able to register creature events from the monster file.

Creaturescript.xml
XML:
<event type="think" name="monsterdeath" event="script" value="monsterdeath.lua"/>

monsterdeath.lua
Lua:
-- How many seconds shall monster stay alive?
seconds = 4

-- Do you want people to be able to loot monster
-- after it dies by this script? 0 = NO, 1 = YES.
loot = 0


function onThink(cid)
    addEvent(fuckmylife,1000*seconds, {cid=cid})
    return true
end
function fuckmylife(cid)
local cid = cid.cid
    if loot > 0 then
        if isCreature(cid) then
            doCreatureAddHealth(cid, -getCreatureHealth(cid))
        return true
        end
    else
        if isCreature(cid) then
            doRemoveCreature(cid)
        return true
        end
    end
    return true
end
(Old code, no idea why I used onThink for this beside bad coding [perhaps there was no onSpawn/Login for creatures back then]).

monster xml file:
XML:
<script>
    <event name="monsterdeath"/>
</script>

Isn't it possible to do something similar in TFS 1.x? That way you can create an onDeath creatureevent for boss monsters and the event will only trigger when actually needed. Instead of looping through a list of monster names on a players onKill event.
looping through list of names is not required in both cases.
the first if question is: does this boss exists in table.
if table[bossName] then end
no loop required.
for side note: monster onKill can be triggered several times by same monster. onDeath however only once.

So you are right about moving the script to onDeath script.
 
Back
Top