• 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
583
Solutions
2
Reaction score
60
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:
How to display CODE properly in your post

If your script is tabbed then upload that.

The problem is that you just give the player the item without checking what the item is weighing and how much cap the player has.
Lua:
doPlayerAddItem(cid, item, 10)

You can take a look at this if you wanna try to fix it yourself; forgottenserver/quests.lua at master · otland/forgottenserver · GitHub
hello, sorry for misscoding :p, thanks for the post, but im very ashamed i cant translate tfs 1.0 to tfs 0.4 :/ haven't work with it. how can i check the ítem weight and the player cap to insert into my code?

also, i dont have this functions
Lua:
ifPlayerCap
ItemWeight
getWeight
 
Last edited:
hello, sorry for misscoding :p, thanks for the post, but im very ashamed i cant translate tfs 1.0 to tfs 0.4 :/ haven't work with it. how can i check the ítem weight and the player cap to insert into my code?

also, i dont have this functions
Lua:
ifPlayerCap
ItemWeight
getWeight

Im really bad with 0.x haha, but I guess this could work.
Thats atleast what the quest system in 0.4 uses.

Lua:
local item = doCreateItemEx(itemid, count)
if doPlayerAddItemEx(cid, item.uid, false) ~= RETURNVALUE_NOERROR then
    -- got item
else
    -- error
end
 
Im really bad with 0.x haha, but I guess this could work.
Thats atleast what the quest system in 0.4 uses.

Lua:
local item = doCreateItemEx(itemid, count)
if doPlayerAddItemEx(cid, item.uid, false) ~= RETURNVALUE_NOERROR then
    -- got item
else
    -- error
end
Thanks for the help, but is not working, the bug continues...

scripted this.
Lua:
local onBuy = function(cid, item, subType, amount, inBackpacks)
local item = doCreateItemEx(itemid, count)
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR then
doAccountRemovePoints(cid, t[item])
doPlayerAddItemEx(cid, item, 10)
selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
else
selfSay("You either need poitns or capacity.", cid)
end
return true
end

and i get this error.
Code:
[13:24:47.304] [Error - NpcScript Interface]
[13:24:47.306] (Unknown script file)
[13:24:47.307] Description:
[13:24:47.308] (luaDoCreateItemEx) Item not found
 
Last edited:
Thanks for the help, but is not working, the bug continues...

scripted this.
Lua:
local onBuy = function(cid, item, subType, amount, inBackpacks)
local item = doCreateItemEx(itemid, count)
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR then
doAccountRemovePoints(cid, t[item])
doPlayerAddItemEx(cid, item, 10)
selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
else
selfSay("You either need poitns or capacity.", cid)
end
return true
end

and i get this error.
Code:
[13:24:47.304] [Error - NpcScript Interface]
[13:24:47.306] (Unknown script file)
[13:24:47.307] Description:
[13:24:47.308] (luaDoCreateItemEx) Item not found

It would help if you post the full script so we can see what the lines are, what the tables should contain etc
But you can't overwrite the t[item] with what I posted as "item"

Hard to say without the updated code, but I guess this should work, just paste it in.
Lua:
local targetItem = doCreateItemEx(item, 1)
if doPlayerAddItemEx(cid, targetItem.uid, false) ~= RETURNVALUE_NOERROR then
    -- got item
else
    -- error
end
 
It would help if you post the full script so we can see what the lines are, what the tables should contain etc
But you can't overwrite the t[item] with what I posted as "item"

Hard to say without the updated code, but I guess this should work, just paste it in.
Lua:
local targetItem = doCreateItemEx(item, 1)
if doPlayerAddItemEx(cid, targetItem.uid, false) ~= RETURNVALUE_NOERROR then
    -- got item
else
    -- error
end
I updated the script and get this error.
Code:
[13:35:36.476] [Error - NpcScript Interface]
[13:35:36.478] (Unknown script file)
[13:35:36.478] Description:
[13:35:36.479] data/npc/scripts/rewards.lua:58: attempt to index local 'targetItem' (a number value)
[13:35:36.480] stack traceback:
[13:35:36.480]  data/npc/scripts/rewards.lua:58: in function <data/npc/scripts/rewards.lua:56>
Here's the full scripts.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 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)
local targetItem = doCreateItemEx(item, 1)
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, targetItem.uid, false) ~= RETURNVALUE_NOERROR then
doAccountRemovePoints(cid, t[item])
doPlayerAddItem(cid, item, 10)
selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
else
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 updated the script and get this error.
Code:
[13:35:36.476] [Error - NpcScript Interface]
[13:35:36.478] (Unknown script file)
[13:35:36.478] Description:
[13:35:36.479] data/npc/scripts/rewards.lua:58: attempt to index local 'targetItem' (a number value)
[13:35:36.480] stack traceback:
[13:35:36.480]  data/npc/scripts/rewards.lua:58: in function <data/npc/scripts/rewards.lua:56>
Here's the full scripts.

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 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)
local targetItem = doCreateItemEx(item, 1)
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, targetItem.uid, false) ~= RETURNVALUE_NOERROR then
doAccountRemovePoints(cid, t[item])
doPlayerAddItem(cid, item, 10)
selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
else
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())

Because you changed it and didn't add it correctly;
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())
 
Last edited:
Because you changed it and didn't add it correctly;
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] and doPlayerAddItemEx(cid, targetItem.uid, false) ~= RETURNVALUE_NOERROR then
            doAccountRemovePoints(cid, t[item])
            doPlayerAddItem(cid, item, 10)
            selfSay("Here your item! (total points: " .. getAccountPoints(cid) .. ")", cid)
        else
            doRemoveItem(targetItem.uid)
            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've paste the scripts and got the same error.

Code:
[13:51:08.630] [Error - NpcScript Interface]
[13:51:08.631] (Unknown script file)
[13:51:08.631] Description:
[13:51:08.632] data/npc/scripts/rewards.lua:53: attempt to index local 'targetItem' (a number value)
[13:51:08.632] stack traceback:
[13:51:08.633]  data/npc/scripts/rewards.lua:53: in function <data/npc/scripts/rewards.lua:51>
 
i've paste the scripts and got the same error.

Code:
[13:51:08.630] [Error - NpcScript Interface]
[13:51:08.631] (Unknown script file)
[13:51:08.631] Description:
[13:51:08.632] data/npc/scripts/rewards.lua:53: attempt to index local 'targetItem' (a number value)
[13:51:08.632] stack traceback:
[13:51:08.633]  data/npc/scripts/rewards.lua:53: in function <data/npc/scripts/rewards.lua:51>

Updated my post
 
Thanks, no error appear in console, but NPC is not giving ítems.

i have enough points and capacity but NPC says
13:59 Reward Shop: You either need poitns or capacity.

Ok then you need to debug the script;
Above:
Lua:
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, targetItem, false) ~= RETURNVALUE_NOERROR then
Add:
Lua:
print(t[item], getAccountPoints(cid) > t[item], doPlayerAddItemEx(cid, targetItem, false))
 
Ok then you need to debug the script;
Above:
Lua:
if t[item] and getAccountPoints(cid) > t[item] and doPlayerAddItemEx(cid, targetItem, false) ~= RETURNVALUE_NOERROR then
Add:
Lua:
print(t[item], getAccountPoints(cid) > t[item], doPlayerAddItemEx(cid, targetItem, false))
Its working, but,it gives 11 ítems (instead of 10) and does not affect capacity
also when it reach max cap npc says
'14:29 Reward Shop: You either need poitns or capacity.'
and gives 3 items
 
Its working, but,it gives 11 ítems (instead of 10) and does not affect capacity
also when it reach max cap npc says
'14:29 Reward Shop: You either need poitns or capacity.'
and gives 3 items

Missed the addItem function, you can also add a fail message for the function, ex;
Lua:
    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
Replace the onBuy snipet with that.
 
Missed the addItem function, you can also add a fail message for the function, ex;
Lua:
    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
Replace the onBuy snipet with that.
1-.Gives ítems (1)
2-.14:51 Reward Shop: You either need more room or more cap.
3-.cap ignored.
4-.points ignored

full code
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())
 
Last edited:
1-.Gives ítems (1)
2-.14:51 Reward Shop: You either need more room or more cap.
3-.cap ignored.
4-.points ignored

full code
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())

Why do you change the tabs to spaces and remove all the new lines?

When you try to buy the second one? Try to say bye and then try again and see if it works then.
The cap dosn't move? WHen you get an item? Are you on a god char?
When you try to buy another item? You get the item but no points are removed?
 
Why do you change the tabs to spaces and remove all the new lines?

When you try to buy the second one? Try to say bye and then try again and see if it works then.
The cap dosn't move? WHen you get an item? Are you on a god char?
When you try to buy another item? You get the item but no points are removed?

Why do you change the tabs to spaces and remove all the new lines?
-i got a format error when copy a text (adds an unknown space carácter, so i must remove it whitn notepad++ to make it work)
The cap dosn't move?
-i mean it gets ignored.
WHen you get an item?
-i got an iteam when i buy something, but caps and poitns are ignored by npc
Are you on a god char?
-i am on an Access = 0 charachter
When you try to buy another item? You get the item but no points are removed?
-no points are removed.
 
Why do you change the tabs to spaces and remove all the new lines?
-i got a format error when copy a text (adds an unknown space carácter, so i must remove it whitn notepad++ to make it work)
The cap dosn't move?
-i mean it gets ignored.
WHen you get an item?
-i got an iteam when i buy something, but caps and poitns are ignored by npc
Are you on a god char?
-i am on an Access = 0 charachter
When you try to buy another item? You get the item but no points are removed?
-no points are removed.

Post these 2 functions;
getAccountPoints
doAccountRemovePoints
 
rewardpoints.lua (libs)
Lua:
function getAccountPoints(cid)
local res = db.getResult('select `reward_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
if(res:getID() == -1) then
return false
end
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)
return db.executeQuery("UPDATE `accounts` SET `reward_points` = '".. getAccountPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end
 
rewardpoints.lua (libs)
Lua:
function getAccountPoints(cid)
local res = db.getResult('select `reward_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
if(res:getID() == -1) then
return false
end
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)
return db.executeQuery("UPDATE `accounts` SET `reward_points` = '".. getAccountPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

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
 
Back
Top