• 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:
Put prints everywhere.
i've done that, and seems working good, NPC trade ítems, remove points needed.
The bugs are these.
1-.When player buy 2 or more ítems, NPC just remove the points from 1 ítem.
2-.When player buy an ítem, and that ítem get stacked with other, the capacity gets ignored.
 
Back
Top