AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   register_clcmd with parameter? [SOLVED] (https://forums.alliedmods.net/showthread.php?t=48425)

James 12-11-2006 16:16

register_clcmd with parameter? [SOLVED]
 
Hello, can I somehow add parameter to register_clcmd command? I want one function (with parameter), which will be called by more register_clcmds.. Like change map...

Now I must copy 2 same function (with different mapname)
register_clcmd("say /cbble", "cmd_cbble", 0, "- changelevel de_cbble")
register_clcmd("say /cpl_mill", "cmd_cpl_mill", 0, "- changelevel de_cpl_mill")


I would like something like this:
register_clcmd("say /cbble", "cmd_changemap('cbble')", 0, "- changelevel de_cbble")
register_clcmd("say /cpl_mill", "cmd_changemap('mill')", 0, "- changelevel de_cpl_mill")

cmd_changemap(id,name[]) {
...
}

Much cleaner code.. Any help please?

schnitzelmaker 12-11-2006 16:30

Re: register_clcmd with parameter?
 
for say command you can use the say event here an code example
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "Administrator" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say", "handle_say") } public handle_say(id){ new nums = read_argc()//read_argc return how many parameter are given in the say client_print(id,print_chat,"You have say %d commands/parameter",nums) for (new i = 1; i < read_argc(); i++) {         new command[32]         read_argv(i, command, 31) //read_argv read the i parameter and store it into command         client_print(id,print_chat,"You %d paramter is %s",i,command)     } new say[128] read_args(say,127) //read_args return the fully string who was say client_print(id,print_chat,"You fully say is: %s",say) }

James 12-11-2006 16:35

Re: register_clcmd with parameter?
 
Interesting, I will try it!

dutchmeat 12-11-2006 16:39

Re: register_clcmd with parameter?
 
Try this:

Code:
register_clcmd("say","cmd_changemap") register_clcmd("say_team","cmd_changemap") cmd_changemap(id){ new said[191] read_args(said,190) remove_quotes(said) if(equali(said,"/cbble")){ server_cmd("changelevel de_cbble") return PLUGIN_HANDLED //Do not show the text that has been said,pointless }else if(equali(said,"/cpl_mill")){ server_cmd("changelevel de_cpl_mill") return PLUGIN_HANDLED //Dito } return PLUGIN_CONTINUE }

James 12-11-2006 16:47

Re: register_clcmd with parameter?
 
I see only way is controll every say text in the game :/ Dont know if it is good solution (many say texts in PUB servers) ... I trying keep CPU usage lowest as possible

dutchmeat 12-11-2006 16:52

Re: register_clcmd with parameter?
 
then use this;
for admin_kick only,

Code:
register_clcmd("say","cmd_changemap") register_clcmd("say_team","cmd_changemap") cmd_changemap(id){ if(!access(id, ADMIN_KICK))  return PLUGIN_CONTINUE //let the msg go, if not an admin new said[191] read_args(said,190) remove_quotes(said)  if(equali(said,"/cbble")){   server_cmd("changelevel de_cbble")   return PLUGIN_HANDLED //Do not show the text that has been said,pointless  }else if(equali(said,"/cpl_mill")){   server_cmd("changelevel de_cpl_mill")   return PLUGIN_HANDLED //Dito  } return PLUGIN_CONTINUE }

schnitzelmaker 12-11-2006 17:32

Re: register_clcmd with parameter?
 
Quote:

I see only way is controll every say text in the game :/ Dont know if it is good solution (many say texts in PUB servers) ... I trying keep CPU usage lowest as possible
you can also use only
Code:
register_clcmd("say /cbble", "handle_say", 0, "- changelevel de_cbble") register_clcmd("say /cpl_mill", "handle_say", 0, "- changelevel de_cpl_mill")
to sort it out.

But it is the same to sort it in the say function or in register_clmd.

James 12-11-2006 17:34

Re: register_clcmd with parameter?
 
Yeah.. Sometimes I think I am stupid :)

Problem solved, code is cleaner, ADMIN acces, say /command, and then controll say by handle_say.. Thanks a Lot! Karma +

VEN 12-12-2006 07:57

Re: register_clcmd with parameter? [SOLVED]
 
Quote:

I trying keep CPU usage lowest as possible
FYI: the metod above isn't CPU intensive.


All times are GMT -4. The time now is 06:57.

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