Author Topic: Simple LUA Assistance: Chat Log / gm_sql  (Read 3705 times)

0 Members and 1 Guest are viewing this topic.

Offline Pantho

  • Newbie
  • *
  • Posts: 39
  • Karma: 2
Simple LUA Assistance: Chat Log / gm_sql
« on: December 04, 2009, 07:32:32 PM »
Code: [Select]
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);
LUA file location and file name
addons/Glogs/lua/autorun/Glogs_init.lua

Code: [Select]
"AddonInfo"
{
"name" "Glogs"
"version" "0.1"
"author_name" "Pantho"
"info" "bybservers.co.uk Glogs"
"override" "0"
}
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!

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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Simple LUA Assistance: Chat Log / gm_sql
« Reply #1 on: December 04, 2009, 08:30:27 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Pantho

  • Newbie
  • *
  • Posts: 39
  • Karma: 2
Re: Simple LUA Assistance: Chat Log / gm_sql
« Reply #2 on: December 05, 2009, 09:09:44 AM »
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.