• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Check this, easy!!

Wezza

lua nOOb
Joined
May 31, 2008
Messages
2,278
Reaction score
31
The error:

[Error - Action Interface]
data/actions/scripts/lever_buy.lua: onUse
Description:
data/actions/scripts/lever_buy.lua:40: attempt to call global 'warnPlayer' (a nil value)
stack traceback:
[29/06/2011 17:22:50] data/actions/scripts/lever_buy.lua:40: in function <data/actions/scripts/lever_buy.lua:14>


The lever buy and lever roll works great.. but when the player is out of money it sends this error, and I want when player doesnt have money it send message you are out of money.


thanks in advance, waiting for u Cyko ;D


here is the lever_buy:
LUA:
local itemList = {
    [2261] = {6000, 15},
    [2293] = {2000, 20},
    [2268] = {5000, 40},
    [2273] = {2000, 100},
    [2173] = {40000, 1},
    [2304] = {2000, 30},
    [2305] = {7000, 5},
    [2313] = {2000, 50},
    [2265] = {1000, 100}

}
 
function onUse(cid, item)

    if item.itemid == 1945 then
        doTransformItem(item.uid, 1946)
    else
        doTransformItem(item.uid, 1945)
    end
    
    local pos = getCreaturePosition(cid)
    local itemid = getThingfromPos({x=pos.x + 3, y=pos.y, z=pos.z, stackpos=2}).itemid
 
     if doComparePositions(getCreaturePosition(cid), {x=836,y=702,z=7}) then
        local buyItem = itemList[itemid]
        if buyItem then
            if getPlayerMoney(cid) >= buyItem[1] then
                local uid = doPlayerAddItem(cid, itemid, 1)
                if uid then
                    doChangeTypeItem(uid, buyItem[2])
                    doPlayerRemoveMoney(cid, buyItem[1])
                    doSendMagicEffect({x=pos.x + 3, y=pos.y, z=pos.z, stackpos=2}, CONST_ME_GIFT_WRAPS)
                    doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You bought a " .. getItemNameById(itemid) .. " with "  .. buyItem[2] .. " charges for " .. buyItem[1] .. " gold coins.")
                else
                    warnPlayer(cid, "Not enough room.")
                end
            else
            warnPlayer(cid, "This rune costs " .. buyItem[1] .. " gold coins.")
            end
        end
    else
        warnPlayer(cid, "You must stand infront of the lever.")
    end
    return TRUE
end
 
Last edited:
Cyko style first attempt:

PHP:
local itemList = {
[2261] = {6000, 15},
[2293] = {2000, 20},
[2268] = {5000, 40},
[2273] = {2000, 100},
[2173] = {40000, 1},
[2304] = {2000, 30},
[2305] = {7000, 5},
[2313] = {2000, 50},
[2265] = {1000, 100}

}
function onUse(cid, item)
 if item.itemid == 1945 then
  doTransformItem(item.uid, 1946)
   else
  doTransformItem(item.uid, 1945)
 end

local pos = getCreaturePosition(cid)
local itemid = getThingfromPos({x=pos.x + 3, y=pos.y, z=pos.z, stackpos=2}).itemid

if doComparePositions(getCreaturePosition(cid), {x=836,y=702,z=7}) then
 local buyItem = itemList[itemid]
  if buyItem then
   if getPlayerMoney(cid) >= buyItem[1] then
    local uid = doPlayerAddItem(cid, itemid, 1)
     if uid then
      doChangeTypeItem(uid, buyItem[2])
      doPlayerRemoveMoney(cid, buyItem[1])
      doSendMagicEffect({x=pos.x + 3, y=pos.y, z=pos.z, stackpos=2}, CONST_ME_GIFT_WRAPS)
      doSendMagicEffect(pos, CONST_ME_MAGIC_GREEN)
      doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You bought a " .. getItemNameById(itemid) .. " with " .. buyItem[2] .. " charges for " .. buyItem[1] .. " gold coins.")
     else
      doPlayerSendCancel(cid,"Not enough room.")
     end
   else
   doPlayerSendCancel(cid,"This rune costs " .. buyItem[1] .. " gold coins.")
   end
  end
else
doPlayerSendCancel(cid,"You must stand infront of the lever.")
end
return TRUE
end
@Edit second attempt
 
Last edited:
@Up

doPlayerSendTextMessage(cid, "You must stand infront of the lever.")

this wont work, the params are:
doPlayerSendTextMessage(cid, MessageClasses, message)

and by the way I see his code, I think he means a cancel message there
 
data/actions/scripts/lever_buy.lua:40: attempt to call global 'warnPlayer' (a nil value)

Add to 050-function.lua

PHP:
function warnPlayer(cid, msg) 
    -- Function by Colandus 
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
    return doPlayerSendCancel(cid, msg) 
end
 
Alright it works perfect now, I just need a little edit:


I want this line
doPlayerSendCancel(cid,"This rune costs " .. buyItem[1] .. " gold coins.")
to show on serverlog.
 
Last edited:
Back
Top