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

item aid in lua?

oshrigames

Active Member
Joined
Nov 9, 2012
Messages
222
Reaction score
47
Location
israel
Original post:
once again Hello :3

anyone know how to add key with action ID as reward?
i use TFS 1.2 (protocol 10.98)

Lua:
lucky_items = {

[6132] = {price = 12}, -- SOFT BOOTS

[2091, 26194] = {price = 6} -- gold key with action ID: 26194

}

^ didnt work btw!
 
Last edited:
Solution
I'm not any good with TFS 1.2 ... but try this?

Remove any of the stuff you added from before.. then

Replace this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
        
            if ((pstorage) >= (itemprice)) then...
Use addItem() and setActionId().
Nvm, saw that you're referring to the config of a system.

You could try:
Lua:
local key = player:addItem(2091, 1)
    if key then
    key:setActionId(26194)
end
 
Last edited:
thanks for reply..

i get this error
Code:
data/talkactions/scripts/luckycoinstalk.lua
data/talkactions/scripts/luckycoinstalk.lua:7: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/luckycoinstalk.lua:7: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/luckycoinstalk.lua

here is the script:
Lua:
--: Configs  :--
local storage = 32143 --: Script storage, same on all files
local msg = "Lucky Coins are used here to buy vip items by playing the game. You can buy it at our website shop." --: Message to show
local msgtwo = "You can view your luckycoins by typing !luckycoins amount. view Shop by typing !luckycoins buy." --: If there's no param on command
local msgbuy = "These are the items that you can buy: Soft Boots"
local modalid = 1053 --: Same as luckycoinstalk
local key = player:addItem(2091, 1)
    if key then
    key:setActionId(26194)
end

--: AMOUNT  :--
local qtdtext = "You have" --: For translation issues

--: BUY  :--
local title = "Buy items with your lucky coins!" --: Modal Title text
local message = "Click to buy a item!" --: Modal text

--: ITENS TO SELL FOR LUCKY COINS :--
-- [ITEM ID] = {price = <ITEM PRICE>},
lucky_items = {
  [6132] = {price = 12}, -- Pair of Soft Boots
  [9933] = {price = 12}, -- Firewalker Boots
  [2091] = {price = 6} -- Advanced Training room key +x4 skill rate --item, 'aid', 26194
}
ordem = {}
-- Limit of ~250 items i guess


function onSay(player, words, param)
  local storageatual = player:getStorageValue(storage)
  local plural = "s"
  local qtd = ""

  if (storageatual < 0) then storageatual = 0    player:setStorageValue(storage, 0) end

  if (storageatual == 1) then    plural = ""    end
  qtd = " " .. qtdtext .. " " .. storageatual .. " lucky coin" .. plural .. "."
  if (param == "amount") then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, qtd)

  elseif (param == "buy") then
    --if (onlypz == 1 and player:isPzLocked()) then player:sendCancelMessage('You are not in protection zone.') return false end adições futuras

    for k in pairs (ordem) do ordem [k] = nil end
    player:registerEvent("ModalWindow_LuckyCoins")

    local window = ModalWindow(modalid, title, message .. qtd)
    window:addButton(100, "Buy")
    window:addButton(101, "Cancel")

    for k in pairs(lucky_items) do
      table.insert(ordem, k)
    end
    table.sort(ordem)
    for i = 1, #ordem do
      local k, v = ordem[i], lucky_items[ ordem[i] ]
      window:addChoice(i, string.upper((ItemType(k):getName())) .. " - " .. lucky_items[k].price .. " " .. "lucky coin(s)")
    end

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)

    window:sendToPlayer(player)
  else
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg .. " " .. msgtwo)
  end
  return false
end
 
you, right.. i'm stupid :p

but i now encounter different issue.
when i say, "!luckycoins buy" i get the key, i need to choose it from the list and 6 luckycoins need to be removed
and when i purchase it from the "onModalWindow" (store list) will has 0 aid.
lc.png
 
What happens if you don't include the local key part? Looks like it's not doing anything right now.
The reason why it's now working for you, is because you removed "26194" from the code below.
Lua:
[2091, 26194] = {price = 6} -- gold key with action ID: 26194
 
I'm not any good with TFS 1.2 ... but try this?

Remove any of the stuff you added from before.. then

