add XP in plugin Equation Quest

Въпроси и проблеми свързани с AMXModX.
Аватар
TheRaiD
Извън линия
Foreigner
Foreigner
Мнения: 32
Регистриран на: 20 Яну 2019, 20:22
Се отблагодари: 5 пъти
Получена благодарност: 1 път

add XP in plugin Equation Quest

Мнение от TheRaiD » 17 Авг 2019, 16:11

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <engine>

#define eqAutoEnabled
#define doNothing 0
#define giveMoney 1
#define giveHealth 2
#define maxHealth get_pcvar_num(hpLimitCvar)

new const taskParam = 12321;
new const messageParam = 32123;

//FVAULT BY EXOLENT
stock const _vault_dir[] = "addons/amxmodx/data/file_vault";
stock const _temp_vault[] = "fvault_temp.txt";

//Colorchat
enum Color
{
	NORMAL = 1, // clients scr_concolor cvar color
	GREEN, // Green Color
	TEAM_COLOR, // Red, grey, blue
	GREY, // grey
	RED, // Red
	BLUE, // Blue
}

new TeamName[][] = 
{
	"",
	"TERRORIST",
	"CT",
	"SPECTATOR"
}


new nr1, nr2, type;
new bool:inWaitTime = false;
new nobodyCvar, correctCvar, timeCvar, bonusCvar, hpLimitCvar;

new correctAnswer[10];

new questionTime
new const file[] = "eq_points";
new bool:eqEnabled[33];

new topPoints[11];
new topNames[11][32];

public plugin_init()
{
	register_plugin("Equation Quest", "1.06", "Andrei.")
	set_task(10.0,"question",0)
	register_clcmd("say", "answer")
	register_clcmd("say_team", "answer")
	register_clcmd("say /eq", "cmdEQ")
	register_clcmd("say_team /eq", "cmdEQ")
	register_clcmd("say /eqpoints", "cmdPoints")
	register_clcmd("say_team /eqpoints", "cmdPoints")
	register_clcmd("say /eqrank", "cmdRank")
	register_clcmd("say_team /eqrank", "cmdRank")
	register_clcmd("say /eqtop15", "cmdShowTop");
	register_clcmd("say_team /eqtop15", "cmdShowTop");
	register_clcmd("say /eqtop10", "cmdShowTop");
	register_clcmd("say_team /eqtop10", "cmdShowTop");
	register_clcmd("say /eqtop", "cmdShowTop");
	register_clcmd("say_team /eqtop", "cmdShowTop");
	nobodyCvar = register_cvar("eq_nobody_answer", "60.0")
	correctCvar = register_cvar("eq_correct_answer", "90.0")
	timeCvar = register_cvar("eq_time_answer", "30.0")
	bonusCvar = register_cvar("eq_bonus", "0");
	hpLimitCvar = register_cvar("eq_hp_limit", "100");
	
	set_task(60.0, "message", messageParam);
	set_task(1.0, "makeTop");
}

public question()
{
	inWaitTime = false
	type = random_num(1, 4);
	switch(type)
	{
		case 1: // == +
		{
			nr1 = random_num(1,1000);
			nr2 = random_num(1,1000);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 +^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 + nr2, correctAnswer, 9);
		}
		case 2: // == -
		{
			nr1 = random_num(1,1000);
			nr2 = random_num(1,nr1);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 -^x03 %d^x01.The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 - nr2, correctAnswer, 9);
		}
		case 3: // == *
		{
			nr1 = random_num(2,100);
			nr2 = random_num(2, 30);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 x^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 * nr2, correctAnswer, 9);
		}
		case 4: // == /
		{
			nr2 = random_num(2, 30);
			nr1 = random_num(2,100) * nr2;
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 /^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 / nr2, correctAnswer, 9);
		}
	}
	set_task(get_pcvar_float(timeCvar), "timeOut", taskParam);
	questionTime = floatround(halflife_time());
}

public timeOut()
{
	new players[32], limit;
	get_players(players, limit, "");
	for(new i=0 ; i<limit ; ++i)
		if(eqEnabled[players[i]])
			ColorChat(players[i], BLUE, "^x04[EQ]^x01 Nobody answered the equation [^x03%s^x01]. Next equation in ^x03 %d ^x01seconds.", correctAnswer, floatround(get_pcvar_float(nobodyCvar)))
	set_task(get_pcvar_float(nobodyCvar),"question",taskParam)
	inWaitTime = true;
}

