Since McFluffy is offline for awhile and I don't know how to contact to him , so I decided to move on and add some Database stuff into his code and try to make his famous PointSystem work with database.
Link :
https://forums.alliedmods.net/showthread.php?p=1257852
The compiler is fine , just some warning and not fatal error or error
The database setup is quite fine too , but when put the smx to plugin folder , the plugins did not create any tables in database.
Any suggestion will be welcome.
Thanks
PHP Code:
//DATABASE
//Database handle
new Handle:db = INVALID_HANDLE;
//Database configuration name convar
new Handle:g_hDbConfName;
//DATABASE_CONVAR
g_hDbConfName = CreateConVar(
"l4d_pointsys_db_conf_name" ,
"default" ,
"The DB connection configuration read from databases.cfg." ,
FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY );
//=============================
// DATABASE
//=============================
//create database connection
public ConnectDB()
{
new String:confname[32];
GetConVarString(g_hDbConfName, confname, sizeof(confname));
if (SQL_CheckConfig(confname))
{
new String:error[256];
db = SQL_Connect(confname, true, error, sizeof(error));
if (db == INVALID_HANDLE)
LogError("Failed to connect to database: %s", error);
else
InitDB(); //Initialize database
}
else
LogError("Database.cfg missing '%s' entry!", confname);
}
//create table if necessary
public InitDB()
{
new String:error[256], String:query[1024];
Format(query, sizeof(query), "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
"CREATE TABLE IF NOT EXISTS `Syspoints` (",
" `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,",
" `steamid` VARCHAR(32) NOT NULL,",
" `CPoint` TINYINT NOT NULL,",
" INDEX (`id`),",
" INDEX (`steamid`))",
" DEFAULT CHARSET=utf8",
";"
);
if (!SQL_FastQuery(db, query))
{
if (SQL_GetError(db, error, sizeof(error)))
LogError("Failed to create table: %s", error);
else
LogError("Failed to create table: unknown");
}
}
//get default values for connected player
public Start(client)
{
if (db == INVALID_HANDLE)
{
points[client] = GetConVarInt(StartPoints);
return;
}
new String:authid[32];
GetClientAuthString(client, authid, sizeof(authid));
decl String:query[256];
Format(query, sizeof(query), "SELECT CPoint FROM Syspoints WHERE steamid = '%s'", authid);
SQL_TQuery(db, SQLPS_GetPoints, query, client);
}
//callback from SaveDefault
public SQLPS_GetPoints(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
LogError("SQLPS_GetPoints / error = \"%s\"", error);
return;
}
new String:authid[32], String:query[256];
if (SQL_GetRowCount(hndl) > 0)
{
GetClientAuthString(data, authid, sizeof(authid));
Format(query, sizeof(query), "UPDATE Syspoints SET CPoints = '%d' WHERE steamid = '%s'", points[data], authid);
}
else
{
GetClientAuthString(data, authid, sizeof(authid));
Format(query, sizeof(query), "INSERT INTO Syspoints (CPoints, steamid) VALUES ('%d')", points[data], authid);
}
CloseHandle(hndl);
SQL_TQuery(db, SQLPS_GetPointsFinalize, query);
}
//callback from SQLSaveDefault
public SQLPS_GetPointsFinalize(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
LogError("SQLPS_GetPointsFinalize / error = \"%s\"", error);
return;
}
CloseHandle(hndl);
}