Hello there, I'm working on a banker npc that interact with player's 'balance' on table accounts in distro "9.31 - The Forgotten Server - Version 0.2.11.2 (Mystic Spirit) - R4".
But I got no clue on how to do that, first of all, is that possible without adding any new function?
There is a function on global.lua that can lead the way:
Theres a way to edit this function to make it work on a script or to make a new function so it would be able to check, add and remove values from 'balance'?
Like:
doPlayerWithdrawMoney
doPlayerSetBalance
getPlayerBalance
???
Thanks in advance!!
EDIT:
As I'm not being sucessful adding or editing that one function I'm trying this script:
but it returns this error:
PD: I'm using 'mysql" and I don't know why it returns about sqlite =S
But I got no clue on how to do that, first of all, is that possible without adding any new function?
There is a function on global.lua that can lead the way:
Lua:
-- Returns player name if player exists in database or 0
function playerExists(name)
dofile("./config.lua")
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
else
env = assert(luasql.sqlite3())
con = assert(env:connect(sqliteDatabase))
end
local cur = assert(con:execute("SELECT `name` FROM `players` WHERE `name` = '" .. escapeString(name) .. "';"))
local row = cur:fetch({}, "a")
local name_ = ""
if row ~= nil then
name_ = row.name
end
cur:close()
con:close()
env:close()
return name_
end
Theres a way to edit this function to make it work on a script or to make a new function so it would be able to check, add and remove values from 'balance'?
Like:
doPlayerWithdrawMoney
doPlayerSetBalance
getPlayerBalance
???
Thanks in advance!!
EDIT:
As I'm not being sucessful adding or editing that one function I'm trying this script:
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)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
-- select action
if (msgcontains(msg, "balance")) and (npcHandler:isFocused(cid)) then
selfSay('Your account balance is ' .. db.executeQuery('SELECT balance FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil .. ' gold.', cid)
npcHandler:addFocus(cid)
talkState[talkUser] = 0
return true
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
but it returns this error:
Code:
[14/12/2011 09:17:16] Lua Script Error: [Npc interface]
[14/12/2011 09:17:16] data/npc/scripts/bankold.lua:onCreatureSay
[14/12/2011 09:17:16] data/db.lua:10: attempt to call field 'sqlite3' (a nil value)
[14/12/2011 09:17:16] stack traceback:
[14/12/2011 09:17:16] [C]: in function 'sqlite3'
[14/12/2011 09:17:16] data/db.lua:10: in function 'getConnection'
[14/12/2011 09:17:16] data/db.lua:22: in function 'executeQuery'
[14/12/2011 09:17:16] data/npc/scripts/bankold.lua:22: in function 'callback'
[14/12/2011 09:17:17] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[14/12/2011 09:17:17] data/npc/scripts/bankold.lua:8: in function <data/npc/scripts/bankold.lua:8>
PD: I'm using 'mysql" and I don't know why it returns about sqlite =S
Last edited: