• 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 Script conversion, not going so well...

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
Converting a script from a prior release to 1.2. Switch throws no errors in console. However, it does display
13zn19z.png
regardless of level.
Any suggestions?

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local storage = 15001
waittime = 10 * 60 -- 10 minutes


demon1pos = {x=1119, y=994, z=10} 

if item.uid == 15102 then 
    if item.itemid == 1946 then
playerpos = getPlayerPosition(cid)
player = getThingfromPos(playerpos) 
nplayerpos = {x=1107, y=994, z=10}
         -- check if player has required level.
          if player:getLevel() >= 60 then
          end

                if player:getStorageValue(storage) == 0 then
                    doTeleportThing(player.uid,nplayerpos)
                    doSendMagicEffect(nplayerpos, CONST_ME_FIREWORK_RED)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")

                    demon1 = doSummonCreature("Stormblast", demon1pos)
                    item:transform(1945)
                    nexttime = os.time()+ waittime
                    addEvent(doRemoveCreature, 600 * 1000, demon1) --  remove time in seconds
                  
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You Have Already Completed The Catacombs Quest.")
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")

            end
        else
                 doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
        end
    if item.itemid == 1946 then
        if os.time() >= nexttime then
            item:transform(1946)
            
        else
            waittime = nexttime - os.time()
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waittime.. " seconds.")
        end
    end
return true
end
 
Cause:
END on line 16 terminating the level 60 check immediately:

if player:getLevel() >= 60 then
end


Move it to line 45 instead.
Or just copy this:


Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local storage = 15001
    local waittime = 10 * 60 -- 10 minutes
    local demon1pos = {x=1119, y=994, z=10}

    if item.uid == 15102 then
        if item.itemid == 1946 then
            playerpos = getPlayerPosition(cid)
            player = getThingfromPos(playerpos)
            nplayerpos = {x=1107, y=994, z=10}
            -- check if player has required level.
            if player:getLevel() >= 60 then
                if player:getStorageValue(storage) == 0 then
                    doTeleportThing(player.uid,nplayerpos)
                    doSendMagicEffect(nplayerpos, CONST_ME_FIREWORK_RED)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
                    demon1 = doSummonCreature("Stormblast", demon1pos)
                    item:transform(1945)
                    nexttime = os.time()+ waittime
                    addEvent(doRemoveCreature, 600 * 1000, demon1) --  remove time in seconds
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You Have Already Completed The Catacombs Quest.")
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
            end
        else
         doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
        end
       
        if item.itemid == 1946 then
            if os.time() >= nexttime then
                item:transform(1946)
            else
                waittime = nexttime - os.time()
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waittime.. " seconds.")
            end
        end
    end
    return true
end
 
Last edited:
This is where proper tabbing comes into play.
Here's what your code looks like right now, after tabbing it correctly.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

   local storage = 15001
   waittime = 10 * 60 -- 10 minutes  
  
   demon1pos = {x=1119, y=994, z=10}

   if item.uid == 15102 then
     if item.itemid == 1946 then
     playerpos = getPlayerPosition(cid)
     player = getThingfromPos(playerpos)
     nplayerpos = {x=1107, y=994, z=10}
       -- check if player has required level.
       if player:getLevel() >= 60 then
       end
    
       if player:getStorageValue(storage) == 0 then
         doTeleportThing(player.uid,nplayerpos)
         doSendMagicEffect(nplayerpos, CONST_ME_FIREWORK_RED)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
    
         demon1 = doSummonCreature("Stormblast", demon1pos)
         item:transform(1945)
         nexttime = os.time()+ waittime
         addEvent(doRemoveCreature, 600 * 1000, demon1) --  remove time in seconds
          
       else
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You Have Already Completed The Catacombs Quest.")
       end
     else
       player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
     end
   else
     doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
   end
  
   if item.itemid == 1946 then
     if os.time() >= nexttime then
       item:transform(1946)  
     else
       waittime = nexttime - os.time()
       player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waittime.. " seconds.")
     end
   end
   return true
end
As you can see, the message is being generated somewhere other then the correct place.

After some looking into it, I believe I have fixed the script back the way it was originally intended.
Note that a player can currently use this switch indefinitely to summon the monster, as it never add's anything to the quest storage after using the switch.
Unsure if that is intentional or not.
There was also a bug in the script that would effectively make the lever never be able to switched back to the correct position.
I fixed that while I was at it.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

     local storage = 15001
     waittime = 10 * 60 -- 10 minutes   
     
     demon1pos = {x=1119, y=994, z=10}
   
     if item.uid == 15102 then
         if item.itemid == 1946 then
             playerpos = getPlayerPosition(cid)
             player = getThingfromPos(playerpos)
             nplayerpos = {x=1107, y=994, z=10}
             -- check if player has required level.
             if player:getLevel() >= 60 then
                 if player:getStorageValue(storage) == 0 then
                     doTeleportThing(player.uid,nplayerpos)
                     doSendMagicEffect(nplayerpos, CONST_ME_FIREWORK_RED)
                     player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
                     demon1 = doSummonCreature("Stormblast", demon1pos)
                     item:transform(1945)
                     nexttime = os.time()+ waittime
                     addEvent(doRemoveCreature, 600 * 1000, demon1) --  remove time in seconds
                 else
                     player:sendTextMessage(MESSAGE_INFO_DESCR, "You Have Already Completed The Catacombs Quest.")
                 end
             else
                 player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
             end
         elseif item.itemid == 1945 then
             if os.time() >= nexttime then
                 item:transform(1946)   
             else
                 waittime = nexttime - os.time()
                 player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waittime.. " seconds.")
             end
         end
     else
         doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
     end
     return true
end
 
It is intended for not setting the storage on pulling switch. Only after completion of the quest at hand do you receive the storage. However, I receive this error onUse:
Code:
data/actions/scripts/custom/Stormblast Summon_switch.lua:onUse
data/actions/scripts/custom/Stormblast Summon_switch.lua:30: attempt to compare
nil with number
stack traceback:
        [C]: in function '__le'
        data/actions/scripts/custom/Stormblast Summon_switch.lua:30: in function
<data/actions/scripts/custom/Stormblast Summon_switch.lua:1>


No errors on console, switch is not useable.
Cause:
END on line 16 terminating the level 60 check immediately:

if player:getLevel() >= 60 then
end


Move it to line 45 instead.
 
Last edited:
I cleanup your code abit and added the new "TFS 1.X" functions and a config table instead of locals inside the onUse function.

Code:
local config = {
    storage = 15001,
    waitTime = 10 * 60,
    monsterPos = Position(1119, 994, 10),
    monsterName = "Stormblast",
    playerPos = Position(1107, 994, 10)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid == 15102 then
        if item.itemid == 1946 then
            if player:getLevel() >= 60 then -- check if player has required level.
                if player:getStorageValue(config.storage) == 0 then
                    if os.time() >= nextTime then
                        player:teleportTo(config.playerPos, false)
                        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
                        monster = Game.createMonster(config.monsterName, config.monsterPos)
                        item:transform(1945)
                        nextTime = os.time() + config.waitTime
                        addEvent(doRemoveCreature, 600 * 1000, monster) --  remove time in seconds
                    else
                        waitTime = nextTime - os.time()
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waitTime.. " more seconds.")
                    end
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
            end
        elseif item.itemid == 1945 then
            item:transform(1946)
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
        return true
    end
    return true
end
 
Last edited:
I cleanup your code abit and added the new "TFS 1.X" functions and a config table instead of locals inside the onUse function.

Code:
local config = {
    storage = 15001,
    waitTime = 10 * 60,
    monsterPos = Position(1119, 994, 10),
    monsterName = "Stormblast",
    playerPos = Position(1107, 994, 10)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid == 15102 then
        if item.itemid == 1946 then
            if player:getLevel() >= 60 then -- check if player has required level.
                if player:getStorageValue(config.storage) == 0 then
                    if os.time() >= nextTime then
                        player:teleportTo(config.playerPos, false)
                        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
                        monster = doSummonCreature(config.monsterName, config.monsterPos)
                        item:transform(1945)
                        nextTime = os.time() + config.waitTime
                        addEvent(doRemoveCreature, 600 * 1000, monster) --  remove time in seconds
                    else
                        waitTime = nextTime - os.time()
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waitTime.. " more seconds.")
                    end
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
            end
        else
            item:transform(1946)
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
        return true
    end
    return true
end

the switch triggers, but the player is not teleported/creature not summoned.
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/Stormblast Summon_switch.lua:onUse
data/actions/scripts/custom/Stormblast Summon_switch.lua:13: attempt to compare
nil with number
stack traceback:
        [C]: in function '__le'
        data/actions/scripts/custom/Stormblast Summon_switch.lua:13: in function
<data/actions/scripts/custom/Stormblast Summon_switch.lua:8>
 
Last edited:
Well, great job everyone. But i would done something like this. With the cleaning part and coding part:

Code:
local config = {
    reqLevel = 60,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1119, 994, 10),
    monsterName = "Stormblast",
    removeMonsterTime = 60,
    playerDestination = Position(1107, 994, 10)
}

local nextTime = 0
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
        if item.uid ~= 15102 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
            return true
        end

        if player:getLevel() < config.reqLevel then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level ".. config.reqLevel ..".")
            return true
        end

        if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
            return true
        end

        if os.time() <= nextTime then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait ".. os.time() - nextTime .." more seconds.")
            return true
        end

        local spawnMonster = Game.createMonster(config.monsterName, config.monsterSpawnPosition, false, true)
        if spawnMonster then
            addEvent(function(cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.removeMonsterTime * 1000, spawnMonster:getId())
        end
      
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
        nextTime = os.time() + config.waitTime
    end
  
    item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
I cleanup your code abit and added the new "TFS 1.X" functions and a config table instead of locals inside the onUse function.

Code:
local config = {
    storage = 15001,
    waitTime = 10 * 60,
    monsterPos = Position(1119, 994, 10),
    monsterName = "Stormblast",
    playerPos = Position(1107, 994, 10)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.uid == 15102 then
        if item.itemid == 1946 then
            if player:getLevel() >= 60 then -- check if player has required level.
                if player:getStorageValue(config.storage) == 0 then
                    if os.time() >= nextTime then
                        player:teleportTo(config.playerPos, false)
                        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
                        monster = Game.createMonster(config.monsterName, config.monsterPos)
                        item:transform(1945)
                        nextTime = os.time() + config.waitTime
                        addEvent(doRemoveCreature, 600 * 1000, monster) --  remove time in seconds
                    else
                        waitTime = nextTime - os.time()
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait " ..waitTime.. " more seconds.")
                    end
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level 60.")
            end
        elseif item.itemid == 1945 then
            item:transform(1946)
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
        return true
    end
    return true
end
u use the storage for what? if u r not checking it later, also it should be (x < 1) where x is storage, is just my opinion
 
u use the storage for what? if u r not checking it later, also it should be (x < 1) where x is storage, is just my opinion
That is correct, thats why i putted 1. Since i think, he got onKill code that sets the storage when the monster die.
 
Back
Top