So I'm helping around with this basewars server, the mysql seems to be set up correctly I'm not sure.
Some people upon leave keep their money, some people don't, and I don't understand why.
Post the code which saves it.
What would be an example code, I'm not exactly sure.
[editline]7th February 2015[/editline]
Because it saves some people's but not all's.
[editline]7th February 2015[/editline]
[code]
function UpdateMoney( self, value )
bils = false
if (value>2147483647) then
value = value/1000000000
bils = true
end
umsg.Start( "MoneyChange", self )
umsg.Short( 0 )
umsg.Long( value )
umsg.Bool(bils)
umsg.End( )
end
function SetName(self, name)
return name
end
function GetName(self)
return ""
end
local mysql_hostname = '' -- Your MySQL server address.
local mysql_username = '' -- Your MySQL username.
local mysql_password = '' -- Your MySQL password.
local mysql_database = '' -- Your MySQL database.
local mysql_port = 3306 -- Your MySQL port. Most likely is 3306.
require('mysqloo')
local db = mysqloo.connect(mysql_hostname, mysql_username, mysql_password, mysql_database, mysql_port)
function db:onConnected()
MsgN('Basewars MySQL: Connected!')
end
function db:onConnectionFailed(err)
MsgN('Basewars MySQL: Connection Failed, please check your settings: ' .. err)
end
db:connect()
function GetMoney( ply )
local money, bils
local q = db:query("SELECT * FROM `basewarsmoney` WHERE id = '".. ply:GetNWInt("id") .."'")
function q:onSuccess(data)
if #data > 0 then
local row = data[1]
money = tonumber(row.money)
bils = tonumber(row.bils)
ply.Money = math.ceil(money+(1000000000*bils))
ply:AddMoney(0)
else
local qq = db:query("INSERT INTO `basewarsmoney` (id, money, bils) VALUES ('"..ply:GetNWInt("id").."','5000','0')")
function qq:onError(err, sql)
if db:status() ~= mysqloo.DATABASE_CONNECTED then
db:connect()
db:wait()
if db:status() ~= mysqloo.DATABASE_CONNECTED then
ErrorNoHalt("Re-connection to database server failed.")
return
end
end
MsgN('Basewars MySQL: Insert Query Failed: ' .. err .. ' (' .. sql .. ')')
end
ply.Money = 5000
ply:AddMoney(0)
qq:start()
end
end
function q:onError(err, sql)
if db:status() ~= mysqloo.DATABASE_CONNECTED then
db:connect()
db:wait()
if db:status() ~= mysqloo.DATABASE_CONNECTED then
ErrorNoHalt("Re-connection to database server failed.")
return
end
end
MsgN('Basewars MySQL: Fetch Query Failed: ' .. err .. ' (' .. sql .. ')')
end
q:start()
end
function SetMoney( ply )
local money
local bils = 0
money = ply:GetTable().Money
while money >= 1000000000 do
money = money - 1000000000
bils = bils + 1
end
money = tostring(money)
bils = tostring(bils)
local q = db:query("UPDATE `basewarsmoney` SET money = '"..money.."', bils = '"..bils.."' WHERE id = '".. ply:GetNWInt("id") .."'")
function q:onError(err, sql)
if db:status() ~= mysqloo.DATABASE_CONNECTED then
db:connect()
db:wait()
if db:status() ~= mysqloo.DATABASE_CONNECTED then
ErrorNoHalt("Re-connection to database server failed.")
return
end
end
MsgN('Basewars MySQL: Set Query Failed: ' .. err .. ' (' .. sql .. ')')
end
q:start()
end
// aliases for nigtits
setMoney = SetMoney
getMoney = GetMoney
[/code]
[editline]7th February 2015[/editline]
That's my money.lua code
Not enough since we don't know when these functions are called.
What more would you need?
[QUOTE=Raindroop;47097852]What more would you need?[/QUOTE]
To see where the functions are called to determine if there is logic errors in the code. Regardless that code is disgusting and the [URL="https://github.com/RGaming/"]code[/URL] it appears to be edited from is even more so. I know this isn't exactly helpful but I wouldn't even touch the gamemode it's so badly coded.
Would you guys happen to have any clue why only some people's money gets deleted?
Because we can't see where the functions are being called it is hard to guess.
My guess is that the data base is has disconnected or something when the player leaves and it doesn'tsave the information.
I don't see any issue with the code as far as I can see but there are so many unknowns.
What is ply:GetNWInt("id"), what's the strucutre of the db table, etc.
Can you atleast check if they lose the money on disconnect or on reconnect?
That is btw also one of the worst ways to store money, don't do the billions thing, just use a BigInt instead...
MySQLOO Doesn't support persistent connects if I recall correctly; you'll need to ensure the db is connected every query, otherwise re-connect and retry the query.
TMySQL Does support it ( have had my dev server up for a week + without it losing connection..
Also, make sure you're loading, saving in the right spots. Here's a basic money system that has everything except the load and save functions set: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_currency_system/simple_currency_system.zip[/url]
View:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_currency_system/sv_currency_system.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_currency_system/cl_currency_system.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_currency_system/_sh_currency_system.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.