Raised This Month: $ Target: $400
 0% 

Error SQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LeoLS
Junior Member
Join Date: Sep 2016
Old 09-07-2016 , 17:59   Error SQL
Reply With Quote #1

Got this plugin, but has this error in loading:

L 09/07/2016 - 18:13:40: [AMXX] Plugin ("tickets.amxx") is setting itself as failed.
L 09/07/2016 - 18:13:40: [AMXX] Plugin says: Database error. Please check it before running the plugin.
L 09/07/2016 - 18:13:40: [AMXX] Run time error 1 (plugin "tickets.amxx") - forced exit

Plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <zombieplague>
#include <sqlx>

#define PLUGIN "SuperHero Tickets"
#define VERSION "1.0"
#define AUTHOR "TheWalker"
#define LOGFILE	"superhero_tickets.log"

new TotalPlayedTime[33]

new Handle:tuple

// new host[] = "host", user[] = "user", pass[] = "password", db[] = "database"

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR )
	
	// Menus
	register_clcmd("SuperHero Tickets", "Menu1")
	register_clcmd("SuperHero Trade", "Menu2")
	
	// Comandos
	register_clcmd("say /tickets", "cmd_tickets")
	register_clcmd("say /pts15", "show_top15")
	register_clcmd("say /pts", "cmd_time")
	
	tuple = SQL_MakeDbTuple(host, user, pass, db)
	if(tuple == Handle:Empty_Handle) set_fail_state("Error in SQL Tuple creation.")
	
	new code, error[80], Handle:con
	con = SQL_Connect(tuple, code, error, charsmax(error))
	if(con == Handle:Empty_Handle){
		server_print("Error #%d connecting in database: %s", code, error)
		set_fail_state("Database error. Please check it before running the plugin.")
	}
	
	new Handle:query
	query = SQL_PrepareQuery(con, "CREATE TABLE IF NOT EXISTS `tickets`(id VARCHAR(33) NOT NULL UNIQUE, tickets INT(6) NOT NULL)")
	if(query == Handle:Empty_Handle){
		SQL_FreeHandle(con)
		set_fail_state("Error creating SQL' table.")
	}
	
	if(!SQL_Execute(query)){
		SQL_FreeHandle(con)
		SQL_FreeHandle(query)
		set_fail_state("Error with table's query.")
	}
	
	SQL_FreeHandle(query)
	SQL_FreeHandle(con)
}

public plugin_precache()
{
	precache_sound("misc/woohoo.wav")
}

public get_tickets(id){
	new tickets = TotalPlayedTime[id] + (get_user_time(id, 1) / 60)
	return tickets
}

public cmd_tickets(id)
{
	if ( zp_get_user_ammo_packs(id) <= 0 ) {
		client_print(id, print_chat, "[3D] Seus tickets estao sendo carregados.")
		return
	}
	
	Menu1(id)
}

public cmd_time(id)
{
	new tickets = get_tickets(id)
	if(tickets >= 0){ // por seguranša, caso seja admin mais nao tenha flags b, m ou n
		client_print(id, print_chat, "[3D] Voce tem: %d ZP Tickets.", tickets);
	
		if ( tickets >= 120 ) {
			client_print(id, print_chat, "[3D] Servidor usando tickets desenvolvidos pela Equipe3D")
			client_print(id, print_chat, "[3D] Digite: /tickets no chat.")
		}
	}
	
	return PLUGIN_CONTINUE
}

public client_disconnect(id)
{
	if(!is_user_admin(id)) return PLUGIN_HANDLED
	new tickets = get_tickets(id)
	if(tickets >= 0) SaveTime(id, tickets)
	return PLUGIN_HANDLED
}

public client_putinserver(id)
{
	if(!is_user_admin(id)) return PLUGIN_HANDLED
	if(is_user_connected(id)) {
		TotalPlayedTime[id] = LoadTime(id)
	}
	
	return PLUGIN_HANDLED
}

/*======================================
[Menu1]
======================================*/

public Menu1(id)
{
	new tickets = get_tickets(id)
	
	//first we need to make a variable that will hold the menu
	new menu = menu_create("\r[\w3D\r] \wZombie \rPlague \wTickets", "menu_handler1")
	
	new Form[50]
	format(Form,49,"%s: \r%d \wTickets!^n","Voce tem",tickets)
	menu_additem(menu ,Form, "3" , 0)
	
	menu_additem(menu, "\wTrocar Tickets por AP ->", "1", 0)
	menu_additem(menu, "\rInfo/Ajuda", "2", 0)   
	
	menu_setprop(menu, MPROP_EXITNAME, "Sair")
	
	menu_display(id, menu, 0)
	return PLUGIN_CONTINUE
}