public answer(id)
{
	new say[192];
	
	read_args(say,192)
	remove_quotes(say)
	if(eqEnabled[id] && !inWaitTime && equal(say, correctAnswer))
	{
		new passedTime = floatround(halflife_time());
		
		new name[32]
		get_user_name(id,name,31)
	    
		passedTime -= questionTime;
		
		new wonPoints = ( floatround(get_pcvar_float(timeCvar)) / 5 ) + 1 - ( passedTime / 5 );
		
		new sPoints[12], points, oldPoints;
		
		fvault_get_data(file, name, sPoints, 11)
		points = (oldPoints = str_to_num(sPoints)) + wonPoints;
		
		num_to_str(points, sPoints, 11)
		fvault_set_data(file, name, sPoints);
		
		if(oldPoints > topPoints[10] || oldPoints == topPoints[10] && isInTop(id))
		{
			new j = 10;
			while(!equal(name, topNames[j]))
				--j;
			topPoints[j] = points;
			while(topPoints[j] > topPoints[--j])
			{
				
				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];
				
				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];
				
				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}
		else if(points > topPoints[10])
		{
			topPoints[10] = points;
			format(topNames[10], 31, "%s", name);
			
			new j = 10;
			while(topPoints[j] > topPoints[--j])
			{
				
				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];
				
				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];
				
				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}
		
		
		switch(get_pcvar_num(bonusCvar))
		{
			case giveHealth:
			{
				if(is_user_alive(id))
				{
					new health = get_user_health(id) + wonPoints*10;
					if(health > maxHealth)
						health = maxHealth
					set_user_health(id, health);
				}
			}
			case giveMoney:
			{
				new money = cs_get_user_money(id) + wonPoints*100;
				if(money > 16000)
					money = 16000;
				cs_set_user_money(id, money);
			}
		}
		
		new players[32], limit;
		get_players(players, limit, "");
		for(new i=0 ; i<limit ; ++i)
			if(eqEnabled[players[i]])
			{
				ColorChat(players[i], BLUE, "^x04[EQ]^x03 %s^x01 solved the equation [^x03%s^x01] after ^x03%d^x01 seconds. He has ^x04%d^x01 total points.", name, correctAnswer, passedTime, points)
				ColorChat(players[i], BLUE, "^x04[EQ]^x01 Next equation in^x03 %d^x01 seconds",floatround(get_pcvar_float(correctCvar)))
			}
		inWaitTime=true;
		
		remove_task(taskParam)
		set_task(get_pcvar_float(correctCvar),"question",taskParam)
		
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE	
}

public client_putinserver(id)
{
	#if defined eqAutoEnabled
	eqEnabled[id] = true;
	#else
	eqEnabled[id] = false;
	#endif
}

public message()
{
	new players[32], limit;
	get_players(players, limit, "");
	for(new i=0 ; i<limit ; ++i)
		ColorChat(players[i], BLUE, "^x04[EQ]^x01 Type^x03 /eq^x01 to %s the Equation Quest.", eqEnabled[players[i]]? "deactivate" : "activate");
	set_task(210.0, "message", messageParam);
}

public cmdEQ(id)
{
	eqEnabled[id] =! eqEnabled[id]
	ColorChat(id, BLUE,"^x04[EQ]^x01 Equation Quest %s it, type^x03 /eq^x01.", eqEnabled[id] ? "activated. If you want to deactivate" : "deactivated. If you want to activate")
	return PLUGIN_HANDLED
}

public cmdPoints(id)
{
	new name[32];
	get_user_name(id, name, 31);
	
	new sPoints[12], points;
	fvault_get_data(file, name, sPoints, 11);
	points = str_to_num(sPoints);
	
	ColorChat(id, BLUE,"^x04[EQ]^x01 You have^x03 %d^x01 points.", points);
	return PLUGIN_HANDLED;
}

public cmdRank(id)
{
	new name[32]
	get_user_name(id, name, 31)
	new sPoints[12], points;
	fvault_get_data(file, name, sPoints, 11);
	points = str_to_num(sPoints);
	new rank = 1;
		
	new Array:keys = ArrayCreate(32);
	new Array:datas = ArrayCreate(12);
	ArrayDestroy(keys)
	new total = fvault_load(file, keys, datas);

	new data[12];
	for( new i = 0; i < total; i++ )
	{
		ArrayGetString(datas, i, data, 11);
		if(str_to_num(data) > points)
			++rank;
	}
	ColorChat(id, BLUE,"^x04[EQ]^x01 Your rank is^x03 %d^x01.", rank);
	return PLUGIN_HANDLED;
}

public makeTop()
{
	topPoints[0] = 1<<30; // Infinity
	for(new i=1 ; i<=10 ; ++i)
	{
		format(topNames[i], 31, "----------")
		topPoints[i] = 0;
	}
	
	new Array:keys = ArrayCreate(32);
	new Array:datas = ArrayCreate(12);

	new total = fvault_load(file, keys, datas);

	new key[32], data[12];
	for( new i = 0; i < total; i++ )
	{
		ArrayGetString(keys, i, key, 31);
		ArrayGetString(datas, i, data, 11);
		
		new points = str_to_num(data);
		if(points > topPoints[10])
		{
			topPoints[10] = points;
			format(topNames[10], 31, "%s", key);
			
			new j = 10;
			while(topPoints[j] > topPoints[--j])
			{
				
				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];
				
				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];
				
				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}
	}	
}

