• 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 Help with config in lua script

Stellow

C++/C#/PHP/LUA
Joined
Oct 23, 2008
Messages
1,106
Reaction score
214
Location
Germany
GitHub
eubrunomiguel
I am trying to make my lua script shortes. This script is supposed to buy items using lever, is not working tho, and not showing any error msg. I am using red 3777 tfs .4


Code:
local config = {
   [1001] = {itemid = 7620, price = 5000, cap = 180},
   [1002] = {itemid = 7589, price = 8000, cap = 200}
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
   local id = config[item.uid]
           
    if(getPlayerFreeCap(cid) < id.cap) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need at least " .. id.cap .. " oz to buy this item.")
        return true
    end
   
    if item.uid < 1001 or item.uid > 1015 then
        return false
    end

    if getCreatureStorage(cid,6667) == -1 then
    doPlayerSendCancel(cid,"You need to finish Annihilator 2 Quest to use this lever.")
        return false
    end
   
    if item.itemid == 1945 then
        doTransformItem(item.uid, 1946)
    elseif item.itemid == 1946 then
        doTransformItem(item.uid, 1945)
    end   
   
    if item.uid == id then
  if getPlayerMoney(cid) >= id.price then
            brown_bp = doPlayerAddItem(cid, id.itemid, 100)
            doPlayerRemoveMoney(cid, id.price)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought it for ".. id.price .." gold coins.")
  else
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have enough money.")
  end
    end
   
   
    return true
end
 
edit: it work if I work with action ID. My scripts are calling an unique action id, and inside the function an unique ID for each item
Code:
local config = {
   [1001] = {itemid = 7620, price = 5000, cap = 180},
   [1002] = {itemid = 7589, price = 8000, cap = 200}
}


function onUse(cid, item, fromPosition, itemEx, toPosition)
   local id = config[item.uid]
    if(getPlayerFreeCap(cid) < id.cap) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need at least " .. id.cap .. " oz to buy this item.")
        return false
    end
  
    if item.uid < 1001 or item.uid > 1015 then
        return false
    end

    if getCreatureStorage(cid,6667) == -1 then
        doPlayerSendCancel(cid,"You need to finish Annihilator 2 Quest to use this lever.")
        return false
    end
  
    if item.itemid == 1945 then
        doTransformItem(item.uid, 1946)
    elseif item.itemid == 1946 then
        doTransformItem(item.uid, 1945)
    end  
  
    if id then
        if getPlayerMoney(cid) >= id.price then
            brown_bp = doPlayerAddItem(cid, id.itemid, 100)
            doPlayerRemoveMoney(cid, id.price)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought it for ".. id.price .." gold coins.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have enough money.")
        end
    end
    return true
end
 
why not
Code:
local itemType = ItemType(id.itemid)
local itemWeight = itemType:getWeight()
local playerCap = player:getFreeCapacity()
if playerCap >= itemWeight then
 
why not
Code:
local itemType = ItemType(id.itemid)
local itemWeight = itemType:getWeight()
local playerCap = player:getFreeCapacity()
if playerCap >= itemWeight then
for cap check I used:

Code:
    if(getPlayerFreeCap(cid) < id.cap * 100) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need " .. id.cap*100 .. " oz to buy this item.")
        return true
    end
 

Similar threads

Back
Top