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

RevScripts quest for vocations

Madusa

Active Member
Joined
Sep 8, 2022
Messages
142
Reaction score
45
Location
Egypt
I have this script and whenever I try to do quest it tells me
It is empty.
How can I solve this?
Lua:
local vocationItemIds = {
    [1] = {5917, 3968},  -- Sorcerer
    [5] = {5917, 3968},  -- Sorcerer
    
    [2] = {5917, 3968},  -- Druid
    [6] = {5917, 3968},  -- Druid

    [3] = {7901, 7898},  -- Paladin
    [7] = {7901, 7898},  -- Paladin

    [4] = {2506, 2492},  -- Knight
    [8] = {2506, 2492},  -- Knight
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getType():isContainer() then
        return true
    end

    local uniqueId = item:getUniqueId()
    if player:getStorageValue(uniqueId) ~= 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local vocation = player:getVocation():getBase()
    local vocationId = vocation:getId()

    local itemIds = vocationItemIds[vocationId]
    if itemIds then
        for _, itemId in ipairs(itemIds) do
            local get = item:getItem(itemId)
            if get then
                local weight = get:getWeight()
                if player:getFreeCapacity() < weight then
                    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You need %.2f weight.", weight / 100))
                    return true
                end

                local reward = get:clone()
                if player:addItemEx(reward) == RETURNVALUE_NOERROR then
                    player:setStorageValue(uniqueId, 1)
                    if reward:getType():isContainer() then
                        player:sendTextMessage(MESSAGE_INFO_DESCR, "You found: " .. reward:getContentDescription())
                    else
                        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You found: %d %s.", reward:getCount(), reward:getName()))
                    end
                else
                    reward:remove()
                    player:sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY)
                end
            end
        end
    end
    return true
end

action:aid(10107)
action:register()
 
Solution
So, I noticed this line 'local uniqueId = item:getUniqueId()' and another one at the end 'action:aid(10107)'. Would it be correct to use 'action:uid(10107)' instead of 'action:aid(10107)' Since 'uid' stands for uniqueId, while 'aid' stands for actionId.

If you defined uniqueID through RME, then using 'action:uid(10107)' should be correct. It should work.
It was a miscommuncation, that part had already been solved.

The issue was the storage wasn't being set, due to the rest of the code being weird (cloning items etc).
I helped him in private and rewrote/simplified it:

