AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   problem while handling a say command (https://forums.alliedmods.net/showthread.php?t=92727)

Cader 05-18-2009 20:48

problem while handling a say command
 
I want to make a command that changes server's current password immediately. A say command like; .svpass <newPassword>

I made a code that works but not properly. If I use "say .svpass 12345" via console, it works. But it doesnt when I try do this by pressing "y" key to say, then type .svpass 12345 , nothing happens.

Here is what I coded :

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

public plugin_init()
{
        
register_plugin(PLUGINVERSIONAUTHOR)
        
register_clcmd("say .svpass""pass")
}


public 
pass (id) {
new 
newpass[32]
read_argv(1newpass31)
server_cmd("sv_password %s"newpass)
return 
PLUGIN_HANDLED



Hunter-Digital 05-18-2009 21:32

Re: problem while handling a say command
 
edit:

tested and works:
PHP Code:

#include <amxmodx>
 
#define SVPASS_CMD ".svpass"
#define SVPASS_LEN 7 // how many chars the cmd has
 
public plugin_init() 
{
    
register_clcmd("say""hookSay")
}
 
public 
hookSay(id)
{
    static 
msg[192]
 
    
read_args(msg191)
    
remove_quotes(msg)
    
trim(msg)
 
    if(!
equali(msgSVPASS_CMDSVPASS_LEN))
        return 
PLUGIN_CONTINUE
 
    copy
(msg191msg[SVPASS_LEN+1]) // remove the ".svpass" from string
 
    
server_cmd("sv_password ^"%s^""msg)
 
    
client_print(0print_chat"(test) Server password changed to: %s"msg// you can remove this
 
    
return PLUGIN_HANDLED



Cader 05-18-2009 21:40

Re: problem while handling a say command
 
hmm, maybe it works. But I didn't like this method. Do we have to catch svpass in this way? Coz I have more "say" commands and I dont want to use all in one function and using if/elses :shock:

Hunter-Digital 05-18-2009 21:45

Re: problem while handling a say command
 
You could use just IF :lol:

PHP Code:

public hookSay(id)
{
    static 
msg[192]
 
    
read_args(msg191)
    
remove_quotes(msg)
    
trim(msg)
 
    if(
equali(msgSVPASS_CMDSVPASS_LEN))
    {
        
copy(msg191msg[SVPASS_LEN+1])
        
server_cmd("sv_password ^"%s^""msg)
        
client_print(0print_chat"(test) Server password changed to: %s"msg)
 
        return 
PLUGIN_HANDLED
    
}
 
    if(
equali(msg".hostname"9))
    {
        
copy(msg191msg[9])
        
server_cmd("hostname ^"%s^""msg)
 
        return 
PLUGIN_HANDLED
    
}
 
    return 
PLUGIN_CONTINUE


Anyway, another method I do not know, search through plugins that does this thing you want and see their methods :P

Cader 05-18-2009 22:06

Re: problem while handling a say command
 
thank you anyway, is it possible to use more than one register to "say" command? like ;

public plugin_init()
{
register_clcmd("say", "SVPass")
register_clcmd("say", "HostName")
}

fysiks 05-18-2009 22:32

Re: problem while handling a say command
 
Yes (I think, try it and find out). Also, I don't see why your first code won't work.

Dores 05-18-2009 23:56

Re: problem while handling a say command
 
Quote:

Originally Posted by fysiks (Post 830264)
Also, I don't see why your first code won't work.

it's because you can't retrieve any other arguments from the say command, except for all arguments together like Hunter-Digital did, and then you need to separate each word.

fysiks 05-19-2009 19:27

Re: problem while handling a say command
 
Quote:

Originally Posted by Dores (Post 830281)
it's because you can't retrieve any other arguments from the say command, except for all arguments together like Hunter-Digital did, and then you need to separate each word.

Oh, I get it now :). Thanks for the explaination.

Dores 05-19-2009 23:57

Re: problem while handling a say command
 
lol, sorry, but i don't really know why it's like that, i just know it is.


All times are GMT -4. The time now is 01:31.

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