Save Ammo Packs Sql

Pluginuri pentru modul AmxModX.

Moderators: Moderatori ajutatori, Moderatori, Echipa eXtreamCS.com

Post Reply
User avatar
Rainq
Membru, skill +2
Membru, skill +2
Posts: 681
Joined: 21 Jul 2015, 19:50
Detinator Steam: Da
CS Status: Retras
Detinator server CS: zm.extreamcs.com
SteamID: mrainq
Reputatie: Fost super moderator
Fost detinator ZM.eXtreamCS.COM
Fost Membru Club eXtreamCS (trei luni)
Fond eXtream: 0
Location: Bucharest
Discord: manuraiders
Has thanked: 29 times
Been thanked: 51 times
Contact:

19 Mar 2021, 10:36

Image
Descriere: Banca de ammo

Descarcare:

Code: Select all

#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <zombieplague>

#define PLUGIN "Zombie Prevolution : Save Ammo Packs"
#define VERSION "1.0.0"
#define AUTHOR "Kia"

// ===============================================================================
//     Editing begins here
// ===============================================================================

// Add SQL Data here

new Host[]        = ""
new User[]        = ""
new Pass[]        = ""
new Db[]       = ""

// ===============================================================================
//     and stops here. DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
// ===============================================================================

// ===============================================================================
//     Variables
// ===============================================================================

/* Booleans */

new bool:g_authed[33]
new bool:g_sql_ready = false
new bool:g_loaded[33]

/* Handler */

new Handle:g_SqlConnection
new Handle:g_SqlTuple

/* Strings */

new g_Error[512]

/* Integer */

new maxplayers;

// ===============================================================================
//     plugin_init
// ===============================================================================

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	    
	/* SQL */
	    
	maxplayers = get_maxplayers()
	set_task(0.1, "MySql_Init")
}

// ===============================================================================
//     client_putinserver - Called when a player joins the Server
// ===============================================================================

public client_putinserver(id)
{
	g_authed[id] = true
	Load_MySql(id)
}

// ===============================================================================
//     client_disconnect - Called when a player leaves the Server
// ===============================================================================

public client_disconnect(id)
{
	Save_MySql(id)
}

// ===============================================================================
//     SQL
// ===============================================================================

public MySql_Init()
{
	// we tell the API that this is the information we want to connect to,
	// just not yet. basically it's like storing it in global variables
	g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
	    
	// ok, we're ready to connect
	new ErrorCode
	g_SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
	if(g_SqlConnection == Empty_Handle)
	{
		 // stop the plugin with an error message
		set_fail_state(g_Error)
	}
	    
	new Handle:Queries
	// we must now prepare some random queries
	Queries = SQL_PrepareQuery(g_SqlConnection,"CREATE TABLE IF NOT EXISTS zpre_ap (name varchar(64), ap INT(11))")
	    
	if(!SQL_Execute(Queries))
	{
		// if there were any problems
		SQL_QueryError(Queries,g_Error,charsmax(g_Error))
		set_fail_state(g_Error)
	}
	    
	// close the handle
	SQL_FreeHandle(Queries)
	    
	g_sql_ready = true
	for(new i=1; i<=maxplayers; i++)
	{
		if(g_authed[i])
		{
			Load_MySql(i)
		}
	}
}

public Load_MySql(id)
{
	if(g_sql_ready)
	{
		if(g_SqlTuple == Empty_Handle)
		{
			set_fail_state(g_Error)
		}
		
		new szPlayerName[32], szQuotedName[64], szTemp[512]
		get_user_name(id, szPlayerName, charsmax(szPlayerName))
		SQL_QuoteString(g_SqlConnection, szQuotedName, charsmax(szQuotedName), szPlayerName)
		new Data[1]
		Data[0] = id
			
		//we will now select from the table `furienmoney` where the steamid match
		format(szTemp,charsmax(szTemp),"SELECT * FROM `zpre_ap` WHERE `name` = '%s'", szQuotedName)
		SQL_ThreadQuery(g_SqlTuple,"register_client", szTemp, Data,1)
	}
}

public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
	if(FailState == TQUERY_CONNECT_FAILED)
	{
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	}
	else if(FailState == TQUERY_QUERY_FAILED)
	{
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	}
	new id
	id = Data[0]
	if(SQL_NumResults(Query) < 1)
	{
		//.if there are no results found
			
		new szName[32], szQuotedName[64]
		get_user_name(id, szName, 31) // get user's name
		SQL_QuoteString(g_SqlConnection, szQuotedName, 63, szName)
			
		new szTemp[512]
			
		// now we will insert the values into our table.
		format(szTemp,charsmax(szTemp),"INSERT INTO `zpre_ap` VALUES ('%s','0');", szQuotedName)
		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
	}
	else
	{
		// if there are results found
		zp_set_user_ammo_packs(id, SQL_ReadResult(Query, 1))
	}
	g_loaded[id] = true
	return PLUGIN_HANDLED
}

public Save_MySql(id)
{
	if(g_loaded[id])
	{
		new szTemp[512], szName[32], szQuotedName[64]
		get_user_name(id, szName, 31)
		SQL_QuoteString(g_SqlConnection, szQuotedName, 63, szName)
			
		// Here we will update the user hes information in the database where the steamid matches.
		format(szTemp,charsmax(szTemp),"UPDATE `zpre_ap` SET `ap` = '%i' WHERE `name` = '%s';", zp_get_user_ammo_packs(id), szQuotedName)
		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
	}
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
	SQL_FreeHandle(Query)
	    
	return PLUGIN_HANDLED
}

public plugin_end()
{
	if(g_SqlConnection != Empty_Handle)
	{
		SQL_FreeHandle(g_SqlConnection) //free connection handle here
	}
}
Nume: Save Ammo Packs
Versiune: 1.0.0
Link oficial: -

Instalare:
1. Fisierul auto_saveap_sql.sma il puneti in addons/amxmodx/scripting
2. Fisierul auto_saveap_sql.amxx il puneti in addons/amxmodx/plugins
3. Intrati in fisierul addons/amxmodx/configs/plugins.ini si adaugati la urma:

Code: Select all

auto_saveap_sql.amxx
4. Alti pasi necesari....

Cvar-uri (se adauga in fisierul amxmodx\configs\amxx.cfg): -



Imagini: -
Image
RoyalServer 2
Zpp.Mihai94
Membru, skill 0
Membru, skill 0
Posts: 95
Joined: 05 Feb 2018, 13:03
Detinator Steam: Da
CS Status: ZMXP
Detinator server CS: ZMXP.WESTCSTRIKE.RO
Fond eXtream: 0
Has thanked: 4 times
Been thanked: 1 time
Contact:

06 Jan 2023, 16:18

e buna banca, nu are probleme cu salvarea de credite?
Zpp.Mihai94
Membru, skill 0
Membru, skill 0
Posts: 95
Joined: 05 Feb 2018, 13:03
Detinator Steam: Da
CS Status: ZMXP
Detinator server CS: ZMXP.WESTCSTRIKE.RO
Fond eXtream: 0
Has thanked: 4 times
Been thanked: 1 time
Contact:

06 Jan 2023, 23:13

Rainq wrote:
06 Jan 2023, 17:00
Zpp.Mihai94 wrote:
06 Jan 2023, 16:18
e buna banca, nu are probleme cu salvarea de credite?
daca apar probleme ,lasa in topic ,nu au fost probleme la mine
azi am pus-o pe server ca cealalta nu salva bine, sper sa fie ok.

numai ca imi da eroarea asta in logs

Code: Select all

L 01/06/2023 - 23:02:12: [AMXX] Run time error 25 (plugin "zp_bank_save_credite.amxx") - debug not enabled!
L 01/06/2023 - 23:02:12: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 01/06/2023 - 23:05:51: String formatted incorrectly - parameter 5 (total 4)
Zpp.Mihai94
Membru, skill 0
Membru, skill 0
Posts: 95
Joined: 05 Feb 2018, 13:03
Detinator Steam: Da
CS Status: ZMXP
Detinator server CS: ZMXP.WESTCSTRIKE.RO
Fond eXtream: 0
Has thanked: 4 times
Been thanked: 1 time
Contact:

07 Jan 2023, 00:49

Rainq wrote:
06 Jan 2023, 23:46
pune debug la sfarsit
am rezolvat.
Post Reply

Return to “AmxModX”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests