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

Lifes (1.2.5 - 29.07.2013)


Post New Thread Reply   
 
Thread Tools Display Modes
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-28-2013 , 18:53   Re: Deathrun Lifes (1.1.0 - 27.07.2013)
Reply With Quote #21

Why do you restrict this to deathrun ?

A complete plugin with rules to obtain lives for each team, or event in specific situation could be usefull and your plugin would be used by more people.
And then, sub plugin feature would make sense.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-29-2013 , 02:38   Re: Deathrun Lifes (1.1.0 - 27.07.2013)
Reply With Quote #22

Well, I only thought of Deathrun, but, okay, I'll edit it.
__________________
Kia is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-29-2013 , 03:39   Re: Lifes (1.2.0 - 29.07.2013)
Reply With Quote #23

Updated to Vers. 1.2.0
  • Changed name from "Deathrun Lifes" to "Lifes".
  • Updated Description.
  • Added CVar lifes_condition
  • Renamed Natives
  • Optimized Plugin.


Updated to Vers. 1.2.5
  • Added Multi-Language
__________________

Last edited by Kia; 07-29-2013 at 03:54.
Kia is offline
Old 07-29-2013, 04:47
LordOfNothing
This message has been deleted by ConnorMcLeod. Reason: troll, or posting random confusing code, or posting for posts count
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-29-2013 , 04:51   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #24

Example of what?
__________________
Kia is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 09-11-2013 , 06:52   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #25

sql support not working correctly (gives me some errors).
Kia, can you test locally plugin and fix it ?
Thanks!
lqlqlq is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-11-2013 , 06:53   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #26

Show me the errors you have.
__________________
Kia is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 09-11-2013 , 06:58   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #27

On restart server:
Code:
L 09/11/2013 - 13:57:56: [MySQL] Invalid column: 2
L 09/11/2013 - 13:57:56: [AMXX] Displaying debug trace (plugin "deathrun_lifes.amxx")
L 09/11/2013 - 13:57:56: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 09/11/2013 - 13:57:56: [AMXX]    [0] deathrun_lifes.sma::register_client (line 355)
On retry:
Code:
L 09/11/2013 - 13:58:18: [MySQL] Invalid column: 2
L 09/11/2013 - 13:58:18: [AMXX] Displaying debug trace (plugin "deathrun_lifes.amxx")
L 09/11/2013 - 13:58:18: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 09/11/2013 - 13:58:18: [AMXX]    [0] deathrun_lifes.sma::register_client (line 355)
I edit the plugin to save by name:
Code:
/* Plugin generated by AMXX-Studio */

// Uncomment this line to use SQL instead of Vault
#define USE_SQL

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#if defined USE_SQL
#include <sqlx>
#endif

#define PLUGIN 	"Lifes"
#define VERSION "1.2.0"
#define AUTHOR 	"Kia"

#define PREFIX 	"[Lifes]"

#if defined USE_SQL
new Host[]    	= "127.0.0.1"
new User[]    	= "root"
new Pass[]    	= "mynameis1514"
new Db[]   	= "dedihost_banlist"

new Handle:g_SqlConnection
new Handle:g_SqlTuple
new g_Error[512]
new g_authed[33]
new g_sql_ready = false
new bool:g_loaded[33]

new maxplayers;
#endif

/* Integer */

new g_iLifes[33]

/* CVars */

new cvar_minimum, cvar_event

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	/* Commands */
	
	register_clcmd("say /life",	"func_cmdLife")
	register_clcmd("say /lifes",	"func_cmdLife")
	
	/* Events */
	
	register_event("DeathMsg",	"func_EventDeathMsg",      "a")
	
	register_event("SendAudio", "func_EventCTWin", "a", "2&%!MRAD_ctwin") 
	register_event("SendAudio", "func_EventTWin", "a", "2&%!MRAD_terwin") 
	
	/* CVars */
	
	cvar_minimum	= register_cvar("lifes_minplayer","0")
	cvar_event	= register_cvar("lifes_condition","1") // 1 : On Player Kill ; 2 : On Team Win (only alive players) ; 3 : On Team Win (all)
	
	#if defined USE_SQL
	maxplayers = get_maxplayers()
	set_task(0.1, "MySql_Init")
	#endif
	
	/* Multi-Language */
	
	register_dictionary("kialifes.txt")
}

