View Single Post
Ingram
Veteran Member
Join Date: May 2004
Old 05-09-2004 , 16:50  
Reply With Quote #24

ok a simple plugin AMX_FF by JustinHoMi might be a good exmaple (If u don't want me to use your plugin as an example, say so and i'll remove it)

First thing u want to know what the plugin does, so run it, next look at the init
Code:
public plugin_init(){
	register_plugin("Admin FF","0.21","JustinHoMi")
	register_concmd("amx_ff","admin_ff",ADMIN_CVAR,"< 0/1 >")
	register_clcmd("say /ff","check_ff")
	return PLUGIN_CONTINUE
}
register_plugin("Admin FF","0.21","JustinHoMi") is the author's info to put in, register_concmd is a command that the server or a client can run (this is important), register_clcmd is a command that only clients can run (also important). return PLUGIN_CONTINUE means u dont want the plugin to end. PLUGIN_HANDLED means u want it to stop.(You don't need to put a return in the init, so my recommendation is dont)

I'll start easier, the client command(commands are what u would type in console, but pressing a key u also run the command in your console) say /ff, runs check_ff
Code:
public check_ff(id) {
	new ff = get_cvar_num("mp_friendlyfire")
	if(ff == 1)
		client_print(id,print_chat,"[AMXX] Friendly fire is on")
	else if(ff == 0)
		client_print(id,print_chat,"[AMXX] Friendly fire is off")
	return PLUGIN_HANDLED
}
first thing this does is it gets the value of mp_friendlyfire and puts it in the value ff, if ff is 1, friendly fire is on and it tells the client that, if not it tells the client its not on

now the harder one, amx_ff, when u type it in console it runs admin_ff
Code:
public admin_ff(id,level,cid){
	if (!cmd_access(id,level,cid,2))   // I changed this part
      		return PLUGIN_HANDLED 

	new ff_s[2]
	read_argv(1,ff_s,2)
	new ff = str_to_num(ff_s)

	if(ff == 1) {
		server_cmd("mp_friendlyfire 1")
		console_print(id,"[AMXX] Friendly fire is now on")
	}
	else if(ff == 0) {
		server_cmd("mp_friendlyfire 0")
		console_print(id,"[AMXX] Friendly fire is now off")
	}

	return PLUGIN_HANDLED
}
if (!cmd_access(id,level,cid,2)) is used to check if they have access and the correct # of arguments has been entered, if not it kicks them outta the plugin (if they have access, but an incorrect # of arguments. it'll give them the help for the command, but that isn't in this plugin (anymore)) new ff_s[2] is creating a array for input, each character that the admin enter, if they entered 12, takes a place in the array, so that would take 2 spaces. read_argv(1,ff_s,2) is reading in the 1st (notice the 1) argument after the command that the admin has entered, ff_s is where it is being read into, and 2 is the maximum length it can be. new ff = str_to_num(ff_s) changes the array u just read in into a #. The rest u should need help with by now.


Now that i have told u the basics of a plugin, u should be able to understand many of them, any natives (commands sorta) in the plugins u don't understand, look in the includes first, then ask questions on them. Sorry if this didn't help, but i can only try.
Edit: Wow i really coulda wrote a new plugin in that time!
Ingram is offline