public isInTop(id)
{
	new name[32]
	get_user_name(id, name, 31)
	
	for(new i=10 ; i ; --i)
		if(equal(name, topNames[i]))
			return true;
	
	return false;
}

public cmdShowTop(id)
{
	new buffer[2048], len;
	
	len = formatex(buffer, 2047, "<body bgcolor=#3399FF><table width=100%% cellpadding=2 cellspacing=0 border=0>")
	len += formatex(buffer[len], 2047-len, "<tr  align=center bgcolor=#0052FF><th width=10%%> # <th width=60%% align=center> Name <th  width=30%%> Points")
	
	for(new i=1 ; i<=10 ; ++i)
		len += formatex(buffer[len], 2047-len, "<tr align=center%s><td> %d <td align=center> %s <td> %d", ((i%2)==0) ? " bgcolor=#5DA5FF" : " bgcolor=#3399FF", i, topNames[i], topPoints[i])
	
	len += formatex(buffer[len], 2047-len, "</table></body>")
	len += formatex(buffer[len], 2047-len, "<tr><Center><b><BR>Plugin created by Andrei.")
	
	show_motd(id, buffer, "Equation top10")
	return PLUGIN_HANDLED;
}


// FVAULT BY EXOLENT

stock fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0)
{
	new filename[128];
	_FormatVaultName(vaultname, filename, sizeof(filename) - 1);
	
	if( !file_exists(filename) )
	{
		return 0;
	}
	
	new vault = fopen(filename, "rt");
	
	new _data[512], _key[64], _time[32];
	
	while( !feof(vault) )
	{
		fgets(vault, _data, sizeof(_data) - 1);
		parse(_data, _key, sizeof(_key) - 1);
		
		if( equal(_key, key) )
		{
			new _len = strlen(_key) + 4; // + 2 = quotes on key, + 1 = space, + 1 = first quote
			for( new i = copy(data, len, _data[_len]) - 1; i > 0; i-- )
			{
				if( data[i] == '"' ) break;
				
				if( data[i] == ' '
				&& data[i - 1] == '"' )
				{
					data[i - 1] = '^0';
					
					copy(_time, sizeof(_time) - 1, data[i + 1]);
					timestamp = str_to_num(_time);
					break;
				}
			}
			
			fclose(vault);
			
			return 1;
		}
	}
	
	fclose(vault);
	
	copy(data, len, "");
	
	return 0;
}

stock fvault_set_data(const vaultname[], const key[], const data[])
{
	_fvault_set_data(vaultname, key, data, get_systime());
}

_fvault_set_data(const vaultname[], const key[], const data[], const timestamp)
{
	new file = fopen(_temp_vault, "wt");
	
	new filename[128];
	_FormatVaultName(vaultname, filename, sizeof(filename) - 1);
	
	new vault = fopen(filename, "rt");
	
	new _data[512], _key[64], _other[3];
	
	new bool:replaced = false;
	
	while( !feof(vault) )
	{
		fgets(vault, _data, sizeof(_data) - 1);
		parse(_data, _key, sizeof(_key) - 1, _other, sizeof(_other) - 1);
		
		if( equal(_key, key) && !replaced )
		{
			fprintf(file, "^"%s^" ^"%s^" %i^n", key, data, timestamp);
			
			replaced = true;
		}
		else
		{
			fputs(file, _data);
		}
	}
	
	fclose(file);
	fclose(vault);
	
	if( !replaced )
	{
		file = fopen(filename, "a+");
		fprintf(file, "^"%s^" ^"%s^" %i^n", key, data, timestamp);
		fclose(file);
		
		delete_file(_temp_vault);
	}
	else
	{
		delete_file(filename);
		
		while( !rename_file(_temp_vault, filename, 1) ) { }
	}
}

stock _FormatVaultName(const vaultname[], filename[], len)
{
	static const invalid_chars[][] =
	{
		"/", "\", "*", ":", "?", "^"", "<", ">", "|"
	};
	
	static tempvault[128], i;
	copy(tempvault, sizeof(tempvault) - 1, vaultname);
	
	for( i = 0; i < sizeof(invalid_chars); i++ )
	{
		replace_all(tempvault, sizeof(tempvault) - 1, invalid_chars[i], "");
	}
	
	if( !dir_exists(_vault_dir) )
	{
		mkdir(_vault_dir);
	}
	
	formatex(filename, len, "%s/%s.txt", _vault_dir, tempvault);
}