public plugin_natives()
{
	register_library("kia_lifes")
	
	register_native("get_user_lifes","func_ReturnLifes")
	register_native("set_user_lifes","func_SetLifes")
}

public func_ReturnLifes(index)
{
	return g_iLifes[get_param(1)]
}

public func_SetLifes(index, value)
{
	new plr = get_param(1)
	g_iLifes[plr] = max(0, get_param(2))
	#if defined USE_SQL
	Save_MySql(index)
	#else
	save_user_lifes(plr)
	#endif
	return g_iLifes[plr]
}

public func_EventDeathMsg()
{
	if(get_pcvar_num(cvar_event) == 1)
	{
		new iKiller = read_data(1)
		new iVictim = read_data(2)
		new iTeamVic = get_user_team(iVictim)
		
		static szNameKiller[32], szNameVic[32]
		
		get_user_name(iKiller, szNameKiller, charsmax(szNameKiller))
		get_user_name(iVictim, szNameVic, charsmax(szNameVic))
		
		if(iKiller != iVictim && get_user_team(iKiller) != iTeamVic)
		{
			g_iLifes[iKiller]++
			print_color(0, iKiller, 0, "%L", LANG_PLAYER, "MSG_KILL", PREFIX, szNameKiller, szNameVic)
			
			new players[32], pnum
			get_players(players, pnum, "a")
			
			if(g_iLifes[iVictim] > 0 && pnum > get_pcvar_num(cvar_minimum))
				func_AskForRevive(iVictim)
		}
	}
	return PLUGIN_HANDLED
}

public func_EventCTWin()
{
	if(get_pcvar_num(cvar_event) >= 2 )
	{
		new players[32], pnum, tempid
		get_players(players, pnum, get_pcvar_num(cvar_event) == 3 ? "ce" : "ae", "CT")
		
		for(new i; i < pnum; i++)
		{
			tempid = players[i]
			g_iLifes[tempid]++
			print_color(tempid, tempid, 0, "%L", LANG_PLAYER, "MSG_RECV", PREFIX, g_iLifes[tempid])
		}
	}
}

public func_EventTWin()
{
	if(get_pcvar_num(cvar_event) >= 2)
	{
		new players[32], pnum, tempid
		get_players(players, pnum, get_pcvar_num(cvar_event) == 3 ? "ce" : "ae", "TERRORIST")
		
		for(new i; i < pnum; i++)
		{
			tempid = players[i]
			g_iLifes[tempid]++
			print_color(tempid, tempid, 0, "%L", LANG_PLAYER, "MSG_,RECV", PREFIX, g_iLifes[tempid])
		}
	}				
}		

public func_AskForRevive(id)
{
	if(is_user_alive(id))
		return PLUGIN_HANDLED
	
	static szMenuTitle[96]
	formatex(szMenuTitle, charsmax(szMenuTitle), "%L", LANG_PLAYER, "MSG_REVIVEASK", PREFIX, g_iLifes[id])
	
	new menu = menu_create(szMenuTitle, "func_AskForRevive_handler")
	
	menu_additem(menu, "Yes.",	"1",0)
	menu_additem(menu, "No.",	"2",0)
	menu_display(id, menu, 0)
	
	return PLUGIN_HANDLED
}

public func_AskForRevive_handler(id, menu, item)
{
	if(is_user_alive(id) || cs_get_user_team(id) == CS_TEAM_T)
		return PLUGIN_HANDLED
	
	new data[6], szName[64];
	new access, callback;
	menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
	
	new key = str_to_num(data)
	
	switch(key)
	{
		case 1:
		{
			g_iLifes[id]--
			print_color(id, id, 0, "%L", LANG_PLAYER, "MSG_REVIVEOK", PREFIX, g_iLifes[id])
			ExecuteHamB(Ham_CS_RoundRespawn, id)
				
			save_user_lifes(id)
		}
		case 2:
		{
			print_color(id, id, 0, "%L", LANG_PLAYER, "MSG_REVIVENO", PREFIX)
		}
	}
	
	return PLUGIN_HANDLED
}
				
				

public func_cmdLife(id)
{
	print_color(id, id, 0, "%L", LANG_PLAYER, "MSG_LIFES", PREFIX, g_iLifes[id])
}

public client_putinserver(id)
{
	g_iLifes[id] = 0
	
	#if defined USE_SQL
	Save_MySql(id)
	#else
	load_user_lifes(id)
	#endif
}

