AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Level rank plugin Help (https://forums.alliedmods.net/showthread.php?t=283208)

cristianronaldo 05-27-2016 16:47

Level rank plugin Help
 
Hello,i need a plugin for block players join to my server,if they dont have 1000 points or more.This points are extracted from a MySql DB.Thanks I really appreciate help
@EasSidezz help!!!

cristianronaldo 05-27-2016 19:07

Re: Level rank plugin Help
 
1 Attachment(s)
@EasSidezz
I have making this plugin,but i need help
See the .sp
This semi-plugin is for the players can know his points.

sdz 05-29-2016 10:55

Re: Level rank plugin Help
 
Someone mentioned you were looking for me, lol.
Well you'll want to look into threading your SQL Queries, because running nonthreaded queries will lag the almighty hell out of your server.

-SQL_TConnect
-SQL_TQuery

I can give you some example database code of how it should be looking..

PHP Code:

#include <sourcemod>

enum Player_Data
{    
    
String:SteamID[32],
    
Money,
    
Bank,
};
new 
g_playerData[MAXPLAYERS 1][Player_Data]

new 
Handle:dbConnection INVALID_HANDLE;

public 
OnPluginStart()
{
    
SQL_TConnect(connectCB"database");
}

//We'll use something similar to this if we want to load data
public connectCB(Handle:ownerHandle:child, const String:error[], any:data)
{
    if(
child == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
PrintToServer("[ERROR] >> %s"error);
        
SQL_TConnect(connectCB"db");
        return;
    }

    
dbConnection child;
    
PrintToServer(">> Connected to MySQL Database! :D :D");
    return;
}

//Standard, non customized callback for queries of which do not return results
public sql_Callback(Handle:queryHandle:child, const String:error[], any:data)
{
    if(
query == INVALID_HANDLE || child == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
return;
    }
}

public 
OnClientPutInServer(client)
{
    
GetClientAuthId(clientAuthId_Steam3g_playerData[client][SteamID], 32);

    
decl String:query[256];
    
Format(querysizeof(query), "SELECT * FROM player_stats WHERE steam_id = '%s'"g_playerData[Client][SteamID]);
    
SQL_TQuery(dbConnectionsql_LoadqueryGetClientUserId(Client));
}

public 
sql_Load(Handle:nothingHandle:result, const String:error[], any:data)
{
    new 
Client GetClientOfUserId(data)
    if(
IsFakeClient(Client))
    {
        return;
    }

    if(
Client == 0)
    {
        return;
    }

    if(
result == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
return;
    }

    
//Load Stats
    
if(!SQL_GetRowCount(result))
    {
        
decl String:query[256];
        
Format(querysizeof(query), "INSERT INTO player_stats (steam_id) VALUES ('%s');"g_playerData[Client][SteamID]);
        
SQL_TQuery(sqlDBsqlQueryquery);
        
PrintToChat(Client"Data not found for you, so we'll set you up with an account..");
    }
    else if(
SQL_FetchRow(result))
    {
        
g_playerData[Client][Money] = SQL_FetchInt(result1);
        
g_playerData[Client][Bank] = SQL_FetchInt(result2);
    }


That's generally how you'll want to approach this

cristianronaldo 05-29-2016 12:39

Re: Level rank plugin Help
 
Quote:

Originally Posted by EasSidezz (Post 2422973)
Someone mentioned you were looking for me, lol.
Well you'll want to look into threading your SQL Queries, because running nonthreaded queries will lag the almighty hell out of your server.

-SQL_TConnect
-SQL_TQuery

I can give you some example database code of how it should be looking..

PHP Code:

#include <sourcemod>

enum Player_Data
{    
    
String:SteamID[32],
    
Money,
    
Bank,
};
new 
g_playerData[MAXPLAYERS 1][Player_Data]

new 
Handle:dbConnection INVALID_HANDLE;

public 
OnPluginStart()
{
    
SQL_TConnect(connectCB"database");
}

//We'll use something similar to this if we want to load data
public connectCB(Handle:ownerHandle:child, const String:error[], any:data)
{
    if(
child == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
PrintToServer("[ERROR] >> %s"error);
        
SQL_TConnect(connectCB"db");
        return;
    }

    
dbConnection child;
    
PrintToServer(">> Connected to MySQL Database! :D :D");
    return;
}

//Standard, non customized callback for queries of which do not return results
public sql_Callback(Handle:queryHandle:child, const String:error[], any:data)
{
    if(
query == INVALID_HANDLE || child == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
return;
    }
}

public 
OnClientPutInServer(client)
{
    
GetClientAuthId(clientAuthId_Steam3g_playerData[client][SteamID], 32);

    
decl String:query[256];
    
Format(querysizeof(query), "SELECT * FROM player_stats WHERE steam_id = '%s'"g_playerData[Client][SteamID]);
    
SQL_TQuery(dbConnectionsql_LoadqueryGetClientUserId(Client));
}

public 
sql_Load(Handle:nothingHandle:result, const String:error[], any:data)
{
    new 
Client GetClientOfUserId(data)
    if(
IsFakeClient(Client))
    {
        return;
    }

    if(
Client == 0)
    {
        return;
    }

    if(
result == INVALID_HANDLE)
    {
        
LogError("[ERROR] >> %s"error); //Error Preface
        
return;
    }

    
//Load Stats
    
if(!SQL_GetRowCount(result))
    {
        
decl String:query[256];
        
Format(querysizeof(query), "INSERT INTO player_stats (steam_id) VALUES ('%s');"g_playerData[Client][SteamID]);
        
SQL_TQuery(sqlDBsqlQueryquery);
        
PrintToChat(Client"\x01\x04[RP]\x10 Data not found for you, so we'll set you up with an account..");
    }
    else if(
SQL_FetchRow(result))
    {
        
g_playerData[Client][Money] = SQL_FetchInt(result1);
        
g_playerData[Client][Bank] = SQL_FetchInt(result2);
    }


That's generally how you'll want to approach this

Thanks, I'll try and then upload the code

ElaMeMamou 05-29-2016 15:00

Re: Level rank plugin Help
 
hey there we want the samething.. if you had success please share..

https://forums.alliedmods.net/showthread.php?p=2423049


thank you

cristianronaldo 05-29-2016 20:23

Re: Level rank plugin Help
 
Quote:

Originally Posted by ElaMeMamou (Post 2423051)
hey there we want the samething.. if you had success please share..

https://forums.alliedmods.net/showthread.php?p=2423049


thank you

hello bro.i need extract the score from Mysql Database,and them if player dont have the minimum score for entry to this server,the server kick him.

Jackol1234 05-30-2016 00:46

Re: Level rank plugin Help
 
I threw this together. Can't guarantee that it'll work, but it did compile:

PHP Code:

#include <ckSurf>

#pragma semicolon 1

#define PLUGIN_VERSION "0.1"

public Plugin:myinfo =
{
    
name "ckSurf Kicker",
    
author "DeweY",
    
version PLUGIN_VERSION,
    
description "Kicks clients with 1000 points or more.",
    
url "http://Omegagaming.org/"
};

Handle g_hDatabase null;

char g_sSteamID[MAXPLAYERS+1][64];

public 
void OnPluginStart()
{
    
SQL_TConnect(SQLCallback_Connect"ckSurf");
}

public 
SQLCallback_Connect(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == null)
    {
        
SetFailState("Error connecting to database. %s"error);
    }

    
g_hDatabase hndl;
}

public 
void OnClientPostAdminCheck(client)
{
    
GetClientAuthId(clientAuthId_SteamID64g_sSteamID[client], sizeof(g_sSteamID[]));
    
CheckRank(client);
}

public 
CheckRank(int client)
{
    
char query[255];
    
Format(query255"SELECT `points` FROM `ck_playerrank` WHERE `steamid`='%s' LIMIT 1"g_sSteamID[client]);
    
SQL_TQuery(g_hDatabaseSQLCallback_LoadPlayerPointsqueryGetClientUserId(client));
}

public 
SQLCallback_LoadPlayerPoints(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == null)
    {
        
SetFailState("Error grabbing player points. %s"error);
    }

    
int client GetClientOfUserId(data);


    if (
SQL_GetRowCount(hndl) == 1)
    {
        
SQL_FetchRow(hndl);
        
int playerpoints SQL_FetchInt(hndl0);
        if (
playerpoints >= 1000)
        {
            
KickClient(client"This server is for beginners.");
        }
    }


EDIT: I now see this isn't for ckSurf, but it should still work for what you're trying to do just change the connecting database and also the SQL format line.

cristianronaldo 05-30-2016 06:47

Re: Level rank plugin Help
 
Quote:

Originally Posted by Jackol1234 (Post 2423141)
I threw this together. Can't guarantee that it'll work, but it did compile:

PHP Code:

#include <ckSurf>

#pragma semicolon 1

#define PLUGIN_VERSION "0.1"

public Plugin:myinfo =
{
    
name "ckSurf Kicker",
    
author "DeweY",
    
version PLUGIN_VERSION,
    
description "Kicks clients with 1000 points or more.",
    
url "http://Omegagaming.org/"
};

Handle g_hDatabase null;

char g_sSteamID[MAXPLAYERS+1][64];

public 
void OnPluginStart()
{
    
SQL_TConnect(SQLCallback_Connect"ckSurf");
}

public 
SQLCallback_Connect(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == null)
    {
        
SetFailState("Error connecting to database. %s"error);
    }

    
g_hDatabase hndl;
}

public 
void OnClientPostAdminCheck(client)
{
    
GetClientAuthId(clientAuthId_SteamID64g_sSteamID[client], sizeof(g_sSteamID[]));
    
CheckRank(client);
}

public 
CheckRank(int client)
{
    
char query[255];
    
Format(query255"SELECT `points` FROM `ck_playerrank` WHERE `steamid`='%s' LIMIT 1"g_sSteamID[client]);
    
SQL_TQuery(g_hDatabaseSQLCallback_LoadPlayerPointsqueryGetClientUserId(client));
}

public 
SQLCallback_LoadPlayerPoints(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == null)
    {
        
SetFailState("Error grabbing player points. %s"error);
    }

    
int client GetClientOfUserId(data);


    if (
SQL_GetRowCount(hndl) == 1)
    {
        
SQL_FetchRow(hndl);
        
int playerpoints SQL_FetchInt(hndl0);
        if (
playerpoints >= 1000)
        {
            
KickClient(client"This server is for beginners.");
        }
    }


EDIT: I now see this isn't for ckSurf, but it should still work for what you're trying to do just change the connecting database and also the SQL format line.

It work!!!!!!Thanks.I need to make a explode, because in my DB the steam are saved only with the numbers, that is, not saved STEAM_1: xxxxx .you could make explode the steam will select only the DB part of the numbers?Thanks

Jackol1234 05-30-2016 15:08

Re: Level rank plugin Help
 
Quote:

Originally Posted by cristianronaldo (Post 2423197)
It work!!!!!!Thanks.I need to make a explode, because in my DB the steam are saved only with the numbers, that is, not saved STEAM_1: xxxxx .you could make explode the steam will select only the DB part of the numbers?Thanks

This should do what you're looking for. Change OnClientPostADmincheck to this:

PHP Code:

public void OnClientPostAdminCheck(client

    
CheckRank(client); 


And add this to CheckRank:

PHP Code:

public CheckRank(int client)
{
    
char query[255];
    
char SteamID[32];
    
GetClientAuthId(clientAuthId_Steam2SteamID32);
    
Format(query255"SELECT `points` FROM `ck_playerrank` WHERE `steamid`='%s' LIMIT 1"g_sSteamID[10]);
    
SQL_TQuery(g_hDatabaseSQLCallback_LoadPlayerPointsqueryGetClientUserId(client));


Then of course remove "char g_sSteamID[MAXPLAYERS+1][64];" at the top of the plugin since it isn't global anymore.

cristianronaldo 05-30-2016 20:39

Re: Level rank plugin Help
 
1 Attachment(s)
Quote:

Originally Posted by Jackol1234 (Post 2423316)
This should do what you're looking for. Change OnClientPostADmincheck to this:

PHP Code:

public void OnClientPostAdminCheck(client

    
CheckRank(client); 


And add this to CheckRank:

PHP Code:

public CheckRank(int client)
{
    
char query[255];
    
char SteamID[32];
    
GetClientAuthId(clientAuthId_Steam2SteamID32);
    
Format(query255"SELECT `points` FROM `ck_playerrank` WHERE `steamid`='%s' LIMIT 1"g_sSteamID[10]);
    
SQL_TQuery(g_hDatabaseSQLCallback_LoadPlayerPointsqueryGetClientUserId(client));


Then of course remove "char g_sSteamID[MAXPLAYERS+1][64];" at the top of the plugin since it isn't global anymore.

This will be just like that.does not fail,But dont work.Please check it.Thanks!!!!!!!


All times are GMT -4. The time now is 22:26.

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