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

Problem with quest system after add two language in game

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i was try add two language PL and ENG, but i have problem with quest system, what's wrong with it?

Now if im using english version i can use chest only one time, and next time i see "Empty.", but when im using polish version i see "Empty." and i got reward everytime when im using chest, no limit

Where i make fault?


Code:
function capAll(str)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end

local advanceChest = Action()

function advanceChest.onUse(player, item, fromPosition, itemEx, toPosition)
   -----------------------------------------------------------------------------------
   -- Local Variables --
   -----------------------------------------------------------------------------------
   local questChest = item:getUniqueId()
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(questChest) == 1 then
        if player:getStorageValue(language_storage) == 0 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
            toPosition:sendMagicEffect(10)
        elseif player:getStorageValue(language_storage) == 1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
            toPosition:sendMagicEffect(10)
       return true
   end
end
 
   local storageOne = questChests[questChest].storageUnique
   -----------------------------------------------------------------------------------
   -- Check if player has already opened box multiple chest only 1 reward --
   -----------------------------------------------------------------------------------
   if player:getStorageValue(storageOne) == 1 then
        if player:getStorageValue(language_storage) == 0 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
            toPosition:sendMagicEffect(10)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
            toPosition:sendMagicEffect(10)
       return true
   end
end
 
   -----------------------------------------------------------------------------------
   -- Check if player meets level requirment
   -----------------------------------------------------------------------------------
   local playerLevel = player:getLevel()
   local minLevel = questChests[questChest].minLevel
   if questChests[questChest].minLevel >= playerLevel then
        if player:getStorageValue(language_storage) == 0 then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Aby otworzyc ta skrzynie musisz miec "..minLevel.." poziom.")
       else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level "..minLevel.." to open this chest.")
       return true
   end
   end
   -----------------------------------------------------------------------------------
 
   -- Give rewward if player has not yet opened box --
 
   -----------------------------------------------------------------------------------
   for i = 1, #questChests[questChest].items do
       local rewardType = questChests[questChest].items[i].type
       -----------------------------------------------------------------------------------
       -- Item Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "item" then
           local item = questChests[questChest].items[i].item
           local count = questChests[questChest].items[i].count
           if player:getStorageValue(language_storage) == 0 then
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Otrzymales ["..count.."x] "..capAll(getItemName(item)))
                   player:addItem(item, count)
           elseif player:getStorageValue(language_storage) == 1 then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You earned ["..count.."x] "..capAll(getItemName(item)))
                    player:addItem(item, count)
        end
       end
       -----------------------------------------------------------------------------------
       -- Experience Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "experience" then
           local amount = questChests[questChest].items[i].amount
           player:addExperience(amount)
           player:say(amount.." EXP gained!", TALKTYPE_MONSTER_SAY)
           player:getPosition():sendMagicEffect(CONST_ME_STUN)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained "..amount.." experience points.")
       end
       -----------------------------------------------------------------------------------
       -- Outfit Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "outfit" then
           local outfitName = questChests[questChest].items[i].name
           local maleOutfit = questChests[questChest].items[i].maleId
           local femaleOutfit = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfit(femaleOutfit)
           else
               player:addOutfit(maleOutfit)
           end
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the "..outfitName.." outfit.")
       end
       -----------------------------------------------------------------------------------
       -- Addon Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "addon" then
           local outfitName = questChests[questChest].items[i].outfit
           local addon = questChests[questChest].items[i].addonNumber
           local maleAddon = questChests[questChest].items[i].maleId
           local femaleAddon = questChests[questChest].items[i].femaleId
           if player:getSex() == 0 then
               player:addOutfitAddon(femaleAddon, addon)
           else
               player:addOutfitAddon(maleAddon, addon)
           end
           if addon == 1 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the first "..outfitName.." outfit addon.")
           elseif addon == 2 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the second "..outfitName.." outfit addon.")
           elseif addon == 3 then
               player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You gained the third "..outfitName.." outfit addon.")
           end
       end
       -----------------------------------------------------------------------------------
       -- Mount Type Reward --
       -----------------------------------------------------------------------------------
       if rewardType == "mount" then
           local mountName = questChests[questChest].items[i].mountName
           local mountId = questChests[questChest].items[i].mountId
           player:addMount(mountId)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have unlocked the "..mountName.." mount.")
       end

            
 
 
   -----------------------------------------------------------------------------------
   -- Add in any cooldowns/storages --
   -----------------------------------------------------------------------------------
   player:setStorageValue(questChest, 1)
   player:setStorageValue(storageOne, 1)
   return true
end
end

for i = 2000, 2100 do
    advanceChest:uid(i)
end

advanceChest:register()
 
Solution
if player:getStorageValue(questChest) == 1 then
if player:getStorageValue(language_storage) == 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
toPosition:sendMagicEffect(10)
elseif player:getStorageValue(language_storage) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
toPosition:sendMagicEffect(10)
return true
end
end

if player:getStorageValue(questChest) == 1 then
if player:getStorageValue(language_storage) == 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
toPosition:sendMagicEffect(10)
elseif player:getStorageValue(language_storage) == 1 then...
if player:getStorageValue(questChest) == 1 then
if player:getStorageValue(language_storage) == 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
toPosition:sendMagicEffect(10)
elseif player:getStorageValue(language_storage) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
toPosition:sendMagicEffect(10)
return true
end
end

if player:getStorageValue(questChest) == 1 then
if player:getStorageValue(language_storage) == 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
toPosition:sendMagicEffect(10)
elseif player:getStorageValue(language_storage) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
toPosition:sendMagicEffect(10)
end
return true
end
 
Solution
@vexler222
You should use some IDE to edit .lua files (IDEA CE or VisualCode). They have auto code formatting.
If you prefer to use text editor, you can use Lua Beautifier - Best Lua Beautifier (https://goonlinetools.com/lua-beautifier/) to format code.

Your code before formatting:
Lua:
   if player:getStorageValue(storageOne) == 1 then
        if player:getStorageValue(language_storage) == 0 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
            toPosition:sendMagicEffect(10)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
            toPosition:sendMagicEffect(10)
       return true
   end
end

Your code after formatting:
Lua:
if player:getStorageValue(storageOne) == 1 then
    if player:getStorageValue(language_storage) == 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
        toPosition:sendMagicEffect(10)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
        toPosition:sendMagicEffect(10)
        return true
    end
end
With proper indentation, it's much easier to find what is wrong with IFs.
 
Back
Top