kaspertje100
Member
- Joined
- May 8, 2008
- Messages
- 236
- Reaction score
- 7
Hi there.
Please help me out with this script.
Sbh-add.lua
Error msg:
lua script error: [talkaction interface]
data/talkactions/scripts/bh-add.luansay
data/db.lua:16: attempt to index global 'luasql' (a nil value) stack trace back:
Data/db.lua:16: in function 'getconnection'
data/db.lua:40: in function 'getresult'
data/talkactions/scripts/bh-add.lua:18: in function (data/talkactions/scripts/bh-add.lua:1
DB.lua:
Please Help rep++ ofc
Please help me out with this script.
Sbh-add.lua
PHP:
function onSay(cid, words, param)
if(param == "") then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
return TRUE
end
local t = string.explode(param, ",")
if(not t[2]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
return TRUE
end
local sp_id = getPlayerGUIDByName(t[2])
if sp_id == nil then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] This player doesn't exists.")
return TRUE
end
local result_plr = db.getResult("SELECT * FROM `bounty_hunters` WHERE `sp_id` = "..sp_id.." AND `killed` = 0;")
if(result_plr:getID() ~= -1) then
is = tonumber(result_plr:getDataInt("sp_id"))
result_plr:free()
else
is = 0
end
prize = tonumber(t[1])
if(prize == nil or prize < 1) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Use: \"!hunt [prize],[nick]\" where prize is for example 1(k).")
return TRUE
end
if(prize >= 100000000000000000000) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Sorry, you typed too big number!")
return TRUE
end
if is ~= 0 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] This player has already hunted.")
return TRUE
end
if doPlayerRemoveMoney(cid, prize*1000) == TRUE then
db.executeQuery("INSERT INTO `bounty_hunters` VALUES (NULL,"..getPlayerGUID(cid)..","..sp_id..",0," .. os.time() .. ","..prize..",0,0);")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] Hunt has been added!")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[BOUNTY HUNTERS] You haven't got enough money!")
end
return 1
end
Error msg:
lua script error: [talkaction interface]
data/talkactions/scripts/bh-add.luansay
data/db.lua:16: attempt to index global 'luasql' (a nil value) stack trace back:
Data/db.lua:16: in function 'getconnection'
data/db.lua:40: in function 'getresult'
data/talkactions/scripts/bh-add.lua:18: in function (data/talkactions/scripts/bh-add.lua:1
DB.lua:
PHP:
--[[
CREDITS:
>> 80% COLANDUS
>> 20% GRANDMATHER, FIX MANY ISSUE!
]]--
db = {}
db.__index = db
function getConnection()
local env, con
if sqlType == "mysql" then
env = assert(luasql.mysql())
con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
else -- sqlite
env = assert(luasql.sqlite3())
con = assert(env:connect(sqliteDatabase))
end
return env, con
end
function db.escapeString(str)
return "'" .. escapeString(str) .. "'"
end
function db.executeQuery(sql)
local env, con = getConnection()
cur = assert(con:execute(sql))
if(type(cur) ~= 'number') then
cur:close()
end
con:close()
env:close()
end
function db.getResult(sql)
local mt = {}
mt.env, mt.con = getConnection()
mt.cur = assert(mt.con:execute(sql))
if(mt.cur:numrows() > 0) then
mt.val = mt.cur:fetch({}, "a")
end
setmetatable(mt, db)
return mt
end
function db:getID()
return self.val and true or LUA_ERROR
end
function db:next()
self.val = self.cur:fetch(self.val, "a")
if self.val then
return true
end
end
function db:getDataInt(name)
if(self.val) then
return tonumber(self.val[name])
end
end
function db:getDataString(name)
if(self.val) then
return tostring(self.val[name])
end
end
function db:free()
self.cur:close()
self.con:close()
self.env:close()
end
Please Help rep++ ofc