AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple plugin not working (https://forums.alliedmods.net/showthread.php?t=55759)

slmclarengt 05-29-2007 01:25

Simple plugin not working
 
1 Attachment(s)
This isn't working - I just wrote it today with some referencing to other plugins/documentation so I bet there are a few mistakes I overlooked but I usually don't detect them until I stop looking at them for weeks :-). But, you can probably find them b/c you haven't looked at them before :-).

Slmclarengt

P.S. Function is to "list all available maps on the server --> client"

Sylwester 05-29-2007 07:55

Re: Simple plugin not working
 
You shouldn't make it this way. It's not a good idea to give rcon password to players, but anyway this is how to fix this plugin:

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say""check_say")    //check say this way
    
register_clcmd("say_team""check_say")   //check say_team this way
    
register_clcmd("amx_maps""cmdListMaps", -1"Lists ALL available maps - * or blank for all otherwise <prefix> (eg: surf)")
}


public 
check_say(id)
{
    new 
said[32]
    new 
arg1[32]
    new 
arg2[32]

    
read_args(said31)
    
remove_quotes(said)
    
strbreak(saidarg131arg231)    //split string
    //check if first arg. equals desired command
    
if (equali(arg1"/maps") || equali(arg1"maps"))  
        
executeListMaps(idarg2)    //send prefix or empty string as an arg.
}

public 
cmdListMaps(id)
{
    new 
arg1[17]
    
read_argv(1arg116)
    
executeListMaps(idarg1)
}

public 
executeListMaps(idparam[])
{
    new 
maps_cmd[33]
    new 
prefix_to_send[16]
    
    new 
arg1[17]
    
copy(arg116param)

    new 
password[64]
    
get_cvar_string("rcon_password"password63)
    if (!
arg1[0])
    {
        
format(prefix_to_send1"*")
        
format(maps_cmd32"maps %s"prefix_to_send)
        
client_cmd(id"rcon_password %s"password)
        
client_cmd(id"rcon %s"maps_cmd)
    }
    else
    {
        
remove_quotes(arg1)
        
copy(prefix_to_send16arg1)
        
format(maps_cmd32"maps %s"prefix_to_send)
        
client_cmd(id"rcon_password %s"password)
        
client_cmd(id"rcon %s"maps_cmd)
    }
    return 
PLUGIN_HANDLED



anssik 05-29-2007 08:20

Re: Simple plugin not working
 
This is actually a really good idea! I made some extra protection in it which should make it much more secure.
Code:
new g_oldpass[64] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say", "check_say")    //check say this way     register_clcmd("say_team", "check_say")   //check say_team this way     register_clcmd("amx_maps", "cmdListMaps", -1, "Lists ALL available maps - * or blank for all otherwise <prefix> (eg: surf)")     get_cvar_string("rcon_password", g_oldpass, 63) } public check_say(id) {     new said[32]     new arg1[32]     new arg2[32]     read_args(said, 31)     remove_quotes(said)     strbreak(said, arg1, 31, arg2, 31)    //split string     //check if first arg. equals desired command     if (equali(arg1, "/maps") || equali(arg1, "maps"))           executeListMaps(id, arg2)    //send prefix or empty string as an arg. } public cmdListMaps(id) {     new arg1[17]     read_argv(1, arg1, 16)     executeListMaps(id, arg1) } public executeListMaps(id, param[]) {     new maps_cmd[33]     new prefix_to_send[16]         new arg1[17]     copy(arg1, 16, param)     set_cvar_string("rcon_password", "temporary")     if (!arg1[0])     {         format(prefix_to_send, 1, "*")         format(maps_cmd, 32, "maps %s", prefix_to_send)         client_cmd(id, "rcon_password temporary")         client_cmd(id, "rcon %s", maps_cmd)         client_cmd(id, "rcon_password empty")     }     else     {         remove_quotes(arg1)         copy(prefix_to_send, 16, arg1)         format(maps_cmd, 32, "maps %s", prefix_to_send)         client_cmd(id, "rcon_password temporary")         client_cmd(id, "rcon %s", maps_cmd)         client_cmd(id, "rcon_password empty")     }     set_cvar_string("rcon_password", g_oldpass)     return PLUGIN_HANDLED }

Cheap_Suit 05-29-2007 12:49

Re: Simple plugin not working
 
I think the problem with check_say is that arg1 returns "say". So you need arg2 to the /map and arg3 for the prefix. Also a better way of getting the maps would be reading the maps directory.

PHP Code:

say /map de_ 


Sylwester 05-29-2007 14:03

Re: Simple plugin not working
 
Wrong, "say" is the command and arg1 will never return "say" until you type it in chat or type "say say" in console :P
My version works fine, I checked it.

slmclarengt, even if this work fine I recommend you to rewrite it other way.
ex. store list of maps in file on server, load list on plugin_init to some array and code some function to display it for clients, you can use containi ( const source[], const string[] ) to compare arg. and maps in the array.

stupok 05-29-2007 14:57

Re: Simple plugin not working
 
I would do it like this:

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #define PLUGIN "List Maps" #define VERSION "1.0" #define AUTHOR "stupok69" #define MAP_DIR "maps" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say /maps", "function_list_maps", -1, "lists all maps on server")     register_clcmd("say maps", "function_list_maps", -1, "lists all maps on server")     register_concmd("list_maps", "function_list_maps", -1, "lists all maps on server") } public function_list_maps(id) {     new file[64]         new dirh = open_dir(MAP_DIR, file, 63)         if(dirh)     {         if(containi(file, ".bsp") != -1)         {             console_print(id, file)         }     }     else     {         console_print(id, "Directory (%s) could not be opened.", MAP_DIR)     }         new counter     while(next_file(dirh, file, 63))     {         if(containi(file, ".bsp") != -1)         {             counter++             set_task(0.01 * float(counter), "delay_console_print", id, file, 63)         }     }         close_dir(dirh) } public delay_console_print(params[], id) {     console_print(id, params) }

slmclarengt 05-29-2007 15:35

Re: Simple plugin not working
 
All of your guys ideas were awesome. Thank you very much for the help! +karma to everyone because they all contain things I did not even think of. I got the idea of listing maps because I got so sick of people asking what maps we had and me having to read them off. I'm going to try Stupok's version because the idea I think is the most dynamic and secure - it doesn't give them any password :-) even a temp.

Works beautifully Stupok. I ran down the list of people who helped me and used all my karma up :-\. I'll give you yours tomorrow Stupok :-). It's awesome because unlike the built-in "maps *" command, it doesn't lag the server because it loads them more efficiently. What a surprise eh? AMXX Scripters > VALVe once again.

Score:
AMXX Scripters: Infinite
VALVe: 1

Slmclarengt

anssik 06-01-2007 16:42

Re: Simple plugin not working
 
Where did the 1 point for VALVe come from? For creating CS? :D

Yeah the stupoks version is best. Stupok you should release it as separate plugin since it's so useful.

BTW Thanks for the karma.

Pro Patria Finland 06-01-2007 16:44

Re: Simple plugin not working
 
Quote:

Originally Posted by anssik (Post 484625)
Where did the 1 point for VALVe come from? For creating CS? :DD

BTW Thanks for the karma.

Valve didn't create CS....

regalis 06-01-2007 16:54

Re: Simple plugin not working
 
Quote:

Originally Posted by Pro Patria Finland (Post 484627)
Valve didn't create CS....

1 point for Pro Patria Finland ;)


All times are GMT -4. The time now is 10:37.

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