Raised This Month: $ Target: $400
 0% 

Words as number/GetCmdArgString/String Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-13-2010 , 11:27   Words as number/GetCmdArgString/String Help
Reply With Quote #1

Hey,
The command should be
sm_smsay [target] "text"
Where when an admin types "sm_smsay Prop Hi" It will print this to everyone:
[SM] PropKiller Wants PropKiller to say 0.
instead of
[SM] PropKiller Wants PropKiller to say Hi.

Here is the whole callback.

PHP Code:
public Action:Command_SMSay(clientargs

    new 
String:arg1[32]; 
    
decl String:saying[192]; 
    
GetCmdArgString(sayingsizeof(saying)); 
  
    new 
String:target_name[MAX_TARGET_LENGTH]; 
    new 
target_list[MAXPLAYERS], target_count
    new 
bool:tn_is_ml
  
    if ((
target_count ProcessTargetString
            
arg1
            
client
            
target_list
            
MAXPLAYERS
            
COMMAND_FILTER_ALIVE
            
target_name
            
sizeof(target_name), 
            
tn_is_ml)) <= 0
    { 
        
ReplyToTargetError(clienttarget_count); 
        return 
Plugin_Handled
    } 
  
    for (new 
0target_counti++) 
    { 
        
LogAction(clienttarget_list[i], "\"%L\" wants  \"%L\" to say: %d"clienttarget_list[i], saying); 
    } 
  
    if (
tn_is_ml
    { 
        
ShowActivity2(client"[SM] ""Wanted %t to say %d "target_namesaying); 
    } 
    else 
    { 
        
ShowActivity2(client"[SM] ""Wanted %s to say %d "target_namesaying); 
    } 
  
    return 
Plugin_Handled

Whats the problem with my callback?
Thanks.

Last edited by PropKiller; 07-17-2010 at 11:21.
PropKiller is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-13-2010 , 12:15   Re: Words showing up as number.
Reply With Quote #2

You are using

Code:
GetCmdArgString(String:buffer[], maxlength);
in the command callback?

You should probably post the command callback.
__________________
Greyscale is offline
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-13-2010 , 12:25   Re: Words showing up as number.
Reply With Quote #3

Im sorta new to sourcepawn. I know that I am not using GetCmdArgString anywhere. I see GetCmdArg in 2 places. Here is where I see them.
PHP Code:
    GetCmdArg(1arg1sizeof(arg1));
 
    if (
args >= && GetCmdArg(2arg2sizeof(arg2)))
    {
        
item StringToInt(arg2);
    } 
And thats in
public Action:Command_SMSay(client, args)
of course.
PropKiller is offline
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-13-2010 , 14:37   Re: Words showing up as number.
Reply With Quote #4

Quote:
Originally Posted by PropKiller View Post
Im sorta new to sourcepawn.
Where would the callback be?
PropKiller is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-13-2010 , 22:44   Re: Words showing up as number.
Reply With Quote #5

Command_SMSay is known as a callback function because it is called when a command is used.

Another example would be a timer callback. If an SM native requires a function name as a parameter, then that function is known as a callback.

http://en.wikipedia.org/wiki/Callbac...puter_science)

The code that you pasted won't work.

Code:
public Action:Command_SMSay(client, args)
{
    decl String:text[192];
    GetCmdArgString(text, sizeof(text));
    PrintToChatAll("[SM] %s", text);
}
That callback above would get all of the text entered after the command and print it to chat with [SM] before it. Which I believe is what you are trying to do.
__________________
Greyscale is offline
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-16-2010 , 09:21   Re: Words showing up as number.
Reply With Quote #6

Look at the first post. I edited it.
Can anyone help?

Last edited by PropKiller; 07-16-2010 at 09:30.
PropKiller is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 07-16-2010 , 09:53   Re: Words showing up as number.
Reply With Quote #7

%d is for digits, use %s for strings.
Wazz is offline
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-17-2010 , 09:30   Re: Words showing up as number.
Reply With Quote #8

That didn't fix it. Whats wrong with this?:
PHP Code:
    decl String:saying[192]; 
    
GetCmdArgString(sayingsizeof(saying)); 
That is the only part that has to do with the saying or text.
( sm_smsay [target] "text" )

When I type sm_smsay Prop Hi
it says this:
[SM] PropKiller Wants PropKiller to say .
PropKiller is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-17-2010 , 19:10   Re: Words as number/GetCmdArgString/String Help
Reply With Quote #9

Study this code:
PHP Code:
public Action:Command_SMSay(clientargs) {
    
decl String:arg[192], String:text[192-MAX_TARGET_LENGTH]; // separate the target from the text
    
GetCmdArgString(argsizeof arg);
    
    new 
space FindCharInString(arg' ');
    
strcopy(textsizeof textarg[space]); // copy the text to a separate string
    
TrimString(text);
    
    
arg[space] = 0// terminate arg on the space
    
    
new String:target_name[MAX_TARGET_LENGTH]; 
    new 
target_list[MAXPLAYERS], target_count
    new 
bool:tn_is_ml
    
    if ((
target_count ProcessTargetString(
            
arg,
            
client,
            
target_list,
            
MAXPLAYERS,
            
COMMAND_FILTER_ALIVE,
            
target_name,
            
sizeof target_name,
            
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
    }
    
    for (new 
0target_count; ++i) {
        
LogAction(clienttarget_list[i], "\"%L\" wants \"%L\" to say: %s"clienttarget_list[i], text); // %s for strings
    
}
    
    if (
tn_is_ml)  { 
        
ShowActivity2(client"[SM] ""Wanted %t to say %s"target_nametext); // idem
    
} else { 
        
ShowActivity2(client"[SM] ""Wanted %s to say %s"target_nametext); // ibidem
    
}
    
    return 
Plugin_Handled

Seta00 is offline
PropKiller
Member
Join Date: Nov 2009
Location: South-East USA
Old 07-17-2010 , 20:35   Re: Words as number/GetCmdArgString/String Help
Reply With Quote #10

Thanks so much!!!
PropKiller is offline
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 13:02.


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