stock fvault_load(const vaultname[], Array:keys=Invalid_Array, Array:datas=Invalid_Array, Array:timestamps=Invalid_Array)
{
	new filename[128];
	_FormatVaultName(vaultname, filename, 127);
	
	if( !file_exists(filename) )
	{
		return 0;
	}
	
	new vault = fopen(filename, "rt");
	
	new array_size;
	
	new filedata[1024];
	new key[64], data[512], timestamp[32];
	while( !feof(vault) )
	{
		fgets(vault, filedata, 1023);
		
		if( parse(filedata, key, 63, data, 511, timestamp, 31) < 2 )
		{
			continue;
		}
		
		if( keys != Invalid_Array )
		{
			ArrayPushString(keys, key);
		}
		if( datas != Invalid_Array )
		{
			ArrayPushString(datas, data);
		}
		if( timestamps != Invalid_Array )
		{
			ArrayPushCell(timestamps, str_to_num(timestamp));
		}
		
		array_size++;
	}
	
	fclose(vault);
	
	return array_size;
}


//Colorchat
ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
{
	new message[256];

	switch(type)
	{
		case NORMAL: // clients scr_concolor cvar color
		{
			message[0] = 0x01;
		}
		case GREEN: // Green
		{
			message[0] = 0x04;
		}
		default: // White, Red, Blue
		{
			message[0] = 0x03;
		}
	}

	vformat(message[1], 251, msg, 4);

	// Make sure message is not longer than 192 character. Will crash the server.
	message[192] = '^0';

	new team, ColorChange, index, MSG_Type;
	
	if(id)
	{
		MSG_Type = MSG_ONE;
		index = id;
	} else {
		index = FindPlayer();
		MSG_Type = MSG_ALL;
	}
	
	team = get_user_team(index);
	ColorChange = ColorSelection(index, MSG_Type, type);

	ShowColorMessage(index, MSG_Type, message);
		
	if(ColorChange)
	{
		Team_Info(index, MSG_Type, TeamName[team]);
	}
}

ShowColorMessage(id, type, message[])
{
	static bool:saytext_used;
	static get_user_msgid_saytext;
	if(!saytext_used)
	{
		get_user_msgid_saytext = get_user_msgid("SayText");
		saytext_used = true;
	}
	message_begin(type, get_user_msgid_saytext, _, id);
	write_byte(id)		
	write_string(message);
	message_end();	
}

Team_Info(id, type, team[])
{
	static bool:teaminfo_used;
	static get_user_msgid_teaminfo;
	if(!teaminfo_used)
	{
		get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
		teaminfo_used = true;
	}
	message_begin(type, get_user_msgid_teaminfo, _, id);
	write_byte(id);
	write_string(team);
	message_end();

	return 1;
}

ColorSelection(index, type, Color:Type)
{
	switch(Type)
	{
		case RED:
		{
			return Team_Info(index, type, TeamName[1]);
		}
		case BLUE:
		{
			return Team_Info(index, type, TeamName[2]);
		}
		case GREY:
		{
			return Team_Info(index, type, TeamName[0]);
		}
	}

	return 0;
}

FindPlayer()
{
	new i = -1;

	while(i <= get_maxplayers())
	{
		if(is_user_connected(++i))
			return i;
	}

	return -1;
}
can someone edit this plugin with ocixcroms xp system if someone answer right he will get 1-20xp random?
https://forums.alliedmods.net/showthread.php?t=308540
if random not work just givee them only 10xp
and if the player has points i want a command /buyxp to buy with this points xp: 1points = 1xp
Последно промяна от TheRaiD на 17 Авг 2019, 16:28, променено общо 1 път.

Аватар
OciXCrom
Извън линия
Администратор
Администратор
Мнения: 7206
Регистриран на: 06 Окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 117 пъти
Получена благодарност: 1295 пъти
Обратна връзка:

help with xp

Мнение от OciXCrom » 17 Авг 2019, 16:17

Код за потвърждение: Избери целия код

#include <amxmodx>
#include <amxmisc>
#include <crxranks>
#include <cstrike>
#include <fun>
#include <engine>

#define eqAutoEnabled
#define doNothing 0
#define giveMoney 1
#define giveHealth 2
#define maxHealth get_pcvar_num(hpLimitCvar)

new const taskParam = 12321;
new const messageParam = 32123;

//FVAULT BY EXOLENT
stock const _vault_dir[] = "addons/amxmodx/data/file_vault";
stock const _temp_vault[] = "fvault_temp.txt";

//Colorchat
enum Color
{
	NORMAL = 1, // clients scr_concolor cvar color
	GREEN, // Green Color
	TEAM_COLOR, // Red, grey, blue
	GREY, // grey
	RED, // Red
	BLUE, // Blue
}

