SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 02/01/2010, 09:47 PM   #1
x-cutter
Huge Clucker
 
Join Date: Oct 2008
Posts: 347
Reputation: 1
Default How to filter a value?


I'd like to know how to filter a value for my birth date system.

1st : A player would enter in a command or whatever some text.
2nd : I'd like to make sure he's using the good format (dd/mm/yyyy)
3rd : Then, I would separate them, removing all the slashes ( / ) into 3 different values

My problem comes after I get the text entered by the player. I don't know what to do for steps 2 and 3.

Thanks for helping!
__________________
GO HABS GO !
x-cutter is offline  
Old 02/01/2010, 11:33 PM   #2
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: How to filter a value?

You only need to split the string

pawn Code:
new day, month, year = -1 = month = day;
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
    if(text[c] == '/')
    {
        if(day == -1)
        {
            if((c - s) > 2) break;
            for(day = 0; s < c; s++)
                day = day * 10 + (text - '0');
            s++;
        }
        else if(month == -1)
        {
            if((c - s) > 2) break;
            for(month = 0; s < c; s++)
                month = month * 10 + (text - '0');
            s++;
        }
    }
    else if(text[c] == ' ')
    {
        if(month == -1 || day == -1) break;
        else if((c - s) > 4) break;
        for(year = 0; s < c; s++)
            year = year * 10 + (text - '0');
        break;
    }
    else if(!('0' <= text[c] <= '9')) break;
if(year == -1 || month == -1 || day == -1) return 0;

if you use it
at OnPlayerText
pawn Code:
if(PlayerTypesDate[playerid])
{
    if(!('0' <= text[0] <= '9')) return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 0
}
at OnPlayerCommandText
pawn Code:
if(strcmp("/command", cmdtext, true, 8 /* strlen("/command") */) == 0)
{
    if(cmdtext[8/* strlen("/command") */] != ' ' || cmdtext[9/* strlen("/command") + 1 */] == EOS)
        return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 9 /* strlen("/command") + 1 */
}
Nero_3D is offline  
Old 02/01/2010, 11:56 PM   #3
x-cutter
Huge Clucker
 
Join Date: Oct 2008
Posts: 347
Reputation: 1
Default Re: How to filter a value?

Quote:
Originally Posted by ♣ Joker ♠
You only need to split the string

pawn Code:
new day, month, year = -1 = month = day;
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
    if(text[c] == '/')
    {
        if(day == -1)
        {
            if((c - s) > 2) break;
            for(day = 0; s < c; s++)
                day = day * 10 + (text - '0');
            s++;
        }
        else if(month == -1)
        {
            if((c - s) > 2) break;
            for(month = 0; s < c; s++)
                month = month * 10 + (text - '0');
            s++;
        }
    }
    else if(text[c] == ' ')
    {
        if(month == -1 || day == -1) break;
        else if((c - s) > 4) break;
        for(year = 0; s < c; s++)
            year = year * 10 + (text - '0');
        break;
    }
    else if(!('0' <= text[c] <= '9')) break;
if(year == -1 || month == -1 || day == -1) return 0;

if you use it
at OnPlayerText
pawn Code:
if(PlayerTypesDate[playerid])
{
    if(!('0' <= text[0] <= '9')) return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 0
}
at OnPlayerCommandText
pawn Code:
if(strcmp("/command", cmdtext, true, 8 /* strlen("/command") */) == 0)
{
    if(cmdtext[8/* strlen("/command") */] != ' ' || cmdtext[9/* strlen("/command") + 1 */] == EOS)
        return SendClientMessage(playerid, 0xFFFFFFAA, "Enter the date in the format dd/mm/yyyy");
    //code above - c = 9 /* strlen("/command") + 1 */
}
Thanks alot, but I don't get something.
In the second piece of code, there's
Code:
// code above - c = 0
What does that mean? (EDIT: talking about the '- c = 0')
__________________
GO HABS GO !
x-cutter is offline  
Old 03/01/2010, 12:07 AM   #4
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: How to filter a value?

Quote:
Originally Posted by X Cutter
What does that mean? (EDIT: talking about the '- c = 0')
that was related to

Quote:
Originally Posted by ♣ Joker ♠
pawn Code:
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
the loop should start at the date
it would stop if the loop gets called before
so I wrote the examples, how to find out the start value
Nero_3D is offline  
Old 03/01/2010, 12:28 AM   #5
x-cutter
Huge Clucker
 
Join Date: Oct 2008
Posts: 347
Reputation: 1
Default Re: How to filter a value?

Quote:
Originally Posted by ♣ Joker ♠
Quote:
Originally Posted by X Cutter
What does that mean? (EDIT: talking about the '- c = 0')
that was related to

Quote:
Originally Posted by ♣ Joker ♠
pawn Code:
for(new c = 0/* Startpoint */, s = c; text[c] != EOS; c++) //the text should start at the date
the loop should start at the date
it would stop if the loop gets called before
so I wrote the examples, how to find out the start value
Okay, thanks, gonna try this atm.
__________________
GO HABS GO !
x-cutter is offline  
Old 03/01/2010, 12:45 AM   #6
x-cutter
Huge Clucker
 
Join Date: Oct 2008
Posts: 347
Reputation: 1
Default Re: How to filter a value?

Tested it. Compiles well except 1 error.
I get
Code:
error 022: must be lvalue (non-constant)
on line:
Code:
new day, month, year = -1 = month = day;
__________________
GO HABS GO !
x-cutter is offline  
Old 03/01/2010, 01:35 AM   #7
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: How to filter a value?

Quote:
Originally Posted by X Cutter
Tested it. Compiles well except 1 error.
I get
Code:
error 022: must be lvalue (non-constant)
on line:
Code:
new day, month, year = -1 = month = day;
oh ye, it should be
pawn Code:
new day, month, year = month = day = -1;
Nero_3D is offline  
 

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
Help with my filter script. doo2002 Help Archive 7 12/07/2010 09:37 PM
Filter Scripts Limt? :S videoscape Server Support 4 14/06/2010 07:15 PM
[DUV] Filter Script jcs14 Português/Portuguese 0 03/02/2010 12:46 PM
Flame filter NewbieBoy Help Archive 2 16/12/2009 02:53 PM
How do I add a filter script? Mike_junlie Server Support 12 29/01/2009 10:01 PM


All times are GMT. The time now is 11:01 AM.


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