Lua:
local vocationItemIds = {
    [1] = {5917, 3968},  -- Sorcerer
    [5] = {5917, 3968},  -- Sorcerer
   
    [2] = {5917...
Well you probably tested it once, and it set the value. If you want to retest the script, you will have to remove the storage row that matches both your player id and key (unique id set on the item in the map editor).

i.e if the chest has a unique id of 5000 and the player id is 1, then look for the row in player_storages table that matches that data.
SQL:
SELECT * FROM `player_storage` WHERE `player_id` = 1 AND `key` = 5000
 
Well you probably tested it once, and it set the value. If you want to retest the script, you will have to remove the storage row that matches both your player id and key (unique id set on the item in the map editor).

i.e if the chest has a unique id of 5000 and the player id is 1, then look for the row in player_storages table that matches that data.
SQL:
SELECT * FROM `player_storage` WHERE `player_id` = 1 AND `key` = 5000
I tried that and it didn't work
 
I tried that and it didn't work

In you code
Lua:
if player:getStorageValue(uniqueId) ~= 0 then

Why not:
Code:
~= -1
or even:
Code:
> 0

For the player to have storage 0, he needs to do an action that gives him this storage, as far as I remember, -1 is used when the player does not have the storage yet. you can, for example, give storage 0 to a player by doing
Lua:
player:setStorageValue(uniqueid, 0)
and then the player will have this storage 0

If you have already done the quest and would like to repeat it to test, just make a commit or even use < 0 or == -1
 
Yeah good spot Mano, I overlooked that line.

@Madusa, no matter what you do, if you want to repeat test, you still need to remove the data from the database each time (or you reset via code on player login, for dev purposes). Then just make the change that Mano said, and check if the storageValue is > 0 instead.
 
Or since you are testing just change storage to 5545555 or somin xd once all quests have been completed you clear your database anyway.

Is this for latest tfs?
 
In you code
Lua:
if player:getStorageValue(uniqueId) ~= 0 then

Why not:
Code:
~= -1
or even:
Code:
> 0

For the player to have storage 0, he needs to do an action that gives him this storage, as far as I remember, -1 is used when the player does not have the storage yet. you can, for example, give storage 0 to a player by doing
Lua:
player:setStorageValue(uniqueid, 0)
and then the player will have this storage 0

If you have already done the quest and would like to repeat it to test, just make a commit or even use < 0 or == -1
Yeah good spot Mano, I overlooked that line.

@Madusa, no matter what you do, if you want to repeat test, you still need to remove the data from the database each time (or you reset via code on player login, for dev purposes). Then just make the change that Mano said, and check if the storageValue is > 0 instead.
I tried that and it didn't work. I even created a new account and it didn't work either
Until it no longer sends
It is empty.
Or since you are testing just change storage to 5545555 or somin xd once all quests have been completed you clear your database anyway.

Is this for latest tfs?
yeah 1.5
 
and the item/chest you are opening, in the map editor, i assume it has an action id of 10107, but what is it's unique id?
 
So, I noticed this line 'local uniqueId = item:getUniqueId()' and another one at the end 'action:aid(10107)'. Would it be correct to use 'action:uid(10107)' instead of 'action:aid(10107)' Since 'uid' stands for uniqueId, while 'aid' stands for actionId.

If you defined uniqueID through RME, then using 'action:uid(10107)' should be correct. It should work.
 
So, I noticed this line 'local uniqueId = item:getUniqueId()' and another one at the end 'action:aid(10107)'. Would it be correct to use 'action:uid(10107)' instead of 'action:aid(10107)' Since 'uid' stands for uniqueId, while 'aid' stands for actionId.

If you defined uniqueID through RME, then using 'action:uid(10107)' should be correct. It should work.
It was a miscommuncation, that part had already been solved.

The issue was the storage wasn't being set, due to the rest of the code being weird (cloning items etc).
I helped him in private and rewrote/simplified it:

Lua:
local vocationItemIds = {
    [1] = {5917, 3968},  -- Sorcerer
    [5] = {5917, 3968},  -- Sorcerer
   
    [2] = {5917, 3968},  -- Druid
    [6] = {5917, 3968},  -- Druid

    [3] = {7901, 7898},  -- Paladin
    [7] = {7901, 7898},  -- Paladin

    [4] = {2506, 2492},  -- Knight
    [8] = {2506, 2492},  -- Knight
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getType():isContainer() then
        return true
    end

    local uniqueId = item:getUniqueId()
    if player:getStorageValue(uniqueId) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local vocation = player:getVocation():getBase()
    local vocationId = vocation:getId()
   
    local rewardString = ""
    local itemIds = vocationItemIds[vocationId]
    if itemIds then
        for _, itemId in ipairs(itemIds) do
            local itemType = ItemType(itemId)
            if player:addItem(itemId, 1, true) then
                rewardString = string.format(
                    "%s%s%s",
                    rewardString,
                    (rewardString ~= "" and ", "  or ""),
                    itemType:getName()
                )
            end
        end
       
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You found: %s.", rewardString))
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

action:aid(10107)
action:register()
 
Solution
It was a miscommuncation, that part had already been solved.

The issue was the storage wasn't being set, due to the rest of the code being weird (cloning items etc).
I helped him in private and rewrote/simplified it:

Lua:
local vocationItemIds = {
    [1] = {5917, 3968},  -- Sorcerer
    [5] = {5917, 3968},  -- Sorcerer
  
    [2] = {5917, 3968},  -- Druid
    [6] = {5917, 3968},  -- Druid

    [3] = {7901, 7898},  -- Paladin
    [7] = {7901, 7898},  -- Paladin

    [4] = {2506, 2492},  -- Knight
    [8] = {2506, 2492},  -- Knight
}

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getType():isContainer() then
        return true
    end

    local uniqueId = item:getUniqueId()
    if player:getStorageValue(uniqueId) > 0 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local vocation = player:getVocation():getBase()
    local vocationId = vocation:getId()
  
    local rewardString = ""
    local itemIds = vocationItemIds[vocationId]
    if itemIds then
        for _, itemId in ipairs(itemIds) do
            local itemType = ItemType(itemId)
            if player:addItem(itemId, 1, true) then
                rewardString = string.format(
                    "%s%s%s",
                    rewardString,
                    (rewardString ~= "" and ", "  or ""),
                    itemType:getName()
                )
            end
        end
      
        player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You found: %s.", rewardString))
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

action:aid(10107)
action:register()
Thank you, everything works fine. I wish you success and everyone who tried to help me
 
Back
Top