new TeamName[][] =
{
	"",
	"TERRORIST",
	"CT",
	"SPECTATOR"
}


new nr1, nr2, type;
new bool:inWaitTime = false;
new nobodyCvar, correctCvar, timeCvar, bonusCvar, hpLimitCvar;

new correctAnswer[10];

new questionTime
new const file[] = "eq_points";
new bool:eqEnabled[33];

new topPoints[11];
new topNames[11][32];

public plugin_init()
{
	register_plugin("Equation Quest", "1.06", "Andrei.")
	set_task(10.0,"question",0)
	register_clcmd("say", "answer")
	register_clcmd("say_team", "answer")
	register_clcmd("say /eq", "cmdEQ")
	register_clcmd("say_team /eq", "cmdEQ")
	register_clcmd("say /eqpoints", "cmdPoints")
	register_clcmd("say_team /eqpoints", "cmdPoints")
	register_clcmd("say /eqrank", "cmdRank")
	register_clcmd("say_team /eqrank", "cmdRank")
	register_clcmd("say /eqtop15", "cmdShowTop");
	register_clcmd("say_team /eqtop15", "cmdShowTop");
	register_clcmd("say /eqtop10", "cmdShowTop");
	register_clcmd("say_team /eqtop10", "cmdShowTop");
	register_clcmd("say /eqtop", "cmdShowTop");
	register_clcmd("say_team /eqtop", "cmdShowTop");
	nobodyCvar = register_cvar("eq_nobody_answer", "60.0")
	correctCvar = register_cvar("eq_correct_answer", "90.0")
	timeCvar = register_cvar("eq_time_answer", "30.0")
	bonusCvar = register_cvar("eq_bonus", "0");
	hpLimitCvar = register_cvar("eq_hp_limit", "100");

	set_task(60.0, "message", messageParam);
	set_task(1.0, "makeTop");
}

public question()
{
	inWaitTime = false
	type = random_num(1, 4);
	switch(type)
	{
		case 1: // == +
		{
			nr1 = random_num(1,1000);
			nr2 = random_num(1,1000);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 +^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 + nr2, correctAnswer, 9);
		}
		case 2: // == -
		{
			nr1 = random_num(1,1000);
			nr2 = random_num(1,nr1);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 -^x03 %d^x01.The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 - nr2, correctAnswer, 9);
		}
		case 3: // == *
		{
			nr1 = random_num(2,100);
			nr2 = random_num(2, 30);
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 x^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 * nr2, correctAnswer, 9);
		}
		case 4: // == /
		{
			nr2 = random_num(2, 30);
			nr1 = random_num(2,100) * nr2;
			new players[32], limit;
			get_players(players, limit, "");
			for(new i=0 ; i<limit ; ++i)
				if(eqEnabled[players[i]])
					ColorChat(players[i], BLUE, "^x04[EQ]^x01 Solve the equation^x03 %d^x01 /^x03 %d^x01. The faster you answer correctly, the more points you earn...", nr1, nr2)
			num_to_str(nr1 / nr2, correctAnswer, 9);
		}
	}
	set_task(get_pcvar_float(timeCvar), "timeOut", taskParam);
	questionTime = floatround(halflife_time());
}

public timeOut()
{
	new players[32], limit;
	get_players(players, limit, "");
	for(new i=0 ; i<limit ; ++i)
		if(eqEnabled[players[i]])
			ColorChat(players[i], BLUE, "^x04[EQ]^x01 Nobody answered the equation [^x03%s^x01]. Next equation in ^x03 %d ^x01seconds.", correctAnswer, floatround(get_pcvar_float(nobodyCvar)))
	set_task(get_pcvar_float(nobodyCvar),"question",taskParam)
	inWaitTime = true;
}