public client_disconnect(id)
{
	#if defined USE_SQL
	Load_MySql(id)
	#else
	save_user_lifes(id)
	#endif
	g_iLifes[id] = 0
}

/* Saving */

public save_user_lifes(id)
{ 
    new name[32]
    get_user_name(id,name,31) 
     
    new vaultkey[64], vaultdata[64] 
    
    formatex(vaultkey,63,"WB-%s-lifes",name) 
    formatex(vaultdata,63,"%d",g_iLifes[id])
    set_vaultdata(vaultkey,vaultdata)
}   

public load_user_lifes(id)
{ 
    new name[32] 
    get_user_name(id,name,31)
     
    new vaultkey[64], vaultdata[64]
    
    formatex(vaultkey,63,"WB-%s-lifes",name) 
    get_vaultdata(vaultkey,vaultdata,63)
    g_iLifes[id] = str_to_num(vaultdata)
}  

/* SQL */

#if defined USE_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 drunlifes (name varchar(64), lifes 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 szName[32], szTemp[512]
		get_user_name(id, szName, charsmax(szName))
		
		new Data[1]
		Data[0] = id
		
		//we will now select from the table `furienmoney` where the steamid match
		format(szTemp,511,"SELECT * FROM `drunlifes` WHERE (`name` = '%s')", szName)
		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) == 0)
	{
		//.if there are no results found
		
		new szName[32]
		get_user_name(id, szName, 31) // get user's name
		
		
		new szTemp[512]
		
		// now we will insert the values into our table.
		format(szTemp,511,"INSERT INTO `drunlifes` (`drunlifes`.`name`,`drunlifes`.`lifes`) VALUES ('%s','0');",szName)

		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
	}
	else
	{
		// if there are results found
		g_iLifes[id]        = SQL_ReadResult(Query, 2)
	}
	g_loaded[id] = true
	return PLUGIN_HANDLED
}

public Save_MySql(id)
{
	if(g_loaded[id])
	{
		new szTemp[512], szName[32]
		get_user_name(id, szName, 31)
		
		// Here we will update the user hes information in the database where the steamid matches.
		format(szTemp,511,"UPDATE `drunlifes` SET `name` = '%s', `lifes` = '%i' WHERE `name` = '%s';",szName,g_iLifes[id])
		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
	}
}
#endif

/* ColorChat Stock */

public print_color(id, cid, color, const message[], any:...)
{
	new msg[192]
	vformat(msg, charsmax(msg), message, 5)
	
	//if you want to use ML, enable
	replace_all(msg, charsmax(msg), "!g", "^x04")
	replace_all(msg, charsmax(msg), "!n", "^x01")
	replace_all(msg, charsmax(msg), "!t", "^x03")
	
	new param
	if (!cid) return
	else param = cid
	new team[32]
	get_user_team(param, team, 31)
	switch (color)
	{
		case 0: msg_teaminfo(param, team)
		case 1: msg_teaminfo(param, "TERRORIST")
		case 2: msg_teaminfo(param, "CT")
		case 3: msg_teaminfo(param, "SPECTATOR")
	}
	if (id) msg_saytext(id, param, msg)
	else msg_saytext(0, param, msg)
	if (color != 0) msg_teaminfo(param, team)
}

public msg_saytext(id, cid, msg[])
{
	message_begin(id?MSG_ONE:MSG_ALL, get_user_msgid("SayText"), {0,0,0}, id)
	write_byte(cid)
	write_string(msg)
	message_end()
}

public msg_teaminfo(id, team[])
{
	message_begin(MSG_ONE, get_user_msgid("TeamInfo"), {0,0,0}, id)
	write_byte(id)
	write_string(team)
	message_end()
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1031\\ f0\\ fs16 \n\\ par }
*/
Can you help me ?
Thanks.
lqlqlq is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 09-11-2013 , 08:59   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #28

Has the SQL User all permissions?
__________________
Kia is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 09-11-2013 , 11:25   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #29

Yes, and succesfully added some info in db, but not gives the correct lifes.
I edited column with nickname with 55 lifes and in game i get 0, when i type /lifes.
On retry and restart server i give error (when i posted).
lqlqlq is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-19-2014 , 07:32   Re: Lifes (1.2.5 - 29.07.2013)
Reply With Quote #30

Please report future bugs and suggestions via mail to : [email protected]

Since I get many messages from different ways I decided to set up this mail account so everything gets to one place.
__________________
Kia 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:57.


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