Senior Member
|
08-11-2023
, 19:52
mysql table flag
|
#1
|
Good evening, I am Yagami and I am currently trying to create a rank system with rank that shows the rank of players because until then most of the ranks are simple
I have a small doubt, I play capture the flag
I will need to create table for 3 flag? delivered, captured, returned?
I am using several plugins to base me because I know nothing mysql
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <geoip>
#include <sqlx>
#include <hamsandwich>
#define PLUGIN "Rank Patente"
#define VERSION "9.0"
#define AUTHOR "Yag"
#define MAX_QUERY_LENGTH 2048
#define MAX_LENGTH 128
#define MAX_ERR_LENGTH 512
#define ENTRY_XP 6200
enum _:CVAR_LIST
{
C_XP_KILL_NORMAL,
C_XP_KILL_KNIFE,
C_XP_KILL_HS,
C_XP_KILL_HE,
C_XP_FLAG_RECUPERED,
C_XP_FLAG_STOLEN,
C_XP_FLAG_CAPTURED
}
enum DB_CONFIG
{
DB_HOST[MAX_LENGTH],
DB_USER[MAX_LENGTH],
DB_PASS[MAX_LENGTH],
DB_NAME[MAX_LENGTH]
}
// Player Cvars
new iPlayerXP[MAX_PLAYERS+1], iPlayerLevel[MAX_PLAYERS+1], iPlayerRank[MAX_PLAYERS+1]
new g_Cvar[CVAR_LIST]
new iFloat:iDamageDone[MAX_PLAYERS+1]
//Database Handles
new Handle:g_dbTaple;
new Handle:g_dbConnect;
//Database setting
new g_dbConfig[DB_CONFIG];
new g_dbError[MAX_ERR_LENGTH];
new xMaxPlayers
new bool:iFirstSpawn[MAX_PLAYERS+1];
init_database()
{
new sql[MAX_QUERY_LENGTH + 1];
new Handle:queries[10];
new len = 0, i = 0;
// Aqui cria tabela na user_info.
len = 0;
sql = "";
len += formatex(sql[len], MAX_QUERY_LENGTH - len, "CREATE TABLE IF NOT EXISTS `%s`.`t_rank`", g_dbConfig[DB_NAME]);
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " (`auth_id` VARCHAR(%d) NOT NULL,", MAX_AUTHID_LENGTH);
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `latest_ip` VARCHAR(%d) NOT NULL,", MAX_IP_LENGTH);
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `online_time` BIGINT UNSIGNED DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `level` BIGINT UNSIGNED NOT NULL DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `xp` BIGINT UNSIGNED NOT NULL DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `kills` BIGINT UNSIGNED NOT NULL DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `deaths` BIGINT UNSIGNED NOT NULL DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `flag` BIGINT UNSIGNED NOT NULL DEFAULT 0,");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " PRIMARY KEY (`auth_id`)");
len += formatex(sql[len], MAX_QUERY_LENGTH - len, " );");
queries[i++] = SQL_PrepareQuery(g_dbConnect, sql);
execute_insert_multi_query(queries ,i);
return PLUGIN_CONTINUE;
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("xp", "iComandMenu")
set_task(1.0, "plugin_core");
}
public plugin_core()
{
new error[MAX_ERR_LENGTH + 1];
new ercode;
// Get Database Configs.
get_cvar_string("amx_sql_host", g_dbConfig[DB_HOST], charsmax(g_dbConfig[DB_HOST]));
get_cvar_string("amx_sql_user", g_dbConfig[DB_USER], charsmax(g_dbConfig[DB_USER]));
get_cvar_string("amx_sql_pass", g_dbConfig[DB_PASS], charsmax(g_dbConfig[DB_PASS]));
get_cvar_string("amx_sql_db", g_dbConfig[DB_NAME], charsmax(g_dbConfig[DB_NAME]));
g_dbTaple = SQL_MakeDbTuple(
g_dbConfig[DB_HOST],
g_dbConfig[DB_USER],
g_dbConfig[DB_PASS],
g_dbConfig[DB_NAME]
);
g_dbConnect = SQL_Connect(g_dbTaple, ercode, error, charsmax(error));
if (g_dbConnect == Empty_Handle)
server_print("[XP] Error No.%d: %s", ercode, error);
else
{
server_print("[XP] Connecting successful.");
init_database();
}
return PLUGIN_CONTINUE;
}
|
|