• 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 NPC on weight capacity

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
586
Solutions
2
Reaction score
61
Location
México
Hello, otlanders im experiencing an issue, i have a reward shop (like Premium shop with npc) so, when i buy an ítem the npc ignores capacity and give ítems even when capacity is overloaded.

heres my lua scripts (tfs 0.4 rev 3884)...

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
[6533] = 200,
[2268] = 50,
[2273] = 5,
[2293] = 8,
[2304] = 3,
[2313] = 4,
[2274] = 4,
[2315] = 4,
[2278] = 30,
[2169] = 20,
[7620] = 5,
[7589] = 8,
[7590] = 10,
[7618] = 5,
[7588] = 8,
[7591] = 10,
[8473] = 15,
[8472] = 10,
[7589] = 5,
[7443] = 10,
[7440] = 10,
[7439] = 10,
[12466] = 35,
[2167] = 20,
[2207] = 20,
[2208] = 20,
[2269] = 20,
[2166] = 20,

[2164] = 50,
[2165] = 50,
[2168] = 50,
[2216] = 50,
[2789] = 10

}
local onBuy = function(cid, item, subType, amount, inBackpacks)
if t[item] and getAccountPoints(cid) < t[item] then
selfSay("You need "..t[item].." reward points to buy this item.", cid)
else
doAccountRemovePoints(cid, t[item])
doPlayerAddItem(cid, item, 10)
selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
end
return true
end
if (msgcontains(msg, 'tutorial') or msgcontains(msg, 'help'))then
doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
\
1-.You must have atleast 50 gp in your backpack (to enable trade).\
2-.You may trade your !points here.\
\
use !online to see your time.\
")
setPlayerStorageValue(cid, 444447910, 1)
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
if getPlayerStorageValue(cid, 444447910) == -1 then
doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
\
1-.You must have atleast 50 gp in your backpack (to enable trade).\
2-.You may trade your !points here.\
\
use !online to see your time.\
")
setPlayerStorageValue(cid, 444447910, 1)
end
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Replace with this, restart the server and take an SS of the error;
Lua:
function getAccountPoints(cid)
    local res = db.getResult('select `reward_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
    if(res:getID() == -1) then
        return 0
    end

    print("Fetching points")
    local ret = res:getDataInt("reward_points")
    res:free()
    return tonumber(ret)
end

function doAccountAddPoints(cid, count)
    return db.executeQuery("UPDATE `accounts` SET `reward_points` = '".. getAccountPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

function doAccountRemovePoints(cid, count)
    print("Removed points")
    return db.executeQuery("UPDATE `accounts` SET `reward_points` = '".. getAccountPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end



Code:
[15:43:27.245] [Error - LuaInterface::loadFile] data/lib/048-ppoints.lua:2: unexpected symbol near '┬'
[15:43:27.245] [Warning - LuaInterface::initState] Cannot load data/lib/

this is the error i get when i paste exact script, so i must remove that '┬' with notepad++.
After removed that special character the error is same
-15:45 Reward Shop: You either need more room or more cap.
-no points removed
-cap ignored
-gives 1 ítem

console says
Code:
 fetching points
 
Last edited:
Fail xD
Lua:
local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
  \
  1-.You must have atleast 50 gp in your backpack (to enable trade).\
  2-.You may trade your !points here.\
  \
  use !online to see your time.\
  ")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
    \
    1-.You must have atleast 50 gp in your backpack (to enable trade).\
    2-.You may trade your !points here.\
    \
    use !online to see your time.\
    ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Fail xD
Lua:
local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
  \
  1-.You must have atleast 50 gp in your backpack (to enable trade).\
  2-.You may trade your !points here.\
  \
  use !online to see your time.\
  ")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
    \
    1-.You must have atleast 50 gp in your backpack (to enable trade).\
    2-.You may trade your !points here.\
    \
    use !online to see your time.\
    ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

1-. npc gives ítem
2-. npc remove points
3-. npc ignore caps x.x

bug still there :/
 
1-. npc gives ítem
2-. npc remove points
3-. npc ignore caps x.x

bug still there :/

I guess I was wrong then, 0.x is a huge mess IMO haha
It's hardcoded now;
Lua:
  local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR and getItemWeight(item) <= getPlayerFreeCap(cid) then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
 \
 1-.You must have atleast 50 gp in your backpack (to enable trade).\
 2-.You may trade your !points here.\
 \
 use !online to see your time.\
 ")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
   \
   1-.You must have atleast 50 gp in your backpack (to enable trade).\
   2-.You may trade your !points here.\
   \
   use !online to see your time.\
   ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I guess I was wrong then, 0.x is a huge mess IMO haha
It's hardcoded now;
Lua:
  local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR and getItemWeight(item) <= getPlayerFreeCap(cid) then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
 \
 1-.You must have atleast 50 gp in your backpack (to enable trade).\
 2-.You may trade your !points here.\
 \
 use !online to see your time.\
 ")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
   \
   1-.You must have atleast 50 gp in your backpack (to enable trade).\
   2-.You may trade your !points here.\
   \
   use !online to see your time.\
   ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


almost, but give this error.

Code:
[12:34:26.602] [Error - NpcScript Interface]
[12:34:26.606] (Unknown script file)
[12:34:26.611] Description:
[12:34:26.614] (LuaInterface::luaGetItemWeight) Item not found
[12:34:26.622] [Error - NpcScript Interface]
[12:34:26.626] (Unknown script file)
[12:34:26.631] Description:
[12:34:26.637] data/npc/scripts/rewards.lua:51: attempt to compare boolean with number
[12:34:26.646] stack traceback:
[12:34:26.649]  data/npc/scripts/rewards.lua:51: in function <data/npc/scripts/rewards.lua:48>
 
almost, but give this error.

Code:
[12:34:26.602] [Error - NpcScript Interface]
[12:34:26.606] (Unknown script file)
[12:34:26.611] Description:
[12:34:26.614] (LuaInterface::luaGetItemWeight) Item not found
[12:34:26.622] [Error - NpcScript Interface]
[12:34:26.626] (Unknown script file)
[12:34:26.631] Description:
[12:34:26.637] data/npc/scripts/rewards.lua:51: attempt to compare boolean with number
[12:34:26.646] stack traceback:
[12:34:26.649]  data/npc/scripts/rewards.lua:51: in function <data/npc/scripts/rewards.lua:48>

Lua:
 local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR and getItemWeight(targetItem) <= getPlayerFreeCap(cid) then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
\
1-.You must have atleast 50 gp in your backpack (to enable trade).\
2-.You may trade your !points here.\
\
use !online to see your time.\
")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
  \
  1-.You must have atleast 50 gp in your backpack (to enable trade).\
  2-.You may trade your !points here.\
  \
  use !online to see your time.\
  ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
 local t = {
  [6533] = 200,
  [2268] = 50,
  [2273] = 5,
  [2293] = 8,
  [2304] = 3,
  [2313] = 4,
  [2274] = 4,
  [2315] = 4,
  [2278] = 30,
  [2169] = 20,
  [7620] = 5,
  [7589] = 8,
  [7590] = 10,
  [7618] = 5,
  [7588] = 8,
  [7591] = 10,
  [8473] = 15,
  [8472] = 10,
  [7589] = 5,
  [7443] = 10,
  [7440] = 10,
  [7439] = 10,
  [12466] = 35,
  [2167] = 20,
  [2207] = 20,
  [2208] = 20,
  [2269] = 20,
  [2166] = 20,
  [2164] = 50,
  [2165] = 50,
  [2168] = 50,
  [2216] = 50,
  [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
  if not npcHandler:isFocused(cid) then
    return false
  end
  local shopWindow = {}
  local onBuy = function(cid, item, subType, amount, inBackpacks)
    local targetItem = doCreateItemEx(item, 1)
    if t[item] and getAccountPoints(cid) > t[item] then
      if doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR and getItemWeight(targetItem) <= getPlayerFreeCap(cid) then
        doAccountRemovePoints(cid, t[item])
        selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
      else
        selfSay("You either need more room or more cap.", cid)
      end
    else
      doRemoveItem(targetItem)
      selfSay("You either need poitns or capacity.", cid)
    end
    return true
  end
  if msgcontains(msg, 'tutorial') or msgcontains(msg, 'help') then
    doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
\
1-.You must have atleast 50 gp in your backpack (to enable trade).\
2-.You may trade your !points here.\
\
use !online to see your time.\
")
    setPlayerStorageValue(cid, 444447910, 1)
  end
  if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
    if getPlayerStorageValue(cid, 444447910) == -1 then
      doPlayerPopupFYI(cid, "[Tutorial]: Reward shop!\
  \
  1-.You must have atleast 50 gp in your backpack (to enable trade).\
  2-.You may trade your !points here.\
  \
  use !online to see your time.\
  ")
      setPlayerStorageValue(cid, 444447910, 1)
    end
    for var, ret in pairs(t) do
      table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
  end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

First ítems adds weight cap(working) but, after second ítem, cap is ignored (when items get stack)
 
almost, but give this error.

Code:
[12:34:26.602] [Error - NpcScript Interface]
[12:34:26.606] (Unknown script file)
[12:34:26.611] Description:
[12:34:26.614] (LuaInterface::luaGetItemWeight) Item not found
[12:34:26.622] [Error - NpcScript Interface]
[12:34:26.626] (Unknown script file)
[12:34:26.631] Description:
[12:34:26.637] data/npc/scripts/rewards.lua:51: attempt to compare boolean with number
[12:34:26.646] stack traceback:
[12:34:26.649]  data/npc/scripts/rewards.lua:51: in function <data/npc/scripts/rewards.lua:48>
Lua:
getItemWeightById(itemid, count[, precise])
getItemWeight(uid[, precise])
Since the item does not exist yet, you'll want to find the weight of the item by it's itemID instead of by fetching the item.uid

also,
Code:
doRemoveItem(targetItem)
This is not required, and will likely cause an error.
You cannot remove an item that only exists in memory.
Code:
selfSay("You either need poitns or capacity.", cid)
This line is incorrect as well.. You've never checked for capacity at all, and it's giving the player false information.
Code:
local targetItem = doCreateItemEx(item, 1)
Shouldn't the "1" be "amount" instead?
Although, as-is it will force the player to buy 1 item at a time, but may confuse them, if they are attempting to use the "slider" to get more then 1 item per purchase.

In either case.. here's is how I think it should look like...

-- nevermind got really busy at work and had no chance to do anything.
Hope my info helps.

-- honestly was a couple hours later.
You can probably ignore my entire message.
 
Lua:
getItemWeightById(itemid, count[, precise])
getItemWeight(uid[, precise])
Since the item does not exist yet, you'll want to find the weight of the item by it's itemID instead of by fetching the item.uid

also,
Code:
doRemoveItem(targetItem)
This is not required, and will likely cause an error.
You cannot remove an item that only exists in memory.
Code:
selfSay("You either need poitns or capacity.", cid)
This line is incorrect as well.. You've never checked for capacity at all, and it's giving the player false information.
Code:
local targetItem = doCreateItemEx(item, 1)
Shouldn't the "1" be "amount" instead?
Although, as-is it will force the player to buy 1 item at a time, but may confuse them, if they are attempting to use the "slider" to get more then 1 item per purchase.

In either case.. here's is how I think it should look like...

-- nevermind got really busy at work and had no chance to do anything.
Hope my info helps.

-- honestly was a couple hours later.
You can probably ignore my entire message.

i have no hurry, seriously. if u could help me i'd be glad :)


WibbenZ and i were trying to fix the problema, the last script done was this.

Lua:
local t = {
 [6533] = 200,
 [2268] = 50,
 [2273] = 5,
 [2293] = 8,
 [2304] = 3,
 [2313] = 4,
 [2274] = 4,
 [2315] = 4,
 [2278] = 30,
 [2169] = 20,
 [7620] = 5,
 [7589] = 8,
 [7590] = 10,
 [7618] = 5,
 [7588] = 8,
 [7591] = 10,
 [8473] = 15,
 [8472] = 10,
 [7589] = 5,
 [7443] = 10,
 [7440] = 10,
 [7439] = 10,
 [12466] = 35,
 [2167] = 20,
 [2207] = 20,
 [2208] = 20,
 [2269] = 20,
 [2166] = 20,
 [2164] = 50,
 [2165] = 50,
 [2168] = 50,
 [2216] = 50,
 [2789] = 10
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
 if not npcHandler:isFocused(cid) then
  return false
 end
 local shopWindow = {}
 local onBuy = function(cid, item, subType, amount, inBackpacks)
  if t[item] and getAccountPoints(cid) > t[item] then
   local targetItem = doCreateItemEx(item, amount)
   if (getItemWeight(targetItem) * amount) <= getPlayerFreeCap(cid) then
    doPlayerAddItem(cid, item, amount)
    doAccountRemovePoints(cid, t[item])
    selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
   else
    selfSay("You either need more room or more cap.", cid)
   end
   doRemoveItem(targetItem)
  else
   selfSay("You either need poitns or capacity.", cid)
  end
  return true
 end
 if msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') then
  for var, ret in pairs(t) do
   table.insert(shopWindow, {id = var, subType = 0, buy = ret, sell = 0, name = getItemNameById(var)})
  end
  openShopWindow(cid, shopWindow, onBuy, onSell)
 end
 return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
getItemWeightById(itemid, count[, precise])
getItemWeight(uid[, precise])
Since the item does not exist yet, you'll want to find the weight of the item by it's itemID instead of by fetching the item.uid

also,
Code:
doRemoveItem(targetItem)
This is not required, and will likely cause an error.
You cannot remove an item that only exists in memory.
Code:
selfSay("You either need poitns or capacity.", cid)
This line is incorrect as well.. You've never checked for capacity at all, and it's giving the player false information.
Code:
local targetItem = doCreateItemEx(item, 1)
Shouldn't the "1" be "amount" instead?
Although, as-is it will force the player to buy 1 item at a time, but may confuse them, if they are attempting to use the "slider" to get more then 1 item per purchase.

In either case.. here's is how I think it should look like...

-- nevermind got really busy at work and had no chance to do anything.
Hope my info helps.

-- honestly was a couple hours later.
You can probably ignore my entire message.

Yes I noticed those things on TV, I tought doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR would check for cap etc
It all seems to work with that script except the cap isn't updated, im guessing it's either an NPC lib problem or source code issue, asked him to update everything and check again.

To make it clear, you get the items you bought, it removes the points, you get the correct message etc but the cap isn't updated.
 
Yes I noticed those things on TV, I tought doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR would check for cap etc
It all seems to work with that script except the cap isn't updated, im guessing it's either an NPC lib problem or source code issue, asked him to update everything and check again.

To make it clear, you get the items you bought, it removes the points, you get the correct message etc but the cap isn't updated.
Code:
doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR
like you said, this line would definitely check for capacity and weight, but it won't show the weight required to the caller.
You have to calculate weight separately, or be a bit lazy and do. "You do not have enough capacity or inventory space."

You can see how I did it over here, if you want.
Give player infinite items from table, with 1 small function.
 
Code:
doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR
like you said, this line would definitely check for capacity and weight, but it won't show the weight required to the caller.
You have to calculate weight separately, or be a bit lazy and do. "You do not have enough capacity or inventory space."

You can see how I did it over here, if you want.
Give player infinite items from table, with 1 small function.

Yes I think it should, but it didn't for some reason, his source is modified that I know, all it says is TFS 0.4, nothing else no creds, links etc
It just kept giving the item haha
And he has another issue that he can't have new lines or any tabs in scripts, checked the encoding of the file but it's fine, something is really weird ..
 
Yes I noticed those things on TV, I tought doPlayerAddItemEx(cid, targetItem, false) == RETURNVALUE_NOERROR would check for cap etc
It all seems to work with that script except the cap isn't updated, im guessing it's either an NPC lib problem or source code issue, asked him to update everything and check again.

To make it clear, you get the items you bought, it removes the points, you get the correct message etc but the cap isn't updated.

I've had updated/dowgraded tfs (from 0.3.6 to 0.4 rev 4267) and seems is not the source o libs.
Since others npc does not ignore the cap after the ítem stack, i might be something that the script lacks, maybe a check out of capacity after buying a second ítem (stacking).

Also when u buy 2 or more ítems NPC just remove points from 1 item
 
I've had updated/dowgraded tfs (from 0.3.6 to 0.4 rev 4267) and seems is not the source o libs.
Since others npc does not ignore the cap after the ítem stack, i might be something that the script lacks, maybe a check out of capacity after buying a second ítem (stacking).

Also when u buy 2 or more ítems NPC just remove points from 1 item

Can you test one of these;
TFS 0.4 r3777 / r3884
TFS 0.3.6

And see if it works or if it's the same, when you test that version make sure to replace the lib folder data/npcs/libs
 
Can you test one of these;
TFS 0.4 r3777 / r3884
TFS 0.3.6

And see if it works or if it's the same, when you test that version make sure to replace the lib folder data/npcs/libs

I've already tried whit those versions/rev libs and npc libs (including my points lib obviously) and its the same problm ,others npc work great, but mine isnt working.
 
I've already tried whit those versions/rev libs and npc libs (including my points lib obviously) and its the same problm ,others npc work great, but mine isnt working.

Lua:
local onBuy = function(cid, item, subType, amount, inBackpacks)
    if t[item] and getAccountPoints(cid) > t[item] then
        local _, amountSold = doNpcSellItem(cid, item, amount, subType, false, inBackpacks)
        if amountSold < amount then
            if amountSold == 0 then
                selfSay("Sorry, but you don't have space to take it.", cid)
            else
                selfSay("I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary.", cid)
                doPlayerRemoveMoney(cid, i * t[item])
            end
        else
            selfSay("Thanks for the money!", cid)
            doPlayerRemoveMoney(cid, amount * t[item])
        end
    else
        selfSay("You either need poitns or capacity.", cid)
    end
    return true
end

Now it's using the same functions a "normal" NPCs does.
 
Lua:
local onBuy = function(cid, item, subType, amount, inBackpacks)
    if t[item] and getAccountPoints(cid) > t[item] then
        local _, amountSold = doNpcSellItem(cid, item, amount, subType, false, inBackpacks)
        if amountSold < amount then
            if amountSold == 0 then
                selfSay("Sorry, but you don't have space to take it.", cid)
            else
                selfSay("I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary.", cid)
                doPlayerRemoveMoney(cid, i * t[item])
            end
        else
            selfSay("Thanks for the money!", cid)
            doPlayerRemoveMoney(cid, amount * t[item])
        end
    else
        selfSay("You either need poitns or capacity.", cid)
    end
    return true
end

Now it's using the same functions a "normal" NPCs does.
-Gives 1 ítem (and ignore cap if get stack)
-NPC: Sorry, but you don't have space to take it (even if player has cap).
-Console print: Fetching points
 
Last edited:
-Gives 1 ítem (and ignore cap if get stack)
-NPC: Sorry, but you don't have space to take it (even if player has cap).
-Console print: Fetching points

In that case im lost, I can't see anything wrong with any of the scripts.
And if you have tested diffrent TFS versions aswell as using that versions NPC libs ... ye I have no ide
 
Back
Top