So, I got myself hooked up with an old PERP gamemode which my friend had located on some of his old USB sticks. I got everything set up, but encountered some problems with Tmsql in the first place, somehow, it fixed itself. But now I am having problems with the query part which let the server and database connect with each other but not communicate with files. Both can't transfer any data.
Here is the code which is giving the error, which is located in sv_hooks.lua (of course)
[CODE]
function GM:InitializeMysql() //I'm too lazy to convert everything from tmysql
Msg("Loading mysql module... ");
require("tmysql");
if (tmysql) then
Msg("done!\n");
else
Msg("failed!\n");
end
tmysql.initialize("database url", "username", "password", "database name", 3306)
DataBase = {}
function DataBase:Query(qure, func)
tmysql.query(qure, function(dat, status)
if (type(func) == "function" and status == QUERY_SUCCESS) then
func(dat)
elseif(status == QUERY_FAIL) then
print("Query failed!" .. qure)
GAMEMODE:InitializeMysql()
end
end)
end
print( "Database has connected!" )
end
[/CODE]
Yes, I have replaced my own details with variables.
Here's an easy fix.
Don't use PERP.
[QUOTE=kpjVideo;51547199]Here's an easy fix.
Don't use PERP.[/QUOTE]
Well, you are not the first who said that. Beside all the errors it has and buggs, it's a very usefull roleplay gamemode though.
tmysql4 now uses the database object to send queries. You can see the documentation here: [url]https://facepunch.com/showthread.php?t=1442438[/url]
perp is old and you're gonna need some experience with gmod and lua to get it running
[QUOTE=code_gs;51547757]tmysql4 now uses the database object to send queries. You can see the documentation here: [url]https://facepunch.com/showthread.php?t=1442438[/url][/QUOTE]
So, you rather using the tmysql3 version instead?
[QUOTE=DeNaamIsKoen;51550841]So, you rather using the tmysql3 version instead?[/QUOTE]
You can, but it's outdated and causes crashes in my experience. Just convert it to use 4.
[QUOTE=code_gs;51550861]You can, but it's outdated and causes crashes in my experience. Just convert it to use 4.[/QUOTE]
I'll try tmysql3 first. I'll let you know about the results.
[editline]19th December 2016[/editline]
[QUOTE=code_gs;51550861]You can, but it's outdated and causes crashes in my experience. Just convert it to use 4.[/QUOTE]
Okay. But if I'd have to use 4, how may I convert it?
[editline]19th December 2016[/editline]
I replaced the Tmysql related error and encountered one error left:
[CODE]
[ERROR] gamemodes/perp/gamemode/sv_hooks.lua:4: attempt to call field 'query' (a nil value)
1. sendOnline - gamemodes/perp/gamemode/sv_hooks.lua:4
2. unknown - gamemodes/perp/gamemode/sv_hooks.lua:69
[/CODE]
Again, you have to use Database:Query instead with tmysql4. The database object is returned from tmysql.Connect or Initialize.
[QUOTE=code_gs;51551233]Again, you have to use Database:Query instead with tmysql4. The database object is returned from tmysql.Connect or Initialize.[/QUOTE]
So this could work with the Tmysql4?
[CODE]function GM:InitializeMysql() //I'm too lazy to convert everything from tmysql
Msg("Loading mysql module... ");
require("tmysql");
if (tmysql) then
Msg("done!\n");
else
Msg("failed!\n");
end
Database connection, String error = tmysql.initialize( String hostname, String username, String password, String database, 3306, nil, CLIENT_MULTI_STATEMENTS)
Database:Connect()
function Database:Query( String query, Function callback, Object anything, Boolean ColumnNumbers )
tmysql.query(qure, function(dat, status)
if (type(func) == "function" and status == QUERY_SUCCESS) then
func(dat)
elseif(status == QUERY_FAIL) then
print("Query failed!" .. qure)
GAMEMODE:InitializeMysql()
end
end)
end
print( "Database has connected!" )
end[/CODE]
[editline]19th December 2016[/editline]
[QUOTE=DeNaamIsKoen;51550881]I'll try tmysql3 first. I'll let you know about the results.
[editline]19th December 2016[/editline]
Okay. But if I'd have to use 4, how may I convert it?
[editline]19th December 2016[/editline]
I replaced the Tmysql related error and encountered one error left:
[CODE]
[ERROR] gamemodes/perp/gamemode/sv_hooks.lua:4: attempt to call field 'query' (a nil value)
1. sendOnline - gamemodes/perp/gamemode/sv_hooks.lua:4
2. unknown - gamemodes/perp/gamemode/sv_hooks.lua:69
[/CODE][/QUOTE]
The code which is cousing this error:
[CODE]
1. local function sendOnline ( )
2. if (GAMEMODE.ServerIdentifier == 0) then return end
3.
4. tmysql.query("UPDATE `perp_system` SET `value`='" .. os.time() .. "' WHERE `key`='online_" .. GAMEMODE.ServerIdentifier .. "' LIMIT 1");
5. timer.Create("sendOnline", 10, 0, sendOnline);
end
[/CODE]
Il leave perp, creating your own RP gamemode is more fun tought.
Oops, forgot to click reply. You don't have to declare the type you're using in Lua; your initialize statement was fine. Just use the database object returned by the function for queries. Ex:
[code]local database = tmysql.initialize(...)
database:Query(...)[/code]
[QUOTE=code_gs;51557244]Oops, forgot to click reply. You don't have to declare the type you're using in Lua; your initialize statement was fine. Just use the database object returned by the function for queries. Ex:
[code]local database = tmysql.initialize(...)
database:Query(...)[/code][/QUOTE]
Pretty sure database would return a table in that case ;)
instead, do
[code]
local database, err = tmysql.initialize(...)
if not database then
print( err )
return
end
database:Query(...)
[/code]
[QUOTE=Tupac;51557422]Pretty sure database would return a table in that case ;)
instead, do
[code]
local database, err = tmysql.initialize(...)
if not database then
print( err )
return
end
database:Query(...)
[/code][/QUOTE]
Was just showing an example of how to use the object, but you are correct :)
|
\/
[editline]26th December 2016[/editline]
This is my current code:
[CODE]
function GM:Initialize ( )
Msg("Loading tmysql module... ");
require('tmysql');
if (tmysql) then
Msg("done!\n");
else
Msg("failed!\n");
end
self.ServerIdentifier = 1;
self.ServerDateIdentifier = 1;
self.numPlayers = 128;
self.ReservedSlots = 64;
self.Serious = true;
SQL_INFO_1 = ""; -- HOST
SQL_INFO_2 = ""; -- Username
SQL_INFO_3 = ""; -- Password
SQL_INFO_4 = ""; -- Database Name
local database, err = tmysql.initialize(SQL_INFO_1, SQL_INFO_2, SQL_INFO_3, SQL_INFO_4, 3306);
if not database then
print( err )
return
end
database:Query(sendOnline());
RunConsoleCommand("sv_visiblemaxplayers", self.numPlayers-self.ReservedSlots);
timer.Simple(1, function ( )
RunConsoleCommand("sv_allowdownload", "0");
RunConsoleCommand("sv_allowupload", "1");
RunConsoleCommand("sv_usermessage_maxsize", "5000");
RunConsoleCommand('lua_log_sv', '1');
RunConsoleCommand('net_maxfilesize', '64');
end);
SetGlobalInt("tax_sales", 5);
SetGlobalInt("tax_income", 5);
RunConsoleCommand("qcache_gamedesc", "");
RunConsoleCommand("sv_max_queries_window", "5");
self.IsSerious = (self.ServerIdentifier == 2);
self.HouseAlarms = {};
tmysql.query("SELECT `key`, `value` FROM `perp_system` WHERE `key`='date_year_" .. self.ServerDateIdentifier .. "' OR `key`='date_month_" .. self.ServerDateIdentifier .. "' OR `key`='date_day_" .. self.ServerDateIdentifier .. "'", function ( Whatever )
for k, v in pairs(Whatever) do
if (v[1] == "date_year_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentYear = tonumber(v[2]);
elseif (v[1] == "date_month_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentMonth = tonumber(v[2]);
elseif (v[1] == "date_day_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentDay = tonumber(v[2]);
end
end
GAMEMODE.LastSaveYear = GAMEMODE.CurrentYear;
GAMEMODE.LastSaveMonth = GAMEMODE.CurrentMonth;
GAMEMODE.LastSaveDay = GAMEMODE.CurrentDay;
GAMEMODE.CurrentTemperature = (AVERAGE_TEMPERATURES[GAMEMODE.CurrentMonth][1] + AVERAGE_TEMPERATURES[GAMEMODE.CurrentMonth][2]) * .5;
SetGlobalInt("temp", GAMEMODE.CurrentTemperature);
Msg("Current in-game date: " .. GAMEMODE.CurrentMonth .. "/" .. GAMEMODE.CurrentDay .. "/" .. GAMEMODE.CurrentYear .. "\n");
GAMEMODE.CanSaveDate = true;
Msg("Date saving authorized.\n");
end);
SetGlobalInt("tv_status", 0);
end
[/CODE]
and I use the newest tmysql4 and got al the needed DLL's, but it keeps giving me this code:
[CODE]
[ERROR] gamemodes/perp/gamemode/sv_hooks.lua:4: attempt to call field 'query' (a nil value)
1. sendOnline - gamemodes/perp/gamemode/sv_hooks.lua:4
2. unknown - gamemodes/perp/gamemode/sv_hooks.lua:61
[/CODE]
Line 61 is the part I replaced : [CODE] database:Query(sendOnline());[/CODE]
1 Tip remove your DB Details.
[editline]26th December 2016[/editline]
And fast.
[QUOTE=TygoE;51585997]1 Tip remove your DB Details.
[editline]26th December 2016[/editline]
And fast.[/QUOTE]
I'm so dumb
I'll try a factory reset on my server and reinstall it, just because it worked before.
[QUOTE=DeNaamIsKoen;51588426]I'll try a factory reset on my server and reinstall it, just because it worked before.[/QUOTE]
Didn't work obviously.
[editline]27th December 2016[/editline]
[QUOTE=DeNaamIsKoen;51585749][editline]26th December 2016[/editline]
This is my current code:
[CODE]
function GM:Initialize ( )
Msg("Loading tmysql module... ");
require('tmysql');
if (tmysql) then
Msg("done!\n");
else
Msg("failed!\n");
end
self.ServerIdentifier = 1;
self.ServerDateIdentifier = 1;
self.numPlayers = 128;
self.ReservedSlots = 64;
self.Serious = true;
SQL_INFO_1 = ""; -- HOST
SQL_INFO_2 = ""; -- Username
SQL_INFO_3 = ""; -- Password
SQL_INFO_4 = ""; -- Database Name
local database, err = tmysql.initialize(SQL_INFO_1, SQL_INFO_2, SQL_INFO_3, SQL_INFO_4, 3306);
if not database then
print( err )
return
end
database:Query(sendOnline());
RunConsoleCommand("sv_visiblemaxplayers", self.numPlayers-self.ReservedSlots);
timer.Simple(1, function ( )
RunConsoleCommand("sv_allowdownload", "0");
RunConsoleCommand("sv_allowupload", "1");
RunConsoleCommand("sv_usermessage_maxsize", "5000");
RunConsoleCommand('lua_log_sv', '1');
RunConsoleCommand('net_maxfilesize', '64');
end);
SetGlobalInt("tax_sales", 5);
SetGlobalInt("tax_income", 5);
RunConsoleCommand("qcache_gamedesc", "");
RunConsoleCommand("sv_max_queries_window", "5");
self.IsSerious = (self.ServerIdentifier == 2);
self.HouseAlarms = {};
tmysql.query("SELECT `key`, `value` FROM `perp_system` WHERE `key`='date_year_" .. self.ServerDateIdentifier .. "' OR `key`='date_month_" .. self.ServerDateIdentifier .. "' OR `key`='date_day_" .. self.ServerDateIdentifier .. "'", function ( Whatever )
for k, v in pairs(Whatever) do
if (v[1] == "date_year_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentYear = tonumber(v[2]);
elseif (v[1] == "date_month_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentMonth = tonumber(v[2]);
elseif (v[1] == "date_day_" .. self.ServerDateIdentifier) then
GAMEMODE.CurrentDay = tonumber(v[2]);
end
end
GAMEMODE.LastSaveYear = GAMEMODE.CurrentYear;
GAMEMODE.LastSaveMonth = GAMEMODE.CurrentMonth;
GAMEMODE.LastSaveDay = GAMEMODE.CurrentDay;
GAMEMODE.CurrentTemperature = (AVERAGE_TEMPERATURES[GAMEMODE.CurrentMonth][1] + AVERAGE_TEMPERATURES[GAMEMODE.CurrentMonth][2]) * .5;
SetGlobalInt("temp", GAMEMODE.CurrentTemperature);
Msg("Current in-game date: " .. GAMEMODE.CurrentMonth .. "/" .. GAMEMODE.CurrentDay .. "/" .. GAMEMODE.CurrentYear .. "\n");
GAMEMODE.CanSaveDate = true;
Msg("Date saving authorized.\n");
end);
SetGlobalInt("tv_status", 0);
end
[/CODE]
and I use the newest tmysql4 and got al the needed DLL's, but it keeps giving me this code:
[CODE]
[ERROR] gamemodes/perp/gamemode/sv_hooks.lua:4: attempt to call field 'query' (a nil value)
1. sendOnline - gamemodes/perp/gamemode/sv_hooks.lua:4
2. unknown - gamemodes/perp/gamemode/sv_hooks.lua:61
[/CODE]
Line 61 is the part I replaced : [CODE] database:Query(sendOnline());[/CODE][/QUOTE]
Line 4 is [CODE]tmysql.query("UPDATE `perp_system` SET `value`='" .. os.time() .. "' WHERE `key`='online_" .. GAMEMODE.ServerIdentifier .. "' LIMIT 1");[/CODE]
I understand the majority of this community dislikes PERP, but I'm having a similar issue. Now that tmysql4 has been retired, I'm using mysqloo v9 with the tmysql wrapper and getting the following error.
[CODE][ERROR] gamemodes/rp/gamemode/sv_hooks.lua:77: attempt to index global 'database' (a nil value)
1. unknown - gamemodes/rp/gamemode/sv_hooks.lua:77[/CODE]
And the offending line of code is just here.
[CODE]database:Query("SELECT `key`, `value` FROM `rp_system` WHERE `key`='date_year_" .. GAMEMODE.ServerDateIdentifier .. "' OR `key`='date_month_" .. GAMEMODE.ServerDateIdentifier .. "' OR `key`='date_day_" .. GAMEMODE.ServerDateIdentifier .. "'", function ( Whatever )[/CODE]
And this is the function (forgive me if the terminology is wrong, my lua knowledge is extremely limited and assumed)
[CODE]local database, err = tmysql.initialize(SQL_INFO_1, SQL_INFO_2, SQL_INFO_3, SQL_INFO_4, 3306);
if not database then
print( err )
return
end[/CODE]
I didn't feel it was unrelated, seeing as it's the exact same issue. I'll go ahead and create a new thread.
Sorry, you need to Log In to post a reply to this thread.