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

TFS 1.X+ Adding a key (with action id) inside a bag with items, as reward from a quest.

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,517
Solutions
27
Reaction score
870
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again! I use TFS 1.4 downgraded by nekiro. I did this simple script and I wonder how can I add a reward with action id (specifically a key) with inside a bag with other items. I know that doing something like this will auto-assing the aid to the key:

Lua:
local key = player:addItem(2091, 1)
    if key then
    key:setActionId(6010)
    end

And this will generate a table for the other items that the bag will hold:
Lua:
local cfgItems = {{2229, 1}, {2151, 2}, {2165, 1}, {2230, 1}}
local bag = player:addItem(1987) -- Bag id
for i = 1, #cfgItems do
bag:addItem(cfgItems[i][1], cfgItems[i][2])
end

The thing is. How can I add the key inside the bag with cfgItems and make the setActionId work?
This is the sample script I made for this, the key is given outside the bag and that's what I need to solve.

Lua:
local cfgItems = {{2229, 1}, {2151, 2}, {2165, 1}, {2230, 1}}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local parchmentStorage = PlayerStorageKeys.ParchmentRoomQuest
    local player = Player(cid)
    if player:getStorageValue(parchmentStorage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The coffin is empty.")
        return true
    end
 
    local bag = player:addItem(1987) -- Bag id
    for i = 1, #cfgItems do
    bag:addItem(cfgItems[i][1], cfgItems[i][2])
    end
    local key = player:addItem(2091, 1)
    if key then
    key:setActionId(6010)
    end
    player:setStorageValue(parchmentStorage, 1)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a bag.")
    toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
    return true
end

Regards! :)
 
Last edited:
Solution
Probably this way, changing player usertada to the bag userdata you already have

Lua:
local key = bag:addItem(2091, 1)
if key then
    key:setActionId(6010)
end

Also you may want to check if the bag actually was added to the player within your for condition
Lua:
if bag then
...
end
Probably this way, changing player usertada to the bag userdata you already have

Lua:
local key = bag:addItem(2091, 1)
if key then
    key:setActionId(6010)
end

Also you may want to check if the bag actually was added to the player within your for condition
Lua:
if bag then
...
end
 
Solution
Lua:
local key = bag:addItem(2091, 1)
if key then
    key:setActionId(6010)
end

Also you may want to check if the bag actually was added to the player within your for condition
Lua:
if bag then
...
end

Thanks for responding :). Yes, the bag is added correctly when triggering the quest; the way you say is not going to work because it is going to add the actionId to the bag, and I want it to be added to the key (id:2091) that's why the local key references that item ;p

I'm trying to make The Parchment Room Quest by the way, and the coffin isn't recognized a container that's why I need to do it manually.

Regards!
Post automatically merged:

Sorry I totally missunderstood it, this is referencing bag to directly add the rewards into it. Thanks a lot! @Baahzera
 
Last edited:
Back
Top