public answer(id)
{
	new say[192];

	read_args(say,192)
	remove_quotes(say)

	new cmd[32], amount[8];
	parse(say, cmd, charsmax(cmd), amount, charsmax(amount));

	if(equal(cmd, "/buyxp"))
	{
		new iamount = str_to_num(amount);

		if(iamount <= 0)
		{
			ColorChat(id, BLUE, "^x04[EQ]^x01 Amount must be greater than 0!");
			return PLUGIN_HANDLED;
		}

		new name[32], points[8];
		get_user_name(id, name, charsmax(name));
		fvault_get_data(file, name, points, charsmax(points));

		new ipoints = str_to_num(points);

		if(iamount > ipoints)
		{
			ColorChat(id, BLUE, "^x04[EQ]^x01 The amount you're trying to exchange (^x04%d^x01) is greater than your current points (^x04%d^x01)!", iamount, ipoints);
			return PLUGIN_HANDLED;
		}

		crxranks_give_user_xp(id, iamount);
		ipoints -= iamount;
		num_to_str(ipoints, points, charsmax(points));
		fvault_set_data(file, name, points);
		ColorChat(id, BLUE, "^x04[EQ]^x01 You successfully exchanged ^x04%d eqPoints ^x01for ^x04%d XP^x01!", iamount, iamount);
		return PLUGIN_HANDLED;
	}

	if(eqEnabled[id] && !inWaitTime && equal(say, correctAnswer))
	{
		new passedTime = floatround(halflife_time());

		new name[32]
		get_user_name(id,name,31)

		passedTime -= questionTime;

		new wonPoints = ( floatround(get_pcvar_float(timeCvar)) / 5 ) + 1 - ( passedTime / 5 );

		new sPoints[12], points, oldPoints;

		fvault_get_data(file, name, sPoints, 11)
		points = (oldPoints = str_to_num(sPoints)) + wonPoints;

		num_to_str(points, sPoints, 11)
		fvault_set_data(file, name, sPoints);

		if(oldPoints > topPoints[10] || oldPoints == topPoints[10] && isInTop(id))
		{
			new j = 10;
			while(!equal(name, topNames[j]))
				--j;
			topPoints[j] = points;
			while(topPoints[j] > topPoints[--j])
			{

				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];

				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];

				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}
		else if(points > topPoints[10])
		{
			topPoints[10] = points;
			format(topNames[10], 31, "%s", name);

			new j = 10;
			while(topPoints[j] > topPoints[--j])
			{

				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];

				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];

				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}


		switch(get_pcvar_num(bonusCvar))
		{
			case giveHealth:
			{
				if(is_user_alive(id))
				{
					new health = get_user_health(id) + wonPoints*10;
					if(health > maxHealth)
						health = maxHealth
					set_user_health(id, health);
				}
			}
			case giveMoney:
			{
				new money = cs_get_user_money(id) + wonPoints*100;
				if(money > 16000)
					money = 16000;
				cs_set_user_money(id, money);
			}
		}

		new xp = random_num(crxranks_get_xp_reward(id, "equation_min"), crxranks_get_xp_reward(id, "equation_max"))
		crxranks_give_user_xp(id, xp)

		new players[32], limit;
		get_players(players, limit, "");
		for(new i=0 ; i<limit ; ++i)
			if(eqEnabled[players[i]])
			{
				ColorChat(players[i], BLUE, "^x04[EQ]^x03 %s^x01 solved the equation [^x03%s^x01] after ^x03%d^x01 seconds and got ^x01%d XP^x01. He has ^x04%d^x01 total points.", name, correctAnswer, passedTime, xp, points)
				ColorChat(players[i], BLUE, "^x04[EQ]^x01 Next equation in^x03 %d^x01 seconds",floatround(get_pcvar_float(correctCvar)))
			}
		inWaitTime=true;

		remove_task(taskParam)
		set_task(get_pcvar_float(correctCvar),"question",taskParam)

		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

public client_putinserver(id)
{
	#if defined eqAutoEnabled
	eqEnabled[id] = true;
	#else
	eqEnabled[id] = false;
	#endif
}

public message()
{
	new players[32], limit;
	get_players(players, limit, "");
	for(new i=0 ; i<limit ; ++i)
		ColorChat(players[i], BLUE, "^x04[EQ]^x01 Type^x03 /eq^x01 to %s the Equation Quest.", eqEnabled[players[i]]? "deactivate" : "activate");
	set_task(210.0, "message", messageParam);
}

public cmdEQ(id)
{
	eqEnabled[id] =! eqEnabled[id]
	ColorChat(id, BLUE,"^x04[EQ]^x01 Equation Quest %s it, type^x03 /eq^x01.", eqEnabled[id] ? "activated. If you want to deactivate" : "deactivated. If you want to activate")
	return PLUGIN_HANDLED
}

public cmdPoints(id)
{
	new name[32];
	get_user_name(id, name, 31);

	new sPoints[12], points;
	fvault_get_data(file, name, sPoints, 11);
	points = str_to_num(sPoints);

	ColorChat(id, BLUE,"^x04[EQ]^x01 You have^x03 %d^x01 points.", points);
	return PLUGIN_HANDLED;
}

public cmdRank(id)
{
	new name[32]
	get_user_name(id, name, 31)
	new sPoints[12], points;
	fvault_get_data(file, name, sPoints, 11);
	points = str_to_num(sPoints);
	new rank = 1;

	new Array:keys = ArrayCreate(32);
	new Array:datas = ArrayCreate(12);
	ArrayDestroy(keys)
	new total = fvault_load(file, keys, datas);

	new data[12];
	for( new i = 0; i < total; i++ )
	{
		ArrayGetString(datas, i, data, 11);
		if(str_to_num(data) > points)
			++rank;
	}
	ColorChat(id, BLUE,"^x04[EQ]^x01 Your rank is^x03 %d^x01.", rank);
	return PLUGIN_HANDLED;
}

public makeTop()
{
	topPoints[0] = 1<<30; // Infinity
	for(new i=1 ; i<=10 ; ++i)
	{
		format(topNames[i], 31, "----------")
		topPoints[i] = 0;
	}

	new Array:keys = ArrayCreate(32);
	new Array:datas = ArrayCreate(12);

	new total = fvault_load(file, keys, datas);

	new key[32], data[12];
	for( new i = 0; i < total; i++ )
	{
		ArrayGetString(keys, i, key, 31);
		ArrayGetString(datas, i, data, 11);

		new points = str_to_num(data);
		if(points > topPoints[10])
		{
			topPoints[10] = points;
			format(topNames[10], 31, "%s", key);

			new j = 10;
			while(topPoints[j] > topPoints[--j])
			{

				new temp, sTemp[32];
				format(sTemp, 31, "%s", topNames[j]);
				temp = topPoints[j];

				format(topNames[j], 31, "%s", topNames[j+1]);
				topPoints[j] = topPoints[j+1];

				format(topNames[j+1], 31, "%s", sTemp);
				topPoints[j+1] = temp;
			}
		}
	}
}

public isInTop(id)
{
	new name[32]
	get_user_name(id, name, 31)

	for(new i=10 ; i ; --i)
		if(equal(name, topNames[i]))
			return true;

	return false;
}

public cmdShowTop(id)
{
	new buffer[2048], len;

	len = formatex(buffer, 2047, "<body bgcolor=#3399FF><table width=100%% cellpadding=2 cellspacing=0 border=0>")
	len += formatex(buffer[len], 2047-len, "<tr  align=center bgcolor=#0052FF><th width=10%%> # <th width=60%% align=center> Name <th  width=30%%> Points")

	for(new i=1 ; i<=10 ; ++i)
		len += formatex(buffer[len], 2047-len, "<tr align=center%s><td> %d <td align=center> %s <td> %d", ((i%2)==0) ? " bgcolor=#5DA5FF" : " bgcolor=#3399FF", i, topNames[i], topPoints[i])

	len += formatex(buffer[len], 2047-len, "</table></body>")
	len += formatex(buffer[len], 2047-len, "<tr><Center><b><BR>Plugin created by Andrei.")

	show_motd(id, buffer, "Equation top10")
	return PLUGIN_HANDLED;
}


// FVAULT BY EXOLENT

stock fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0)
{
	new filename[128];
	_FormatVaultName(vaultname, filename, sizeof(filename) - 1);

	if( !file_exists(filename) )
	{
		return 0;
	}

	new vault = fopen(filename, "rt");

	new _data[512], _key[64], _time[32];

	while( !feof(vault) )
	{
		fgets(vault, _data, sizeof(_data) - 1);
		parse(_data, _key, sizeof(_key) - 1);

		if( equal(_key, key) )
		{
			new _len = strlen(_key) + 4; // + 2 = quotes on key, + 1 = space, + 1 = first quote
			for( new i = copy(data, len, _data[_len]) - 1; i > 0; i-- )
			{
				if( data[i] == '"' ) break;

				if( data[i] == ' '
				&& data[i - 1] == '"' )
				{
					data[i - 1] = '^0';

					copy(_time, sizeof(_time) - 1, data[i + 1]);
					timestamp = str_to_num(_time);
					break;
				}
			}

			fclose(vault);

			return 1;
		}
	}

	fclose(vault);

	copy(data, len, "");

	return 0;
}

stock fvault_set_data(const vaultname[], const key[], const data[])
{
	_fvault_set_data(vaultname, key, data, get_systime());
}

_fvault_set_data(const vaultname[], const key[], const data[], const timestamp)
{
	new file = fopen(_temp_vault, "wt");

	new filename[128];
	_FormatVaultName(vaultname, filename, sizeof(filename) - 1);

	new vault = fopen(filename, "rt");

	new _data[512], _key[64], _other[3];

	new bool:replaced = false;

	while( !feof(vault) )
	{
		fgets(vault, _data, sizeof(_data) - 1);
		parse(_data, _key, sizeof(_key) - 1, _other, sizeof(_other) - 1);

		if( equal(_key, key) && !replaced )
		{
			fprintf(file, "^"%s^" ^"%s^" %i^n", key, data, timestamp);

			replaced = true;
		}
		else
		{
			fputs(file, _data);
		}
	}

	fclose(file);
	fclose(vault);

	if( !replaced )
	{
		file = fopen(filename, "a+");
		fprintf(file, "^"%s^" ^"%s^" %i^n", key, data, timestamp);
		fclose(file);

		delete_file(_temp_vault);
	}
	else
	{
		delete_file(filename);

		while( !rename_file(_temp_vault, filename, 1) ) { }
	}
}

