AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Passing arguments to messagemode (https://forums.alliedmods.net/showthread.php?t=310072)

edon1337 08-17-2018 17:13

Passing arguments to messagemode
 
This code gets logged up to #3, #4 never gets logged, no idea why.
What I've done is a menu that shows some player names, when you select one of them, you should get a messagemode showing:

<playername>: <yourinput>

from where:
<playername> - The name of the player which we selected on the menu (must be passed through somewhere)
<yourinput> - the value that we're going to set in the messagemode.

PHP Code:

public plugin_init( )
{
    
register_clcmd"suspendTime""OnSuspendTime" );
}

public 
OnSuspend_HandleridiMenuiItem )
{
    new 
szPlayerId], iAccessiItemCallback;
    
    
menu_item_getinfoiMenuiItemiAccessszPlayerIdcharsmaxszPlayerId ), __iItemCallback );
    
menu_destroyiMenu );
    
    new 
iTarget str_to_numszPlayerId );
    
    
log_to_file"sss.txt""#1" );
    
    if( ! 
is_user_connectediTarget ) )
    return 
PLUGIN_HANDLED;
    
    
log_to_file"sss.txt""#2" );
    
    new 
szName32 ];
    
get_user_nameiTargetszNamecharsmaxszName ) );
        
    
client_cmdid"messagemode suspendTime ^"%s^""szName );
    
    
log_to_file"sss.txt""#3" );
    return 
PLUGIN_CONTINUE;
}

public 
OnSuspendTimeid )
{
    
log_to_file"sss.txt""#4" );

    new 
szArgs192 ], szTarget32 ]
    
read_argsszArgscharsmaxszArgs ) );
    
remove_quotesszArgs );
    
    
read_argv1szTargetcharsmaxszTarget ) );
    
    
log_to_file"sss.txt""%s | %s | %s"szArgsszTargetszNum );
    
    if( ! 
is_str_numszArgs ) )
    {
        
client_print_coloridDontChange"^4[Suspend System] ^3You can't input letters." );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iMinutes str_to_numszArgs );
    
    if( 
is_negative_numiMinutes ) )
    {
        
client_print_coloridDontChange"^4[Suspend System] ^3You can't input negative numbers." );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iTarget find_player"a"szTarget );
    
    if( ! 
is_user_connectediTarget ) )
    return 
PLUGIN_HANDLED;
    
    
SuspendPlayeriTargetid );
    
SuspendSaveDataiTargetszTargetiMinutes );

    return 
PLUGIN_CONTINUE;


Any help is greatly appreciated, thanks!

OciXCrom 08-17-2018 18:03

Re: Passing arguments to messagemode
 
Code:
client_cmd( id, "messagemode suspendTime ^"%s^"", szName );

I don't think you can do that. Save the name in a variable and add it to the string later.

Code:
client_cmd( id, "messagemode suspendTime" );

edon1337 08-17-2018 18:21

Re: Passing arguments to messagemode
 
Quote:

Originally Posted by OciXCrom (Post 2610832)
Save the name in a variable and add it to the string later.

I can't, there would be no information on who the command will be executed upon.
PHP Code:

#define MAX_PLAYERS 32
#define MAX_NAME_LENGTH 31

new g_szNameHolderMAX_PLAYERS ][ MAX_NAME_LENGTH ];

public 
plugin_init( ) 

    
register_clcmd"suspendTime""OnSuspendTime" ); 


public 
OnSuspend_HandleridiMenuiItem 

    new 
szPlayerId], iAccessiItemCallback
     
    
menu_item_getinfoiMenuiItemiAccessszPlayerIdcharsmaxszPlayerId ), __iItemCallback ); 
    
menu_destroyiMenu ); 
     
    new 
iTarget str_to_numszPlayerId ); 
          
    if( ! 
is_user_connectediTarget ) ) 
    return 
PLUGIN_HANDLED
          
    new 
szName32 ]; 
    
get_user_nameiTargetszNamecharsmaxszName ) ); 
         
    
copyg_szNameHolderiTarget ], charsmaxg_szNameHolder ), szName );
    
client_cmdid"messagemode suspendTime" );
    
    return 
PLUGIN_CONTINUE
}

public 
OnSuspendTimeid 
{
    new 
szArgs192 ];
    
read_argsszArgscharsmaxszArgs ) ); 
    
remove_quotesszArgs ); 
     
    
// we got no ID to identify the person



OciXCrom 08-17-2018 19:44

Re: Passing arguments to messagemode
 
You have iTarget, szPlayerId - save one of them in a global variable - g_iTarget[33] and you can use it in the comnand's body.

CrAzY MaN 08-17-2018 22:28

Re: Passing arguments to messagemode
 
Quote:

Originally Posted by edon1337 (Post 2610838)
I can't, there would be no information on who the command will be executed upon.

I think you must go with what OciXCrom said.
Check my Whatsapp plugin for more example of messagemode.

edon1337 08-18-2018 06:49

Re: Passing arguments to messagemode
 
Quote:

Originally Posted by OciXCrom (Post 2610848)
You have iTarget, szPlayerId - save one of them in a global variable - g_iTarget[33] and you can use it in the comnand's body.

Well, szPlayerId is simply iTarget as a string, but your reply gave me an idea, I created a variable g_iTarget[33] as you said, and did

Code:
g_iTarget[id] = iTarget

When sending client_cmd messagemode, then in the command's handler I used new iTarget = g_iTarget[id]

Quote:

Originally Posted by CrAzY MaN (Post 2610855)
I think you must go with what OciXCrom said.
Check my Whatsapp plugin for more example of messagemode.

Your plugin uses the basic version of the messagemode, I needed to pass something through it.

OciXCrom 08-18-2018 17:07

Re: Passing arguments to messagemode
 
That's exactly what I meant. You can check my JailBreak Reasons plugin for a very similar usage like yours.


All times are GMT -4. The time now is 17:32.

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