public menu_handler1(id, menu, item)
{
	if (item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}
	
	new data[6], iName[64]
	new access, callback
	menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
	
	new key = str_to_num(data)
	switch(key)
	{
		case 1:
		{
			Menu2(id)
			menu_destroy(menu)
			return PLUGIN_HANDLED				
		}
		case 2:
		{
			client_print(id, print_chat, "[3D] Cada 1 Minuto voce recebe 1 ticket.")
			client_print(id, print_chat, "[3D] Voce pode trocar alguns tickets por Ammo Packs neste Servidor.")
			Menu1(id)
			menu_destroy(menu)
			return PLUGIN_HANDLED			
		}
		case 3:
		{
			Menu1(id)
			menu_destroy(menu)
			return PLUGIN_HANDLED
		}		
	}
	
	menu_destroy(menu)
	return PLUGIN_HANDLED
}

/*======================================
[Menu2]
======================================*/

public Menu2(id)
{
	//first we need to make a variable that will hold the menu
	new menu = menu_create("\ySuperHero Tickets^n\dTrade tickets for XP:", "menu_handler2")
	// Voce tem X tickets!
	
	new tickets = get_tickets(id)
	
	new Form[50]
	format(Form,49,"%s: \r%d \wtickets!^n","You have",tickets)
	menu_additem(menu ,Form, "7" , 0)
	
	if ( tickets >= 120 ) {
		menu_additem(menu, "\wTrade \r120 pts \wfor \r1000 XP", "1", 0)
	}
	else menu_additem(menu, "\dTrade 120 pts for 1000 XP", "1", 0)
	
	if ( tickets >= 240 ) {
		menu_additem(menu, "\wTrade \r240 pts \wfor \r2500 XP", "2", 0)
	}
	else menu_additem(menu, "\dTrade 240 pts for 2500 XP", "2", 0)
	
	if ( tickets >= 360 ) {
		menu_additem(menu, "\wTrade \r360 pts \wfor \r4500 XP", "3", 0)
	}
	else menu_additem(menu, "\dTrade 360 pts for 4500 XP", "3", 0)	
	
	if ( tickets >= 600 ) {
		menu_additem(menu, "\wTrade \r600 pts \wfor \r9500 XP", "4", 0)
	}
	else menu_additem(menu, "\dTrade 600 pts for 9500 XP", "4", 0)	
	
	if ( tickets >= 900 ) {
		menu_additem(menu, "\wTrade \r900 pts \wfor \r16000 XP", "5", 0)
	}
	else menu_additem(menu, "\dTrade 900 pts for 16000 XP", "5", 0)	
	
	if ( tickets >= 1500 ) {
		menu_additem(menu, "\wTrade \r1500 pts \wfor \r26000 XP", "6", 0)
	}
	else menu_additem(menu, "\dTrade 1500 pts for 26000 XP", "6", 0)		 
	
	menu_setprop(menu, MPROP_EXITNAME, "Exit")
	
	menu_display(id, menu, 0)
	return PLUGIN_CONTINUE
}

