Lurk
Active Member
- Joined
- Dec 4, 2017
- Messages
- 336
- Reaction score
- 48
Helo, I have this script that allows players to use their website points in tradow windows with other players
I have this on my libs
this creaturescript (registered on login.lua and creaturescripts.xml)
and this talkaction
as you can see I added some prints. The error I got is this
and with my prints I found out that
edit: fixed. There are source changes for this code (I didn't post/mention because I thought they didn't matter) and turns out that I changed the onlook message there and I have to change the line 12 of the creaturescript to match the new description
I have this on my libs
Lua:
function getAccountPoints(cid)
local Points = 0
local Result = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
if Result:getID() ~= -1 then
Points = Result:getDataInt("points")
end
return tonumber(Points)
end
function doAccountAddPoints(cid, count)
return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) + count .."' WHERE `account_id` = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
end
function doAccountRemovePoints(cid, count)
return db.query("UPDATE `znote_accounts` SET `points` = '".. getAccountPoints(cid) - count .."' WHERE `account_id` = " .. getAccountNumberByPlayerName(getCreatureName(cid))..";")
end
this creaturescript (registered on login.lua and creaturescripts.xml)
Lua:
function CompleteTrade(fromplayer, toplayer, points)
if getPlayerItemCount(toplayer, 7722) >= 1 and getAccountPoints(fromplayer) >= points then
doAccountRemovePoints(fromplayer, points)
doPlayerRemoveItem(toplayer, 7722, 1)
doPlayerAddPoints(toplayer, points)
doPlayerSendTextMessage(toplayer, MESSAGE_STATUS_WARNING, "You have received ".. points .." Collapser Orbs.")
return true
end
end
function CollapserOrbs(item)
return tonumber(string.match(getItemDescriptions(item.uid).special, "You see (%w+) Collapser Orbs."))
end
function onTradeAccept(cid, target, item, targetItem)
if isPlayer(cid) and isPlayer(target) then
if (item.itemid == 7722 and targetItem.itemid == 7722) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You cannot trade points for points.")
doPlayerSendTextMessage(target, MESSAGE_STATUS_WARNING, "You cannot trade points for points.")
return false
end
if item.itemid == 7722 then
local points = CollapserOrbs(item)
addEvent(CompleteTrade, 1, cid, target, points)
end
if targetItem.itemid == 7722 then
local points = CollapserOrbs(targetItem)
addEvent(CompleteTrade, 1, target, cid, points)
end
end
return true
end
and this talkaction
Lua:
function onSay(cid, words, param, channel)
local t = string.explode(param, ",")
local target = getCreatureByName(t[1])
local points = tonumber(t[2])
if(param == '') then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
end
if (target ~= nil and target ~= cid) and isPlayer(target) and not isPlayerGhost(target) then
if (points ~= nil) and (type(points) == 'number') and (points>0) then
if (getAccountPoints(cid) >= points) then
doTradeOrbs(cid, target, points)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You do not have enough points.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
end
return true
end
as you can see I added some prints. The error I got is this
Code:
[23:41:39.870] [Error - CreatureScript Interface]
[23:41:39.876] In a timer event called from:
[23:41:39.880] data/creaturescripts/scripts/Trade_Orbs.lua:onTradeAccept
[23:41:39.884] Description:
[23:41:39.886] data/creaturescripts/scripts/Trade_Orbs.lua:5: attempt to compare nil with number
[23:41:39.890] stack traceback:
[23:41:39.891] data/creaturescripts/scripts/Trade_Orbs.lua:5: in function <data/creaturescripts/scripts/Trade_Orbs.lua:1>
and with my prints I found out that
points
on my creaturescripts is always null, can anyone help? My print on the talkaction side is showing the currect amount of points but when it goes to the creaturescript it becomes nulledit: fixed. There are source changes for this code (I didn't post/mention because I thought they didn't matter) and turns out that I changed the onlook message there and I have to change the line 12 of the creaturescript to match the new description
Last edited: