SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/07/2019, 02:36 PM   #1
PoniStar
Huge Clucker
 
Join Date: Aug 2018
Posts: 254
Reputation: 0
Default space on sscanf (strings)

hi how can i have space (optional) in sccanf ? for exp for this command : /setclanname name tag i want to be able to have a clan name with spaces like The Viper and TV tag , like : /setclanname The Viper TV i hope you get it , and i dont want to use clan name as the secound var its should be /setclanname [name] [tag]
PoniStar is offline   Reply With Quote
Old 14/07/2019, 03:04 PM   #2
YouShootIDodge
Little Clucker
 
Join Date: May 2019
Posts: 42
Reputation: 11
Default Re: space on sscanf (strings)

Not possible, use dialogs.
YouShootIDodge is offline   Reply With Quote
Old 14/07/2019, 03:05 PM   #3
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 723
Reputation: 131
Default Re: space on sscanf (strings)

Change the order to /setclanname [tag] [name]
Calisthenics is offline   Reply With Quote
Old 14/07/2019, 07:45 PM   #4
=KempeR=
Huge Clucker
 
=KempeR='s Avatar
 
Join Date: Oct 2011
Location: Kyiv, Ukraine
Posts: 253
Reputation: 7
Default Re: space on sscanf (strings)

Or you can try to use Pawn.Regex plugin with this regular expression:
PHP Code:
^\/setclanname\s(.+)\s(.+)$ 
instead of sscanf
__________________
Dafuq am I still doing in SA-MP in 2018?

Sincerely, Kemper
=KempeR= is offline   Reply With Quote
Old 14/07/2019, 08:22 PM   #5
PoniStar
Huge Clucker
 
Join Date: Aug 2018
Posts: 254
Reputation: 0
Default Re: space on sscanf (strings)

kemper can you show the usage of pawn regex in this case ? i need a little explain , do it with that i explain on first post plz
PoniStar is offline   Reply With Quote
Old 14/07/2019, 08:47 PM   #6
ShadowMortar
Big Clucker
 
Join Date: Jul 2016
Location: Croatia
Posts: 93
Reputation: 10
Default Re: space on sscanf (strings)

If I understand, you want this?
PHP Code:
CMD:setclannameplayeridparams[ ] )
{
    new 
clanname50 ], tag50 ];
    if( 
sscanfparams"s[50]s[50]"clannametag ) ) SendClientMessageplayerid, -1"Usage: /setclanname [Clan Name] [Tag]" );
    else
    {
        
//Rest of the code..
    
}
    return 
1;

If you want optional tag:
PHP Code:
if( sscanfparams"s[50]S[50]"clannametag ) ) SendClientMessageplayerid, -1"Usage: /setclanname [Clan Name] [Tag(optional)]" ); 
ShadowMortar is offline   Reply With Quote
Old 14/07/2019, 11:26 PM   #7
=KempeR=
Huge Clucker
 
=KempeR='s Avatar
 
Join Date: Oct 2011
Location: Kyiv, Ukraine
Posts: 253
Reputation: 7
Default Re: space on sscanf (strings)

Quote:
Originally Posted by PoniStar View Post
kemper can you show the usage of pawn regex in this case ? i need a little explain , do it with that i explain on first post plz
I thought a bit and decided that you can do it without a plugin at all. It is silly to connect the whole library for the sake of a single solution.

PHP Code:
#include <a_samp>

public OnFilterScriptInit()
{
    new const
        
params[] = "My clan name ClanTag",
        
strLength strlen(params);
    new 
clanName[32], clanTag[8],
        
spaceIndex = -1;
    
    for (new 
strLength 1>= 0i--)
    {
        if (
params[i] == ' ')
        {
            
spaceIndex i;
            break;
        }
    }
    if (
spaceIndex == -1)
    {
        print(
"Invalid string format");
        return;
    }
    
strmid(clanNameparams0spaceIndex);
    
strmid(clanTagparamsspaceIndex 1strLength);
    if (!
strlen(clanName) || strlen(clanTag))
    {
        print(
"Invalid string format");
        return;
    }
    
printf("Parameter 0: %s\nParameter 1: %s"clanNameclanTag);

UPD:
Okay. Here is the solution using the plugin. It looks certainly fancier.

PHP Code:
#include <a_samp>
#include <Pawn.Regex>

public OnFilterScriptInit()
{
    new const
        
params[] = "My clan name ClanTag",
        
Regex:regEx Regex_New("^(.+)\\s(.+)$");
    new
        
RegexMatch:regExMatch,
        
clanName[32], clanTag[8],
        
clanNameLengthclanTagLength;

    if (
Regex_Match(paramsregExregExMatch))
    {
        
Match_GetGroup(regExMatch1clanNameclanNameLength);
        
Match_GetGroup(regExMatch2clanTagclanTagLength);
        
Match_Free(regExMatch);
    }
    else
    {
        print(
"Invalid string format");
        return;
    }
    
printf("Parameter 0: %s\nParameter 1: %s"clanNameclanTag);

__________________
Dafuq am I still doing in SA-MP in 2018?

Sincerely, Kemper
=KempeR= is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
sscanf kustom specifiers and space X337 Scripting Help 3 20/11/2016 09:01 AM
Strings in array - sscanf CrashCar Scripting Help 7 26/04/2015 02:52 AM
Sscanf strings Golimad Scripting Help 2 15/02/2014 11:09 PM
[Help] sscanf warning [Strings] GBLTeam Scripting Help 0 25/01/2014 07:45 PM
[Tutorial] How to create space with one string or Spacing Strings. (sscanf) Tee Tutorials 8 10/09/2011 09:46 AM


All times are GMT. The time now is 07:09 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.