public menu_handler2(id, menu, item)
{
	if (item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}
	
	new data[6], iName[64]
	new access, callback
	menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
	
	new key = str_to_num(data)
	new tickets = get_tickets(id)
	switch(key)
	{		
		case 1:
		{			
			if ( tickets >= 120 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 120 tickets! XP after: %i || XP before: %i", name, XP, XP + 1000)				
				
				TotalPlayedTime[id] -= 120
				zp_set_user_ammo_packs(id, XP + 1000)
				client_print(id, print_chat, "[ST] You traded 120 superhero tickets for 1000 XP!")
				
				client_print(0, print_chat, "[ST] Player %s traded 120 superhero tickets for 1000 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")
		}
		case 2:
		{			
			if ( tickets >= 240 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 240 tickets! XP after: %i || XP before: %i", name, XP, XP + 2500)
				
				TotalPlayedTime[id] -= 240
				zp_set_user_ammo_packs(id, XP + 2500)
				client_print(id, print_chat, "[ST] You traded 240 superhero tickets for 2500 XP!")
				client_cmd(id, "speak misc/woohoo")
				
				client_print(0, print_chat, "[ST] Player %s traded 240 superhero tickets for 2500 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")
		}
		case 3:
		{
			if ( tickets >= 360 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 360 tickets! XP after: %i || XP before: %i", name, XP, XP + 4500)				
				
				TotalPlayedTime[id] -= 360
				zp_set_user_ammo_packs(id, XP + 4500)
				client_print(id, print_chat, "[ST] You traded 360 superhero tickets for 4500 XP!")
				client_cmd(id, "speak misc/woohoo")

				client_print(0, print_chat, "[ST] Player %s traded 360 superhero tickets for 4500 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")	
		}
		case 4:
		{
			if ( tickets >= 600 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 600 tickets! XP after: %i || XP before: %i", name, XP, XP + 9500)		
				
				TotalPlayedTime[id] -= 600
				zp_set_user_ammo_packs(id, XP + 9500)
				client_print(id, print_chat, "[ST] You traded 600 superhero tickets for 9500 XP!")
				client_cmd(id, "speak misc/woohoo")
				
				client_print(0, print_chat, "[ST] Player %s traded 600 superhero tickets for 9500 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")	
		}
		case 5:
		{
			if ( tickets >= 900 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 900 tickets! XP after: %i || XP before: %i", name, XP, XP + 16000)				
				
				TotalPlayedTime[id] -= 900
				zp_set_user_ammo_packs(id, XP + 16000)
				client_print(id, print_chat, "[ST] You traded 900 superhero tickets for 16000 XP!")
				client_cmd(id, "speak misc/woohoo")
				
				client_print(0, print_chat, "[ST] Player %s traded 900 superhero tickets for 16000 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")
		}
		case 6:
		{
			if ( tickets >= 1500 )
			{
				new XP = zp_get_user_ammo_packs(id)
				new name[33]
				get_user_name(id, name, charsmax(name))				
				
				log_to_file(LOGFILE, "PLAYER: %s traded 1500 tickets! XP after: %i || XP before: %i", name, XP, XP + 26000)				
				
				TotalPlayedTime[id] -= 1500
				zp_set_user_ammo_packs(id, XP + 26000)
				client_print(id, print_chat, "[PT] [ST] You traded 1500 superhero tickets for 26000 XP!")
				client_cmd(id, "speak misc/woohoo")
				
				client_print(0, print_chat, "[ST] Player %s traded 900 superhero tickets for 26000 XP!", name)
				
				TotalPlayedTime[id] += 1
			}
			else client_print(id, print_chat, "[ST] You do not have superhero tickets enough to make this trade.")
		}		
		case 7:
		{
			Menu1(id)
		}		
	}
	
	menu_destroy(menu)
	return PLUGIN_HANDLED
}

public LoadTime(id) 
{
	new authid[34]
	get_user_authid(id, authid, charsmax(authid))
	
	if(containi(authid, "lan") || containi(authid, "pending")) {
		get_user_name(id, authid, charsmax(authid))
	}
	
	new Handle:con, code, error[80]
	con = SQL_Connect(tuple, code, error, charsmax(error))
	if(con == Handle:Empty_Handle){
		server_print("Error #%d to connect in database: %s", code, error)
		set_fail_state("Database Error")
	}
	
	new s[250]
	formatex(s, charsmax(s), "SELECT `tickets` FROM `tickets` WHERE `id` = ^"%s^"", authid)
	new Handle:query = SQL_PrepareQuery(con, s)
	if(query == Handle:Empty_Handle){
		SQL_FreeHandle(con)
		set_fail_state("Error creating sql table")
	}
	
	if(!SQL_Execute(query)){
		new error[500]
		SQL_QueryError(query, error, charsmax(error))
		log_amx("Error in load query: %s", error)
		SQL_FreeHandle(con)
		SQL_FreeHandle(query)
		set_fail_state("Error creating sql load")
	}
	
	new tickets = 0
	if(SQL_NumResults(query) > 0){
		new col = SQL_FieldNameToNum(query, "tickets")
		tickets = SQL_ReadResult(query, col)
	}
	
	SQL_FreeHandle(query)
	SQL_FreeHandle(con)
		
	return tickets
}

public SaveTime(id,PlayedTime)
{
	if (PlayedTime <= 0)  {
		return PLUGIN_CONTINUE
	}
	
	new authid[34]
	get_user_authid(id, authid, charsmax(authid))
	
	if(containi(authid, "lan") || containi(authid, "pending")) {
		get_user_name(id, authid, charsmax(authid))
	}
	
	new Handle:con, code, error[80]
	con = SQL_Connect(tuple, code, error, charsmax(error))
	if(con == Handle:Empty_Handle){
		server_print("Error #%d to connect in database: %s", code, error)
		set_fail_state("Database Error")
	}
	
	new rows, s[250]
	if(!SQL_SimpleQueryFmt(con, error, charsmax(error), rows, "SELECT * FROM `tickets` WHERE `id` = ^"%s^"", authid)){
		SQL_FreeHandle(con)
		log_amx("Error, query SELECT: %s", error)
		set_fail_state("Erro")
	}
	if(rows > 0){
		formatex(s, charsmax(s), "UPDATE `tickets` SET `tickets` = ^"%d^" WHERE `id` = ^"%s^"", PlayedTime, authid)
		new Handle:query = SQL_PrepareQuery(con, s)
		if(query == Handle:Empty_Handle){
			SQL_FreeHandle(con)
			set_fail_state("Error creating first save query.")
		}
	
		if(!SQL_Execute(query)){
			new error[500]
			SQL_QueryError(query, error, charsmax(error))
			log_amx("Error creating first save query: %s", error)
			SQL_FreeHandle(con)
			SQL_FreeHandle(query)
			set_fail_state("Error creating first save query")
		}
		SQL_FreeHandle(query)
	}
	else
	{
		formatex(s, charsmax(s), "INSERT INTO `tickets` VALUES(^"%s^",^"%d^")", authid, PlayedTime)
		new Handle:query = SQL_PrepareQuery(con, s)
		if(query == Handle:Empty_Handle){
			SQL_FreeHandle(con)
			set_fail_state("Error creating second save query")
		}
		
		if(!SQL_Execute(query)){
			new error[500]
			SQL_QueryError(query, error, charsmax(error))
			log_amx("Error creating second save query: %s", error)
			SQL_FreeHandle(con)
			SQL_FreeHandle(query)
			set_fail_state("Error creating second save query")
		}
		SQL_FreeHandle(query)
	}
	
	SQL_FreeHandle(con)
	return PLUGIN_HANDLED
}

public show_top15(id)
{
	new i = 0, count, pls[32], playerCount, tickets
	static sort[33][2]
	
	get_players(pls, playerCount, "ch")
	
	for(;i<playerCount;i++)
	{
		tickets = get_tickets(pls[i])
		if(tickets <= 0) continue
		
		sort[count][0] = pls[i]
		sort[count][1] = tickets
		count++;
	}
	
	SortCustom2D(sort,count,"stats_custom_compare");
	
	new motd[1024], len	
	
	len = format(motd, 1023,"<body bgcolor=#000000><font color=#FFB000><pre>")
	len += format(motd[len], 1023-len,"%s %-22.22s %3s^n", "#", "Nick", "Number of Tickets")
	
	new players[32], num
	get_players(players, num)
	
	new b = clamp(count,0,15)
	
	new name[32], player
	
	for(new a = 0; a < b; a++)
	{
		player = sort[a][0]
		
		get_user_name(player, name, 31)		
		len += format(motd[len], 1023-len,"%d %-22.22s %d^n", a+1, name, sort[a][1])
	}
	
	len += format(motd[len], 1023-len,"</body></font></pre>")
	show_motd(id, motd, "TOP 15 TICKETS ONLINE")
	
	return PLUGIN_CONTINUE
}

public stats_custom_compare(elem1[],elem2[])
{
	if(elem1[1] > elem2[1]) return -1
	else if(elem1[1] < elem2[1]) return 1
		
	return 0
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1046\\ f0\\ fs16 \n\\ par }
*/
LeoLS is offline
PlayStation
Junior Member
Join Date: Nov 2015
Old 09-07-2016 , 18:23   Re: Error SQL
Reply With Quote #2

well, your database connection fails, check it ^^
PlayStation is offline
LeoLS
Junior Member
Join Date: Sep 2016
Old 09-07-2016 , 18:28   Re: Error SQL
Reply With Quote #3

already I checked but not can know the problem ...
what could it be?
LeoLS is offline
PlayStation
Junior Member
Join Date: Nov 2015
Old 09-07-2016 , 18:39   Re: Error SQL
Reply With Quote #4

you need to activate sql plugin in plugins.ini and configure your connection

you can also do it in your plugin as I see, just uncomment and edit this line
// new host[] = "host", user[] = "user", pass[] = "password", db[] = "database"
PlayStation is offline
LeoLS
Junior Member
Join Date: Sep 2016
Old 09-07-2016 , 19:08   Re: Error SQL
Reply With Quote #5

Error #2003 connecting in database: Can't connect to MySQL server on '127.0.0.1' (10061)

how do I know my information correct database?
LeoLS is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 09-07-2016 , 19:19   Re: Error SQL
Reply With Quote #6

Quote:
Originally Posted by LeoLS View Post
Error #2003 connecting in database: Can't connect to MySQL server on '127.0.0.1' (10061)

how do I know my information correct database?
Get an online MySQL server.
WAR3DM is offline
LeoLS
Junior Member
Join Date: Sep 2016
Old 09-07-2016 , 20:14   Re: Error SQL
Reply With Quote #7

I don't know how to do it =(
there is a simpler way that does not need it ?

using a plugin registersystem ??

Last edited by LeoLS; 09-07-2016 at 20:19.
LeoLS is offline
Reply


Thread Tools
Display Modes

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 00:19.


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