• 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 Solo Desert Quest [code optimize]

Dibis

Member
Joined
Dec 1, 2022
Messages
73
Reaction score
16
Location
POLAND
Hello. I use TFS 0.3.7 [based on OTX2]
Who Can optimized for me desert quest [solo] ?
This is my code.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)   

        local storageValue = 61111 -- only if status is false this will be used

        local sorcerer = {1,5}
        local itemId1 = 2175
        local druid = {2,6}
        local itemId2 = 2674
        local paladin = {3,7}
        local itemId3 = 2455
        local knight = {4,8}
        local itemId4 = 2376
    
        local newPos = {x = 1835, y = 1143, z = 8} -- Position of the reward room.
        local itemPos = {x=1827,y=1133,z=9,stackpos=2} -- Position of Spellbook "Sorcerer".
        local stackpos = {2,3,4,5,6,7,8,9,10}
        local pos = {x = 1827, y = 1134, z = 9}
        
             if getPlayerVocation(cid) == 1 or 5 and getItemCountFromPosition(itemId1, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId1).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)

            else if getPlayerVocation(cid) == 2 or 6 and getItemCountFromPosition(itemId2, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId2).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)   
            
            else if getPlayerVocation(cid) == 3 or 7 and getItemCountFromPosition(itemId3, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId3).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)                   

            else if getPlayerVocation(cid) == 4 or 8 and getItemCountFromPosition(itemId4, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId4).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)                           
                else
                doCreatureSay(cid, "You don't have items for your vocation or you don't have 20 level!", TALKTYPE_ORANGE_1, false, cid, pos)
                return TRUE       
                end
                end
                end
                end
                    end
 
Hello. I use TFS 0.3.7 [based on OTX2]
Who Can optimized for me desert quest [solo] ?
This is my code.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition) 

        local storageValue = 61111 -- only if status is false this will be used

        local sorcerer = {1,5}
        local itemId1 = 2175
        local druid = {2,6}
        local itemId2 = 2674
        local paladin = {3,7}
        local itemId3 = 2455
        local knight = {4,8}
        local itemId4 = 2376
  
        local newPos = {x = 1835, y = 1143, z = 8} -- Position of the reward room.
        local itemPos = {x=1827,y=1133,z=9,stackpos=2} -- Position of Spellbook "Sorcerer".
        local stackpos = {2,3,4,5,6,7,8,9,10}
        local pos = {x = 1827, y = 1134, z = 9}
      
             if getPlayerVocation(cid) == 1 or 5 and getItemCountFromPosition(itemId1, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId1).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)

            else if getPlayerVocation(cid) == 2 or 6 and getItemCountFromPosition(itemId2, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId2).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos) 
          
            else if getPlayerVocation(cid) == 3 or 7 and getItemCountFromPosition(itemId3, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId3).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)                 

            else if getPlayerVocation(cid) == 4 or 8 and getItemCountFromPosition(itemId4, itemPos) == 1 then
                    doRemoveItem(getTileItemById(itemPos,itemId4).uid,1)
                    doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
                    setPlayerStorageValue(cid, storageValue, 1)
                    doTeleportThing(cid, newPos)
                    doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)                         
                else
                doCreatureSay(cid, "You don't have items for your vocation or you don't have 20 level!", TALKTYPE_ORANGE_1, false, cid, pos)
                return TRUE     
                end
                end
                end
                end
                    end
you could use tables instead
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local vocations = {
        [1] = {itemId = 2175, vocation = {1, 5}},
        [2] = {itemId = 2674, vocation = {2, 6}},
        [3] = {itemId = 2455, vocation = {3, 7}},
        [4] = {itemId = 2376, vocation = {4, 8}},
    }

    local storageValue = 61111
    local newPos = {x = 1835, y = 1143, z = 8}
    local itemPos = {x = 1827, y = 1133, z = 9, stackpos = 2}
    local pos = {x = 1827, y = 1134, z = 9}

    for i, v in ipairs(vocations) do
        if isInArray(v.vocation, getPlayerVocation(cid)) and getPlayerItemCount(cid, v.itemId) > 0 then
            doRemoveItem(getTileItemById(itemPos, v.itemId).uid, 1)
            doSendMagicEffect(itemPos, CONST_ME_HITBYFIRE)
            setPlayerStorageValue(cid, storageValue, 1)
            doTeleportThing(cid, newPos)
            doCreatureSay(cid, "Done! Reward Desert Room.", TALKTYPE_ORANGE_1, false, cid, pos)
            return true
        end
    end
    doCreatureSay(cid, "You don't have items for your vocation or you don't have 20 level!", TALKTYPE_ORANGE_1, false, cid, pos)
end
 
Back
Top