Ok i try and put it in debug mode now im getting:
Code:
L 01/13/2007 - 06:51:49: Start of error session.
L 01/13/2007 - 06:51:49: Info (map "de_aztec") (logfile "error_011307.log")
L 01/13/2007 - 06:51:49: [SQLITE] Invalid DBI result handle -1
L 01/13/2007 - 06:51:49: [AMXX] Run time error 10 (plugin "banbot.amxx") (native "dbi_free_result") - debug not enabled!
L 01/13/2007 - 06:51:49: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
Quote:
Originally Posted by Brad
Post your entire script please.
|
Code:
#include <amxmodx>
#include <amxmisc>
#include <dbi>
#define PLUGIN "MySQL Example"
#define VERSION "1.0"
#define AUTHOR "Sphinx"
//The MySQL DataBase Connection.
new Sql:dbc
//The result, it tells us if the command/query worked and such
//Used like this
//"result = dbi_query(dbc, "The command sent to the database")
new Result:result
//We need to check to see if the player is new, so we have this.
//If its 0 that means he is completely new to the server
//If its above 0 that means he has a recorded time.
new g_ConnectTime[33]
//What we are using the MySQL database for, storing the information
//You can alter this anyway you like.
new g_PlayerInfo[33]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
//Initializes the connection
set_task(0.1,"sql_init")
}
public client_disconnect(id) {
//Checks to make sure we have a connection, if we don't then don't continue.
if (dbc == SQL_FAILED) {
return PLUGIN_HANDLED;
}
//We need to retrieve the Steamid
new authid[32]
get_user_authid(id,authid,31)
//We retrieve how long they have been on the server, on this connection.
//It will get stored into ConnectTime,
new playtime = get_user_time (id)
//This one will check to see that the player has a entry set up. It will just echo in the
//The database as "Empty Set" if he doesn't have one, so its harmless to have if he doesn't have
//A slot.
result = dbi_query(dbc,"SELECT * FROM tablename WHERE steamid = '%s'",authid)
if (result == RESULT_FAILED) {
log_amx("[MySQL Test] MySQL Query Failed!!")
return PLUGIN_CONTINUE
// It failed for some reason, probably becuase DBC failed.
}
// We were talking about this earlier, 0 means create a fresh entry.
else if (g_ConnectTime[id]== 0) {
//This tells the database to create an entry, storing the players steamid, connect time, and w/e else you want.
result = dbi_query(dbc,"INSERT INTO tablename (steamid, connecttime, playerinfo) values ('%s',%i,%i)",authid,playtime,g_PlayerInfo[id])
}
else {
//So we add this connection with the overall ConnectTime
new store_time = (playtime + g_ConnectTime[id])
result = dbi_query(dbc,"UPDATE tablename SET connecttime='%i'. playerinfo='%i' WHERE steamid='%s'",store_time,g_PlayerInfo[id],authid)
}
// We have to free the result, so it can save properly.
dbi_free_result(result);
return PLUGIN_CONTINUE;
}
public client_authorized(id) {
if (dbc == SQL_FAILED) {
return PLUGIN_HANDLED;
}
new authid[32]
get_user_authid(id,authid,31)
result = dbi_query(dbc,"SELECT * FROM tablename WHERE steamid = '%s'",authid)
if (result == RESULT_FAILED) {
log_amx("[MySQL Test] MySQL Query Failed!!")
return PLUGIN_CONTINUE // Query failed! Sorry :P
}
// If he doesn't have a entry, we shall put up the defualts.
else if (result == RESULT_NONE) {
g_ConnectTime[id] = 0
g_PlayerInfo[id] = 0
}
else {
dbi_nextrow(result) // This retrieves data from your entry.
//Loads up the recorded connect time, so we can tell that they have been on the server before
g_ConnectTime[id] = dbi_result(result,"connecttime")
//Loads up the information you stored last time they played.
g_PlayerInfo[id] = dbi_result(result, "playerinfo")
}
// You MUST free the result!
dbi_free_result(result)
return PLUGIN_HANDLED;
}
public sql_init() {
new error[256]
// The database connection, cvars work here too.
dbc = dbi_connect("deasdfnp.silvsdfa-hsdostisdfgng.com", "deanpsdf_banbot", "rsdgdfg", "deandfsp_banbot", error,255)
if (dbc == SQL_FAILED) {
log_amx("[MySQL Test] SQL Connection Failed = %s", error)
}
else {
//You don't have to do this, I just recommend it if you are going to make your plugin public.
//This will Create a table to store the information to, with the proper values.
dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `tablename` (`steamid` VARCHAR(32) NOT NULL,`connecttime` INT NOT NULL,`playerinfo` INT NOT NULL, PRIMARY KEY(`steamid`))")
}
}
public plugin_end() {
// Close the connection
dbi_close(dbc);
}