Basewars money capping, Something to do with strings?
23 replies, posted
[CODE]if ( !sql.TableExists( "rpdmmoney" ) ) then
sql.Query( "CREATE TABLE IF NOT EXISTS rpdmmoney (Money TEXT, SteamID TEXT)" )
end
local sql = sql
local Format = Format
local SQLStr = SQLStr
local meta = FindMetaTable( "Player" )
local function FormatID( str )
return str:lower():gsub( ":", "_" )
end
function UpdateMoney( self, value )
umsg.Start( "MoneyChange", self )
umsg.Short( 0 )
umsg.Long( value )
umsg.End( )
end
function SetMoney( self )
local id
id = self:SteamID()
id = FormatID( id )
if ( tonumber( self.Money ) ~= nil ) then
local str = Format( "UPDATE rpdmmoney SET Money = %s WHERE SteamID = %s", self.Money, SQLStr( id ) )
sql.Query( str )
end
end
function GetMoney( self )
local id, money
id = self:SteamID()
id = FormatID( id )
money = sql.QueryValue( Format( "SELECT Money FROM rpdmmoney WHERE SteamID = %s", SQLStr( id ) ) )
money = tonumber( money ) || sql.Query( Format( "INSERT INTO rpdmmoney (SteamID, Money) VALUES (%s, 5000)", SQLStr( id ) ) ) || 5000
self.Money = math.min( math.ceil( money ), 214748364799 )
UpdateMoney( self, self.Money )
end
// aliases for nigtits
setMoney = SetMoney
getMoney = GetMoney
/*function getMoney(player)
local IDSteam = string.lower(string.gsub(player:SteamID(), ":", ""))
local money = sql.QueryValue("SELECT Money FROM rpdmmoney WHERE SteamID='"..IDSteam.."'")
//PrintTable(table)
local plmoney = 25000
if money != nil then
plmoney = math.ceil(tonumber(money))
else
Msg("Adding new user: " ..IDSteam.."\n")
sql.Query("INSERT INTO rpdmmoney (Money, SteamID) VALUES ('"..IDSteam.."', 5000)")
end
player:GetTable().Money = plmoney
// if its more than a long, just basically say A LOT
if (player:GetTable().Money>10000000000000) then
plmoney = 10000000000000
end
umsg.Start("MoneyChange", player)
umsg.Short(0)
umsg.Long(plmoney)
umsg.End()
end*/
/*function setMoney(player, amount)
local IDSteam = string.lower(string.gsub(player:SteamID(), ":", ""))
//player:GetTable().Money = player:GetTable().Money+amount
if tonumber(player:GetTable().Money)!=nil then
sql.Query("UPDATE rpdmmoney SET Money = ".. tostring(player:GetTable().Money .. "WHERE SteamID='"..IDSteam.."'"))
end
end*/[/CODE]
The money wont go past 2.1 billion dollars for some reason, Is it something to do with how it is layed out?
This line:
[CODE]self.Money = math.min( math.ceil( money ), 214748364799 )[/CODE]
Is saying that if your money is greater than 214748364799 then it will return 214748364799.
I will try and edit that
[editline]25th January 2014[/editline]
It is still capped, i edited the numbers and tried removing it all together
Try this:
[CODE]self.Money = math.min( math.ceil( money ), 21474836479900 )[/CODE]
If that doesn't work, I will take another look.
Still does not work, But thanks for the continuous help i appreciate it
Try this:
[CODE]self.Money = math.ceil( money )[/CODE]
If that doesn't work then the issue is somewhere else, or it is too large for usermessages.
Still broken, I was wondering if it is the way that it is formatted in sql or something?
This is due to MySQL and the maximum number for a 32 bit storage system is 2^31 − 1. Change the data type in your MySQL columns, should fix it.
There is no visible files anywhere for this, And im new to lua, Let alone SQL :/
[editline]25th January 2014[/editline]
Would you edit the money.lua?
No, You would edit the MySQL column data type. Open up your preferred MySQL database managing tool, select the database you are using, right click on the appropriate table and select 'modify table'. Change the data data to something like 'BIG INT'.
The thing is, the rpdmoney file appears no where on my servers drive :L
[QUOTE=Hydreh;43664053]The thing is, the rpdmoney file appears no where on my servers drive :L[/QUOTE]
Do you even know how a MySQL server works?
No, thats why i came here for help D:
Well i know it stores data in columns something like
STEAMID MONEY
And then it selects the row where steamid is = to your own and selects the money data, that about all
just execute this sql
[code]
ALTER TABLE rpdmmoney MODIFY Money BIGINT
[/code]
How would you go about doing that?
im going to asume that you use the database in garrysmod/garrysmod/sv.db
open that file with any sqllite manger such as [url=https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/]this one[/url]
now click the tab that says "execute sql" and execute the code above
How do you use that addon, im completely lost on how to execute it or even open that extension
[editline]25th January 2014[/editline]
Just cant find the way to open the extension
open firefox, press the firefox icon, press webdevloper, press sqllite manger at the very bottom OR
open firefox, press alt, press tools, press sqllite manger
thats strange but you can also just select your table in the left side then click structure, right click money, click "Edit column" and then change the new column type to bigint
[CODE]if ( !sql.TableExists( "rpdmmoney" ) ) then
sql.Query( "CREATE TABLE IF NOT EXISTS rpdmmoney (Money BIGINT, SteamID TEXT)" )
end
local sql = sql
local Format = Format
local SQLStr = SQLStr
local meta = FindMetaTable( "Player" )
local function FormatID( str )
return str:lower():gsub( ":", "_" )
end
function UpdateMoney( self, value )
umsg.Start( "MoneyChange", self )
umsg.Short( 0 )
umsg.Long( value )
umsg.End( )
end
function SetMoney( self )
local id
id = self:SteamID()
id = FormatID( id )
if ( tonumber( self.Money ) ~= nil ) then
local str = Format( "UPDATE rpdmmoney SET Money = %s WHERE SteamID = %s", self.Money, SQLStr( id ) )
sql.Query( str )
end
end
function GetMoney( self )
local id, money
id = self:SteamID()
id = FormatID( id )
money = sql.QueryValue( Format( "SELECT Money FROM rpdmmoney WHERE SteamID = %s", SQLStr( id ) ) )
money = tonumber( money ) || sql.Query( Format( "INSERT INTO rpdmmoney (SteamID, Money) VALUES (%s, 5000)", SQLStr( id ) ) ) || 5000
self.Money = math.ceil( money )
UpdateMoney( self, self.Money )
end
// aliases for nigtits
setMoney = SetMoney
getMoney = GetMoney
[/CODE]
[CODE]
[ERROR] gamemodes/basewars/gamemode/player.lua:119: attempt to call global 'getMoney' (a nil value)
1. AddMoney - gamemodes/basewars/gamemode/player.lua:119
2. unknown - gamemodes/basewars/gamemode/extracrap.lua:758
[[/CODE]
[editline]25th January 2014[/editline]
Fixed errors, Still a money cap though :/
Are you sure the money cap isn't just clientside? Check the database and see if the amount of money is what you set it to.
The range for a usermessage long is considerably smaller than the sql bigint.
bigint: 9,223,372,036,854,775,807
long: 2,147,483,647
My money is well beyond 2b, is there a way to remove the long thing?
No the only way I can thinking of at the moment is checking if the value is above a certain value, and if so divide it up and send multiple longs in the usermessage.
There may be a more efficient way though.
Sorry, you need to Log In to post a reply to this thread.