AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Someone knows how to... (https://forums.alliedmods.net/showthread.php?t=127924)

#8 SickneSS 05-26-2010 14:28

Someone knows how to...
 
...hook say and make a command called /rr !rr or .rr (NUM) and the server will make a restart depending of the NUM ?

I have tried with strbreak and changing the str to num,but doesn't works.

Sylwester 05-26-2010 14:53

Re: Someone knows how to...
 
PHP Code:

#include <amxmodx>
public plugin_init(){
    
register_clcmd("say""handle_say")
    
register_clcmd("say_team""handle_say")
}

public 
handle_say(id){
    static 
args[32], cmd[16], tmp[16]
    
read_args(args31)
    
remove_quotes(args)
    
parse(argscmd15tmp15)
    if(
equali("rr"cmd[cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.'])){
        
server_cmd("sv_restartround %d"str_to_num(tmp))
    }



#8 SickneSS 05-26-2010 14:56

Re: Someone knows how to...
 
I will test it later,thanks:)

fysiks 05-26-2010 18:28

Re: Someone knows how to...
 
What in the world is this???

Code:

equali("rr", cmd[cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.'])
EDIT:
I figured it out. This bool/int conversion assumption is annoying sometimes. It will also return true if you say "rr".

You should probably change it to:

Code:

equali("rr", cmd[!!(cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.')])

Sylwester 05-27-2010 01:46

Re: Someone knows how to...
 
Why double negation? It doesn't change anything here and in the end it's still auto conversion to int.
Did you mean:
Code:

equali("rr", cmd[_:(cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.')])
?

fysiks 05-27-2010 02:56

Re: Someone knows how to...
 
Quote:

Originally Posted by Sylwester (Post 1192317)
Why double negation? It doesn't change anything here and in the end it's still auto conversion to int.
Did you mean:
Code:

equali("rr", cmd[_:(cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.')])
?

Nope. Essentially this. There is more discussion about it in the thread.

But, now that I think of it, it should be something like:

Code:

equali("rr", cmd[(cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.') ? 1 : 0])
But because Pawn is typeless it may work your way without fail. Basically the result of (cmd[0] == '!' || cmd[0] == '/' || cmd[0] == '.') cannot be -1 or 3 (i.e. anything not 1 or 0; all of which evaluate as true) or it will case a index out of bounds.

Sylwester 05-27-2010 04:59

Re: Someone knows how to...
 
Quote:

Originally Posted by fysiks (Post 1192338)
Nope. Essentially this. There is more discussion about it in the thread.

They used !! in that thread only for conversion int -> bool, but you tried to use it in this thread for conversion bool -> int (it does nothing in this case).

fysiks 05-27-2010 12:06

Re: Someone knows how to...
 
Quote:

Originally Posted by Sylwester (Post 1192390)
They used !! in that thread only for conversion int -> bool, but you tried to use it in this thread for conversion bool -> int (it does nothing in this case).

Yeah, but the result of (var == 3) will not necessarily be 1 or 0. If it's true it could be 34. This is the way I understand it but maybe I am wrong.

#8 SickneSS 05-27-2010 12:16

Re: Someone knows how to...
 
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say","hook")
}

public 
hook(id) {
    
    new 
said[192]
    
read_args(said,191)
    
remove_quotes(said)
    
    new 
Restart[11]
    new 
Value[11]
    
    
strbreak(said,Restart,10,Value,10)

    if(
equali(Restart,"/rr"))
    {
        if(
equal(Value,""))
        {
            
server_cmd("sv_restart 1")
            
client_print(id,print_chat,"Restart por 1")
        }
        else
        {
            
server_cmd("sv_restart %d",str_to_num(Value))
            
client_print(id,print_chat,"Restart por %d",str_to_num(Value))
        }
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE


I Made this,but I can't take if is str num or is more than 60,because if I put that,doesn't do nothing when I put only /rr

btw : i will made a const to type !rr /rr .rr or /r !r .r or !restart /restart .restart

Sylwester 05-27-2010 12:26

Re: Someone knows how to...
 
Quote:

Originally Posted by fysiks (Post 1192657)
Yeah, but the result of (var == 3) will not necessarily be 1 or 0. If it's true it could be 34. This is the way I understand it but maybe I am wrong.

Can you provide an example proving your theory? Because as far as I know the result of (x == y) will always be true or false (converted to int it will always be 1 or 0). The same goes for other logical operators.


All times are GMT -4. The time now is 05:23.

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