Raised This Month: $51 Target: $400
 12% 

Solved Passing arguments to messagemode


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-17-2018 , 17:13   Passing arguments to messagemode
Reply With Quote #1

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!
__________________

Last edited by edon1337; 08-18-2018 at 06:49.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-17-2018 , 18:03   Re: Passing arguments to messagemode
Reply With Quote #2

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" );
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-17-2018 , 18:21   Re: Passing arguments to messagemode
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
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

__________________

Last edited by edon1337; 08-17-2018 at 18:31.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-17-2018 , 19:44   Re: Passing arguments to messagemode
Reply With Quote #4

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.
__________________

Last edited by OciXCrom; 08-17-2018 at 19:44.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
CrAzY MaN
Senior Member
Join Date: Mar 2017
Location: India
Old 08-17-2018 , 22:28   Re: Passing arguments to messagemode
Reply With Quote #5

Quote:
Originally Posted by edon1337 View Post
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.
__________________
CrAzY MaN is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 06:49   Re: Passing arguments to messagemode
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
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 View Post
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.
__________________
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-18-2018 , 17:07   Re: Passing arguments to messagemode
Reply With Quote #7

That's exactly what I meant. You can check my JailBreak Reasons plugin for a very similar usage like yours.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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