Can add refresh in file .ini

В този раздел можете да подавате всякакви заявки за намиране, изработка или преработка на плъгини/модове.
Аватар
lantimilan
Извън линия
Foreigner
Foreigner
Мнения: 424
Регистриран на: 29 Ное 2017, 22:49
Се отблагодари: 31 пъти
Получена благодарност: 3 пъти

Can add refresh in file .ini

Мнение от lantimilan » 14 Фев 2019, 09:10

Hello i have one plugins my friend he sent me and i want to ask plugin have file .ini but i want to set one function for refresh all 5 second file .ini not to wait to change map, and if you can see how much names can i set in this plugin or not limited ?

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

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Lista Zeze"
#define VERSION "1.0"
#define AUTHOR "DPS Staff"

new const user_file[] = "dps_list.ini"
new Array:BlackList

new cvar_blacklist_handle
new cvar_blacklist_bantype, cvar_blacklist_bantime

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	cvar_blacklist_handle = register_cvar("bl_handle", "2") // 1 = Kick | 2 = Ban
	
	cvar_blacklist_bantype = register_cvar("bl_ban_type", "2") // 1 = Ban SteamID | 2 = Ban IP
	cvar_blacklist_bantime = register_cvar("bl_ban_time", "120") // Minutes
}

public plugin_precache()
{
	BlackList = ArrayCreate(32, 1)
	read_user_from_file()
}

public read_user_from_file()
{
	static user_file_url[64], config_dir[32]
	
	get_configsdir(config_dir, sizeof(config_dir))
	format(user_file_url, sizeof(user_file_url), "%s/%s", config_dir, user_file)
	
	if(!file_exists(user_file_url))
		return
	
	static file_handle, line_data[64], line_count
	file_handle = fopen(user_file_url, "rt")
	
	while(!feof(file_handle))
	{
		fgets(file_handle, line_data, sizeof(line_data))
		
		replace(line_data, charsmax(line_data), "^n", "")
		
		if(!line_data[0] || line_data[0] == ';') 
			continue
			
		ArrayPushString(BlackList, line_data)
		line_count++
	}
	
	fclose(file_handle)
}

public client_connect(id)
{
	check_and_handle(id)
}

public client_infochanged(id)
{
	check_and_handle(id)
}

public check_and_handle(id)
{
	static name[64], steamid[64], Data[32]
	
	get_user_name(id, name, sizeof(name))
	get_user_authid(id, steamid, sizeof(steamid))
	
	for(new i = 0; i < ArraySize(BlackList); i++)
	{
		ArrayGetString(BlackList, i, Data, sizeof(Data))
		
		if(equal(name, Data) || equal(steamid, Data))
		{
			if(get_pcvar_num(cvar_blacklist_handle) == 1) // Kick
			{
				server_cmd("amx_kick %s BlackList", name)
				
				client_printcolor(0, "!g[DPS]!y !t%s!y eshte ne Listen e Zeze ---> Kicked !t%s!y !!!", name, name)
			} else if(get_pcvar_num(cvar_blacklist_handle) == 2) { // Ban
				if(get_pcvar_num(cvar_blacklist_bantype) == 1) // Ban SteamID
				{
					server_cmd("amx_ban %s BlackList %i", steamid, get_pcvar_num(cvar_blacklist_bantime))
				} else if(get_pcvar_num(cvar_blacklist_bantype) == 2) { // BanIP
					server_cmd("amx_banip %s BlackList %i", name, get_pcvar_num(cvar_blacklist_bantime))
				}
				
				client_printcolor(0, "!g[DPS]!y !t%s!y eshte ne Listen e Zeze ---> Banned !t%s!y for | %i minuta !!!", name, name, get_pcvar_num(cvar_blacklist_bantime))				
			}
		}
	}		
}

stock client_printcolor(const id, const input[], any:...)
{
	new iCount = 1, iPlayers[32]
	static szMsg[191]
	
	vformat(szMsg, charsmax(szMsg), input, 3)
	replace_all(szMsg, 190, "!g", "^4")
	replace_all(szMsg, 190, "!y", "^1")
	replace_all(szMsg, 190, "!t", "^3")
	
	if(id) iPlayers[0] = id
	else get_players(iPlayers, iCount, "ch")
	
	for (new i = 0; i < iCount; i++)
	{
		if(is_user_connected(iPlayers[i]))
		{
			message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, iPlayers[i])
			write_byte(iPlayers[i])
			write_string(szMsg)
			message_end()
		}
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1066\\ f0\\ fs16 \n\\ par }
*/

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

Can add refresh in file .ini

Мнение от OciXCrom » 15 Фев 2019, 14:34

If you're using AMXX 1.9, there's an easier method - instead of reading every 5 seconds, we can add a check to see if the file was modified and if it was - read it again.

Аватар
lantimilan
Извън линия
Foreigner
Foreigner
Мнения: 424
Регистриран на: 29 Ное 2017, 22:49
Се отблагодари: 31 пъти
Получена благодарност: 3 пъти

Can add refresh in file .ini

Мнение от lantimilan » 15 Фев 2019, 17:44

Im using 1.8.3

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

Can add refresh in file .ini

Мнение от OciXCrom » 15 Фев 2019, 19:56

I made it check every 15 seconds. You can change the duration in the beginning of the code.

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

#include <amxmodx>
#include <amxmisc>

// Edit by OciXCrom: added auto file read every X seconds
#define PLUGIN "Lista Zeze"
#define VERSION "1.1"
#define AUTHOR "DPS Staff"

const Float:refresh_delay = 15.0
new const user_file[] = "dps_list.ini"
new Array:BlackList

new user_file_url[64]
new last_file_time
new cvar_blacklist_handle
new cvar_blacklist_bantype, cvar_blacklist_bantime

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)

	cvar_blacklist_handle = register_cvar("bl_handle", "2") // 1 = Kick | 2 = Ban

	cvar_blacklist_bantype = register_cvar("bl_ban_type", "2") // 1 = Ban SteamID | 2 = Ban IP
	cvar_blacklist_bantime = register_cvar("bl_ban_time", "120") // Minutes
}

public plugin_precache()
{
	BlackList = ArrayCreate(32, 1)
	read_user_from_file()
	set_task(refresh_delay, "check_file_time")
}

public plugin_end()
	ArrayDestroy(BlackList)

public read_user_from_file()
{
	new config_dir[32]

	get_configsdir(config_dir, sizeof(config_dir))
	format(user_file_url, sizeof(user_file_url), "%s/%s", config_dir, user_file)

	if(!file_exists(user_file_url))
		return

	new file_handle, line_data[64]
	file_handle = fopen(user_file_url, "rt")

	while(!feof(file_handle))
	{
		fgets(file_handle, line_data, sizeof(line_data))

		replace(line_data, charsmax(line_data), "^n", "")

		if(!line_data[0] || line_data[0] == ';')
			continue

		ArrayPushString(BlackList, line_data)
	}

	fclose(file_handle)
	last_file_time = GetFileTime(user_file_url, FileTime_LastChange)
}

public check_file_time()
{
	if(last_file_time != GetFileTime(user_file_url, FileTime_LastChange))
	{
		ArrayClear(BlackList)
		read_user_from_file()
	}
}

public client_connect(id)
{
	check_and_handle(id)
}

public client_infochanged(id)
{
	check_and_handle(id)
}

public check_and_handle(id)
{
	static name[64], steamid[64], Data[32]

	get_user_name(id, name, sizeof(name))
	get_user_authid(id, steamid, sizeof(steamid))

	for(new i = 0; i < ArraySize(BlackList); i++)
	{
		ArrayGetString(BlackList, i, Data, sizeof(Data))

		if(equal(name, Data) || equal(steamid, Data))
		{
			if(get_pcvar_num(cvar_blacklist_handle) == 1) // Kick
			{
				server_cmd("amx_kick %s BlackList", name)

				client_printcolor(0, "!g[DPS]!y !t%s!y eshte ne Listen e Zeze ---> Kicked !t%s!y !!!", name, name)
			} else if(get_pcvar_num(cvar_blacklist_handle) == 2) { // Ban
				if(get_pcvar_num(cvar_blacklist_bantype) == 1) // Ban SteamID
				{
					server_cmd("amx_ban %s BlackList %i", steamid, get_pcvar_num(cvar_blacklist_bantime))
				} else if(get_pcvar_num(cvar_blacklist_bantype) == 2) { // BanIP
					server_cmd("amx_banip %s BlackList %i", name, get_pcvar_num(cvar_blacklist_bantime))
				}

				client_printcolor(0, "!g[DPS]!y !t%s!y eshte ne Listen e Zeze ---> Banned !t%s!y for | %i minuta !!!", name, name, get_pcvar_num(cvar_blacklist_bantime))
			}
		}
	}
}

stock client_printcolor(const id, const input[], any:...)
{
	new iCount = 1, iPlayers[32]
	static szMsg[191]

	vformat(szMsg, charsmax(szMsg), input, 3)
	replace_all(szMsg, 190, "!g", "^4")
	replace_all(szMsg, 190, "!y", "^1")
	replace_all(szMsg, 190, "!t", "^3")

	if(id) iPlayers[0] = id
	else get_players(iPlayers, iCount, "ch")

	for (new i = 0; i < iCount; i++)
	{
		if(is_user_connected(iPlayers[i]))
		{
			message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, iPlayers[i])
			write_byte(iPlayers[i])
			write_string(szMsg)
			message_end()
		}
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1066\\ f0\\ fs16 \n\\ par }
*/
If it doesn't work, you're using a very old 1.8.3 version and you should upgrade to 1.9.

Аватар
lantimilan
Извън линия
Foreigner
Foreigner
Мнения: 424
Регистриран на: 29 Ное 2017, 22:49
Се отблагодари: 31 пъти
Получена благодарност: 3 пъти

Can add refresh in file .ini

Мнение от lantimilan » 15 Фев 2019, 20:17

Thanks bro very much closed thread

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

Обратно към “Заявки за плъгини”

Кой е на линия

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