Replace this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
        
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                player:addItem(itemid, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
with this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
            local aid = (lucky_items[ordem[choiceId]].actionID)
        
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                local thing = player:addItem(itemid, 1)
                if aid and aid ~= nil then
                    thing:setActionId(aid)
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
and update your item table, to look like this.
Lua:
-- this way
lucky_items = {
    [6132] = {price = 12, actionID = nil}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}

-- or this way
lucky_items = {
    [6132] = {price = 12}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}
 
Solution
What happens if you don't include the local key part? Looks like it's not doing anything right now.
The reason why it's now working for you, is because you removed "26194" from the code below.


that was the main issue
i can't put , in the "lucky items" table

Code:
[Warning - Event::checkScript] Can not load script: scripts/luckycoinstalk.lua
data/talkactions/scripts/luckycoinstalk.lua:20: ']' expected near ','
 
Last edited:
that was the main issue
i can't put , in the "lucky items" table

Code:
[Warning - Event::checkScript] Can not load script: scripts/luckycoinstalk.lua
data/talkactions/scripts/luckycoinstalk.lua:20: ']' expected near ','
show your current script?
 
I'm not any good with TFS 1.2 ... but try this?

Remove any of the stuff you added from before.. then

Replace this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
    
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                player:addItem(itemid, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
with this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
            local aid = (lucky_items[ordem[choiceId]].actionID)
    
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                local thing = player:addItem(itemid, 1)
                if aid and aid ~= nil then
                    thing:setActionId(aid)
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
and update your item table, to look like this.
Lua:
-- this way
lucky_items = {
    [6132] = {price = 12, actionID = nil}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}

-- or this way
lucky_items = {
    [6132] = {price = 12}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}

ive change, and tested both,Key still:
"
18:57 You see a golden key (Key:0).
It weighs 1.00 oz.
Item ID: 2091
"

but this time i don't get
Code:
[Warning - Event::checkScript] Can not load script: scripts/luckycoinstalk.lua
data/talkactions/scripts/luckycoinstalk.lua:20: ']' expected near ','

current script:
Lua:
--: Configs  :--
local storage = 32143 --: Script storage, same on all files
local msg = "Lucky Coins are used here to buy vip items by playing the game. You can buy it at our website shop." --: Message to show
local msgtwo = "You can view your luckycoins by typing !luckycoins amount. view Shop by typing !luckycoins buy." --: If there's no param on command
local msgbuy = "These are the items that you can buy: Soft Boots"
local modalid = 1053 --: Same as luckycoinstalk

--: AMOUNT  :--
local qtdtext = "You have" --: For translation issues

--: BUY  :--
local title = "Buy items with your lucky coins!" --: Modal Title text
local message = "Click to buy a item!" --: Modal text

--: ITENS TO SELL FOR LUCKY COINS :--
-- [ITEM ID] = {price = <ITEM PRICE>},
lucky_items = {
    [6132] = {price = 12}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}
ordem = {}
-- Limit of ~250 items i guess


function onSay(player, words, param)
  local storageatual = player:getStorageValue(storage)
  local plural = "s"
  local qtd = ""

  if (storageatual < 0) then storageatual = 0    player:setStorageValue(storage, 0) end

  if (storageatual == 1) then    plural = ""    end
  qtd = " " .. qtdtext .. " " .. storageatual .. " lucky coin" .. plural .. "."
  if (param == "amount") then
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, qtd)

  elseif (param == "buy") then
    --if (onlypz == 1 and player:isPzLocked()) then player:sendCancelMessage('You are not in protection zone.') return false end adições futuras

    for k in pairs (ordem) do ordem [k] = nil end
    player:registerEvent("ModalWindow_LuckyCoins")

    local window = ModalWindow(modalid, title, message .. qtd)
    window:addButton(100, "Buy")
    window:addButton(101, "Cancel")

    for k in pairs(lucky_items) do
      table.insert(ordem, k)
    end
    table.sort(ordem)
    for i = 1, #ordem do
      local k, v = ordem[i], lucky_items[ ordem[i] ]
      window:addChoice(i, string.upper((ItemType(k):getName())) .. " - " .. lucky_items[k].price .. " " .. "lucky coin(s)")
    end

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)

    window:sendToPlayer(player)
  else
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg .. " " .. msgtwo)
  end
  return false
end
 
I'm not any good with TFS 1.2 ... but try this?

Remove any of the stuff you added from before.. then

Replace this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
      
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                player:addItem(itemid, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
with this
Lua:
--: Configurações Gerais  :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk


function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("ModalWindow_LuckyCoins")
    if modalWindowId == modalid then
        if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
            local itemprice = (lucky_items[ordem[choiceId]].price)
            local pstorage = (player:getStorageValue(storage))
            local itemid = (ordem[choiceId])
            local aid = (lucky_items[ordem[choiceId]].actionID)
      
            if ((pstorage) >= (itemprice)) then
                player:setStorageValue(storage, (pstorage - itemprice))
                local thing = player:addItem(itemid, 1)
                if aid and aid ~= nil then
                    thing:setActionId(aid)
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
            else
                player:sendCancelMessage('You dont have enough lucky coins.')
            end
        end
    end
end
and update your item table, to look like this.
Lua:
-- this way
lucky_items = {
    [6132] = {price = 12, actionID = nil}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}

-- or this way
lucky_items = {
    [6132] = {price = 12}, -- SOFT BOOTS
    [2091] = {price = 6, actionID = 26194} -- gold key with action ID: 26194
}

Works great!, i'll make sure to note the changes in original post so other people who might wanna use it can add it more easily

big thanks
 
Last edited:
Back
Top