Raised This Month: $ Target: $400
 0% 

About AutoJoin plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ali0mer
Senior Member
Join Date: Jan 2016
Location: Iraq
Old 06-13-2023 , 11:53   About AutoJoin plugin
Reply With Quote #1

Hello guys,

I wanted to to make an ini file for this plugin where i can write the names of players that i dont want them to get auto joined by this plugin

I tried to read this tuto
But i couldnt understand anything

Here is the code
Code:
#include <amxmodx>

#define IMMUNITY_ACCESS_LEVEL ADMIN_IMMUNITY

#define AUTO_TEAM_JOIN_DELAY 0.1

#define TEAM_SELECT_VGUI_MENU_ID 2

new g_pcvar_team
new g_pcvar_class

new filename[256]

public plugin_init() {

	register_plugin("AutoJoin", "2.0b", "None");
	
        get_configsdir(filename,255)
        format(filename,255,"%s/block_list.txt",filename) 
 

	register_message(get_user_msgid("ShowMenu"), "message_show_menu")
	register_message(get_user_msgid("VGUIMenu"), "message_vgui_menu")

	g_pcvar_team = register_cvar("ajc_team", "5")
	g_pcvar_class = register_cvar("ajc_class", "5")
}

public message_show_menu(msgid, dest, id) {
	if (!should_autojoin(id))
		return PLUGIN_CONTINUE

	static team_select[] = "#Team_Select"
	static menu_text_code[sizeof team_select]
	get_msg_arg_string(4, menu_text_code, sizeof menu_text_code - 1)
	if (!equal(menu_text_code, team_select))
		return PLUGIN_CONTINUE

	set_force_team_join_task(id, msgid)

	return PLUGIN_HANDLED
}

public message_vgui_menu(msgid, dest, id) {
	if (get_msg_arg_int(1) != TEAM_SELECT_VGUI_MENU_ID || !should_autojoin(id))
		return PLUGIN_CONTINUE

	set_force_team_join_task(id, msgid)

	return PLUGIN_HANDLED
}

bool:should_autojoin(id) {
	return (get_pcvar_num(g_pcvar_team) && !get_user_team(id) && !task_exists(id))
        new fsize = file_size(filename,1)
        for (new line=0;line<=fsize;line++)
        {
            read_file(filename,line,readdata,127,txtlen)
}

set_force_team_join_task(id, menu_msgid) {
	static param_menu_msgid[2]
	param_menu_msgid[0] = menu_msgid
	set_task(AUTO_TEAM_JOIN_DELAY, "task_force_team_join", id, param_menu_msgid, sizeof param_menu_msgid)
}

public task_force_team_join(menu_msgid[], id) {
	if (get_user_team(id))
		return

	static team[2], class[2]
	get_pcvar_string(g_pcvar_team, team, sizeof team - 1)
	get_pcvar_string(g_pcvar_class, class, sizeof class - 1)
	force_team_join(id, menu_msgid[0], team, class)
}

stock force_team_join(id, menu_msgid, /* const */ team[] = "5", /* const */ class[] = "0") {
	static jointeam[] = "jointeam"
	if (class[0] == '0') {
		engclient_cmd(id, jointeam, team)
		return
	}

	static msg_block, joinclass[] = "joinclass"
	msg_block = get_msg_block(menu_msgid)
	set_msg_block(menu_msgid, BLOCK_SET)
	engclient_cmd(id, jointeam, team)
	engclient_cmd(id, joinclass, class)
	set_msg_block(menu_msgid, msg_block)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
I added the new filename and the one in plugin_init but what about the others where should i added the other codes here?
can someone show me example
thank you

Last edited by Ali0mer; 06-13-2023 at 11:55.
Ali0mer is offline
Send a message via Skype™ to Ali0mer
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-13-2023 , 23:56   Re: About AutoJoin plugin
Reply With Quote #2

A couple things:
  • You shouldn't read the file every time you call your function. Read the file once in plugin_init() and cache the data into an array of strings (or even better would be a Trie but that might be more complex) and also cache the number of SteamIDs that were loaded. Then, you loop through that array to check if the player is "in the list" (this loop can be optimized out entirely if you use a Trie).
  • When reading a whole file, do not use the read_file() method. Use the fgets() method instead. If you ever plan on writing plugins in the future, you'll want to learn this method and use it for nearly all file reading requirements.

There isn't much else to say about it that I can see until you finish writing the should_autojoin() function.
__________________
fysiks 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 01:04.


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