Raised This Month: $51 Target: $400
 12% 

mysql table flag


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 08-11-2023 , 19:52   mysql table flag
Reply With Quote #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 00;

    
// 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_dbConnectsql);
    
execute_insert_multi_query(queries ,i);

    return 
PLUGIN_CONTINUE;
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
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_dbTapleercodeerrorcharsmax(error));
    
    if (
g_dbConnect == Empty_Handle)
        
server_print("[XP] Error No.%d: %s"ercodeerror);
    else 
    {
          
server_print("[XP] Connecting successful.");
          
init_database();
      }
    return 
PLUGIN_CONTINUE;

yagami is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-18-2023 , 09:46   Re: mysql table flag
Reply With Quote #2

Code:
    len += formatex(sql[len], MAX_QUERY_LENGTH - len, "  `delivered_flag`            BIGINT UNSIGNED     NOT NULL DEFAULT 0,");     len += formatex(sql[len], MAX_QUERY_LENGTH - len, "  `captured_flag`            BIGINT UNSIGNED     NOT NULL DEFAULT 0,");     len += formatex(sql[len], MAX_QUERY_LENGTH - len, "  `returned_flag`            BIGINT UNSIGNED     NOT NULL DEFAULT 0,");
I don't get it, it's basically copy-paste.

You still have to do some things in other parts of the plugin(s) to actually load, increase and save the number though.
If your table already exist you'd have to add the columns to it or recreate it from scratch.

Just as a side note, there's no point of actually using BIGINT UNSIGNED vs. INT (SIGNED) since AMXX doesn't have a data type over 32-bits and there's no way of choosing signed/unsigned.
__________________

Last edited by Black Rose; 09-04-2023 at 14:52.
Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode