General > Developers Corner

Simple LUA Assistance: Chat Log / gm_sql

(1/1)

Pantho:

--- Code: ---require( "mysql" )
function PlayerSpoke(ply, saywhat)
local message = {};
message[1] = tostring(ply:Nick());
message[2] = tostring(ply:SteamID());
message[3] = tostring(ply:IPAddress());
message[4] = saywhat; 
message[5] = string.gsub(message[4],"'","");
message[6] = (os.date("%x"));
message[7] = (os.date("%X"));

local db, error = mysql.connect("xt","x","x", "x")
print(tostring(error) .. "\n")
print("connection opened - " .. db .. "!\n"); 
MySQLQuery = "INSERT INTO GLogs (Name,SteamID,IP,Text,Date,Time) VALUES('" .. message[1] .. "','" .. message[2] .. "','" .. message[3] .."','" .. message[5] .. "','" .. message[6] .. "','" .. message[7] .. "')"

test, isok, error = mysql.query(db, MySQLQuery); 
if (test) then 
print("");
end   
if (!isok) then 
    print(tostring(error) .. "\n"); 
end
end
hook.Add("PlayerSay", 1, PlayerSpoke);
--- End code ---
LUA file location and file name
addons/Glogs/lua/autorun/Glogs_init.lua


--- Code: ---"AddonInfo"
{
"name" "Glogs"
"version" "0.1"
"author_name" "Pantho"
"info" "bybservers.co.uk Glogs"
"override" "0"
}

--- End code ---
addons/glogs/info.txt

I am trying to make a quick server side script to upload the chat logs. The issue I am having is the following:

It works perfectly in single player, but im MP dedicated server I get:


--- Quote ---03:24:46 L 12/05/2009 - 03:24:43: Lua Error: ERROR: GAMEMODE:'PlayerSay' Failed: attempt to compare string with number
03:24:46 L 12/05/2009 - 03:24:43: Lua Error: Error: hook->PlayerSay returned a non-string!

--- End quote ---

I posted this on facepunch, but here forums remind me of 4chan with less intellect. If anyone here could lend assistance it would be appreciated. Script seems simple enough, Just cannot understand why it works in single player and not on a dedicated server.

JamminR:
http://wiki.garrysmod.com/?title=Hook.Add
hook.Add expects the unique name (parameter #2, which your passing a 1 with no quotes) to be a string.
Try changing 1 to "1"
Better yet, to avoid confusing Lua all together, change it to an actual name "glog" or some such.

I see other possible issues that may occur, but for now, will let you test from there on out and learn if there are any.

Pantho:
Thanks I am going to test the change soon as my test server installs.

I let a guy run the servers for me as I don't play anymore, and kinda pissed him off last night breaking the server with it.

Navigation

[0] Message Index

Go to full version