• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

When player will kill monster, server is creating teleport [TFS 1.0]

  • Thread starter Thread starter tejdi
  • Start date Start date
T

tejdi

Guest
Hello
I've got script:

Code:
local config = {
   ["minotaurus"] = {time = 60, toPos = {x = 1214, y = 1026, z = 7}, tpPos = {x = 1117, y = 955, z = 3}},
   ["bazir"] = {time = 60, toPos = {x = 100, y = 100, z = 7}, tpPos = {x = 100, y = 100, z = 7}}
}

local function removeTeleport(pos)
   local teleport = getTileItemById(pos, 1387).uid
   if(teleport > 0) then
      doRemoveItem(teleport)
      doSendMagicEffect(pos, CONST_ME_POFF)
   end
   return true
end

function onKill(cid, target)
   local monster = config[getCreatureName(target):lower()]

   if(isPlayer(target) or not monster) then
      return true
   end
   doCreateTeleport(1387, monster.toPos, monster.tpPos)
   doCreatureSay(cid, "You have "..monster.time.." seconds to enter the teleport!", TALKTYPE_ORANGE_1)
   addEvent(removeTeleport, monster.time * 1000, monster.tpPos)
   return true
end
Code:
    <event type="kill" name="minotaurus" event="script" value="test/minotaurus.lua"/>
and in login.lia
Code:
    registerCreatureEvent(cid, "minotaurus")

It doesn't work.
I haven't any errors in console too.


Code:
[ADDITIONAL INFO]
Monster: Minotaurus
Teleport To Pos: x = 1214, y = 1026, z = 7
Teleport Pos: x = 1117, y = 955, z = 3
Time to remove teleport: 60 sec [one min]
 
I killed minotaurus, teleport is not created, any errors:
Code:
local config = {
    ["minotaurus"] = {time = 60, toPos = Position(1214, 1026, 7), tpPos = Position(1117, 955, 3)}
}

local function deleteTeleport(position)
    local teleport = Tile(position):getItemById(1387)
    if teleport then
        teleport:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    local monster = config[target:getName():lower()]
    if not monster or target:isPlayer() then
        return true
    end

    local item = Game.createItem(1387, 1, monster.tpPos)
    if item:isTeleport() then
        item:setDestination(monster.toPos)
    end

    creature:say("You have " .. monster.time .. " seconds to enter the teleport!", TALKTYPE_MONSTER_SAY)
    addEvent(deleteTeleport, monster.time * 1000, monster.tpPos)
    return true
end
 
Change
Code:
<event type="kill" name="minotaurus" event="script" value="test/minotaurus.lua"/>
To
Code:
<event type="kill" name="minotaurus" script="test/minotaurus.lua"/>

If you have the compat.lua you can use the TFS 0.2 version of the script in TFS 1.0.
 
Make sure you have this in login.lua.
Code:
player:registerEvent("minotaurus")
And the script is in the right folder (folder test).

Which script are you using atm, the TFS 0.2 version or the edited TFS 1.1 version?
 
Last edited:
@Limos My login.lua:
Code:
function onLogin(cid)
    local player = Player(cid)

    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    player:registerEvent("PlayerDeath")
    registerCreatureEvent(cid, "minotaurus")
    player:registerEvent("Management")
    registerCreatureEvent(cid, "freebless")
    return true
end

I'm using this script:
Code:
local config = {
["minotaurus"] = {time = 60, toPos = Position(1214, 1026, 7), tpPos = Position(1117, 955, 3)}
}

local function deleteTeleport(position)
local teleport = Tile(position):getItemById(1387)
if teleport then
teleport:remove()
position:sendMagicEffect(CONST_ME_POFF)
end
end

function onKill(creature, target)
local monster = config[target:getName():lower()]
if not monster or target:isPlayer() then
return true
end

local item = Game.createItem(1387, 1, monster.tpPos)
if item:isTeleport() then
item:setDestination(monster.toPos)
end

creature:say("You have " .. monster.time .. " seconds to enter the teleport!", TALKTYPE_MONSTER_SAY)
addEvent(deleteTeleport, monster.time * 1000, monster.tpPos)
return true
end

And minotaurus.lua place:
Code:
C:\Users\Mateusz\Desktop\ots\data\creaturescripts\scripts\test
 
If you're going to use the version for TFS 1.1, you have to edit it to make it work for TFS 1.0.
The parameter in function onKill is creature userdata in TFS 1.1, in TFS 1.0 it's a creatureid.

The TFS 0.2 version already works in TFS 1.0 with the compat.lua, but you can change the TFS 0.2 functions to TFS 1.0 functions using compat.lua as example to make it faster.
 
Replace the function onKill with this
Code:
function onKill(cid, target)
    local targetMonster = Monster(target)
    if not targetMonster then
        return true
    end

    local targetName = config[targetMonster:getName():lower()]
    if not targetName then
        return true
    end

    local item = Game.createItem(1387, 1, targetName.tpPos)
    if item:isTeleport() then
        item:setDestination(targetName.toPos)
    end

    Player(cid):say("You have " .. targetName.time .. " seconds to enter the teleport!", TALKTYPE_MONSTER_SAY)
    addEvent(deleteTeleport, targetName.time * 1000, targetName.tpPos)
    return true
end
 
Holy, wtf is wrong with me xDD

@Ninja i changed, still nothing.

All of files:
creaturescripts.xml
Code:
    <event type="kill" name="minotaurus" script="test/minotaurus.lua"/>

login.lua
Code:
    registerCreatureEvent(cid, "minotaurus")

test/minotaurus.lua
Code:
local config = {
    ["minotaurus"] = {time = 60, toPos = Position(1214, 1026, 7), tpPos = Position(1117, 955, 3)}
}

local function deleteTeleport(position)
    local teleport = Tile(position):getItemById(1387)
    if teleport then
        teleport:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(cid, target)
    local targetMonster = Monster(target)
    if not targetMonster then
        return true
    end

    local targetName = config[targetMonster:getName():lower()]
    if not targetName then
        return true
    end

    local item = Game.createItem(1387, 1, targetName.tpPos)
    if item:isTeleport() then
        item:setDestination(targetName.toPos)
    end

    Player(cid):say("You have " .. targetName.time .. " seconds to enter the teleport!", TALKTYPE_MONSTER_SAY)
    addEvent(deleteTeleport, targetName.time * 1000, targetName.tpPos)
    return true
end

compat.lua:
http://wklej.to/XJN8S
 
Back
Top