• 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 [TFS Master] [Talkaction] Buy AOL Script

Demnish

Tibian Hero
Joined
Sep 28, 2011
Messages
402
Solutions
2
Reaction score
65
Location
Sweden
Need some help with my !aol script which errors out.
It looks good to me, so I need some assistance as to why it does.

Code:
LUA:
local config = {
    itemId = ITEM_AMULETOFLOSS,
    price = 50000
}

local itemType = ItemType(config.itemId)
local itemWeight = itemType:getWeight()
local playerCap = player:getFreeCapacity()

function onSay(player, words, param)
    if player:removeMoney(config.price) and playerCap >= itemWeight then
        player:addItem(config.itemId)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought an amulet of loss for " .. config.price .. " gold coins.")
    elseif playerCap < itemWeight then
        player:sendCancelMessage("You can not recieve " .. itemType:getName() .. " weighing " .. itemWeight .. " oz, it is too heavy.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    else
        player:sendCancelMessage("You do not have enough money, an amulet of loss costs " .. config.price .. " gold coins.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end

Error:
Lua Script Error: [Test Interface]
data/talkactions/scripts/custom/buyaol.lua
data/talkactions/scripts/custom/buyaol.lua:8: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/talkactions/scripts/custom/buyaol.lua:8: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/custom/buyaol.lua

Thanks in advance. :)
 
Last edited:
Solution
E
LUA:
local config = {
    itemId = ITEM_AMULETOFLOSS,
    price = 50000
}

local itemType = ItemType(config.itemId)
local itemWeight = itemType:getWeight()

function onSay(player, words, param)
    local playerCap = player:getFreeCapacity()
    if player:removeMoney(config.price) and playerCap >= itemWeight then
        player:addItem(config.itemId)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought an amulet of loss for " .. config.price .. " gold coins.")
    elseif playerCap < itemWeight then
        player:sendCancelMessage("You can not recieve " .. itemType:getName() .. " weighing " .. itemWeight .. " oz, it is too heavy.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    else...
LUA:
local config = {
    itemId = ITEM_AMULETOFLOSS,
    price = 50000
}

local itemType = ItemType(config.itemId)
local itemWeight = itemType:getWeight()

function onSay(player, words, param)
    local playerCap = player:getFreeCapacity()
    if player:removeMoney(config.price) and playerCap >= itemWeight then
        player:addItem(config.itemId)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You bought an amulet of loss for " .. config.price .. " gold coins.")
    elseif playerCap < itemWeight then
        player:sendCancelMessage("You can not recieve " .. itemType:getName() .. " weighing " .. itemWeight .. " oz, it is too heavy.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    else
        player:sendCancelMessage("You do not have enough money, an amulet of loss costs " .. config.price .. " gold coins.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end
 
Solution
Back
Top