stock _FormatVaultName(const vaultname[], filename[], len)
{
	static const invalid_chars[][] =
	{
		"/", "\", "*", ":", "?", "^"", "<", ">", "|"
	};

	static tempvault[128], i;
	copy(tempvault, sizeof(tempvault) - 1, vaultname);

	for( i = 0; i < sizeof(invalid_chars); i++ )
	{
		replace_all(tempvault, sizeof(tempvault) - 1, invalid_chars[i], "");
	}

	if( !dir_exists(_vault_dir) )
	{
		mkdir(_vault_dir);
	}

	formatex(filename, len, "%s/%s.txt", _vault_dir, tempvault);
}

stock fvault_load(const vaultname[], Array:keys=Invalid_Array, Array:datas=Invalid_Array, Array:timestamps=Invalid_Array)
{
	new filename[128];
	_FormatVaultName(vaultname, filename, 127);

	if( !file_exists(filename) )
	{
		return 0;
	}

	new vault = fopen(filename, "rt");

	new array_size;

	new filedata[1024];
	new key[64], data[512], timestamp[32];
	while( !feof(vault) )
	{
		fgets(vault, filedata, 1023);

		if( parse(filedata, key, 63, data, 511, timestamp, 31) < 2 )
		{
			continue;
		}

		if( keys != Invalid_Array )
		{
			ArrayPushString(keys, key);
		}
		if( datas != Invalid_Array )
		{
			ArrayPushString(datas, data);
		}
		if( timestamps != Invalid_Array )
		{
			ArrayPushCell(timestamps, str_to_num(timestamp));
		}

		array_size++;
	}

	fclose(vault);

	return array_size;
}


//Colorchat
ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
{
	new message[256];

	switch(type)
	{
		case NORMAL: // clients scr_concolor cvar color
		{
			message[0] = 0x01;
		}
		case GREEN: // Green
		{
			message[0] = 0x04;
		}
		default: // White, Red, Blue
		{
			message[0] = 0x03;
		}
	}

	vformat(message[1], 251, msg, 4);

	// Make sure message is not longer than 192 character. Will crash the server.
	message[192] = '^0';

	new team, ColorChange, index, MSG_Type;

	if(id)
	{
		MSG_Type = MSG_ONE;
		index = id;
	} else {
		index = FindPlayer();
		MSG_Type = MSG_ALL;
	}

	team = get_user_team(index);
	ColorChange = ColorSelection(index, MSG_Type, type);

	ShowColorMessage(index, MSG_Type, message);

	if(ColorChange)
	{
		Team_Info(index, MSG_Type, TeamName[team]);
	}
}

ShowColorMessage(id, type, message[])
{
	static bool:saytext_used;
	static get_user_msgid_saytext;
	if(!saytext_used)
	{
		get_user_msgid_saytext = get_user_msgid("SayText");
		saytext_used = true;
	}
	message_begin(type, get_user_msgid_saytext, _, id);
	write_byte(id)
	write_string(message);
	message_end();
}

Team_Info(id, type, team[])
{
	static bool:teaminfo_used;
	static get_user_msgid_teaminfo;
	if(!teaminfo_used)
	{
		get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
		teaminfo_used = true;
	}
	message_begin(type, get_user_msgid_teaminfo, _, id);
	write_byte(id);
	write_string(team);
	message_end();

	return 1;
}

ColorSelection(index, type, Color:Type)
{
	switch(Type)
	{
		case RED:
		{
			return Team_Info(index, type, TeamName[1]);
		}
		case BLUE:
		{
			return Team_Info(index, type, TeamName[2]);
		}
		case GREY:
		{
			return Team_Info(index, type, TeamName[0]);
		}
	}

	return 0;
}

FindPlayer()
{
	new i = -1;

	while(i <= get_maxplayers())
	{
		if(is_user_connected(++i))
			return i;
	}

	return -1;
}
Open RankSystem.ini and add the following in the [XP Rewards] section:

Код за потвърждение: Избери целия код

equation_min = 1
equation_max = 20
You can change these numbers if you want to modify the random interval.

Аватар
TheRaiD
Извън линия
Foreigner
Foreigner
Мнения: 32
Регистриран на: 20 Яну 2019, 20:22
Се отблагодари: 5 пъти
Получена благодарност: 1 път

add XP in plugin Equation Quest

Мнение от TheRaiD » 18 Авг 2019, 15:34

works thankss!!

Заключено
  • Подобни теми
    Отговори
    Преглеждания
     Последно мнение

Обратно към “Поддръжка / Помощ”

Кой е на линия

Потребители разглеждащи този форум: Bing [Bot] и 6 госта