Anty TextDraw crashing in /news
#1

Hello, same as the thread. Who has a good idea to protect textdraw, when code is:

pawn Код:
CMD:news(playerid, params[])
{
/* new text[128];
if(sscanf.... */


TextDrawSetString(Text:TextDrawNews, text);
return 1;
}
And my problem is: when the player send in command /news a symbol like '~', this textdraw crashing all players who see this, how i can protect this, if the script find '~' the player see the message "There are a bad symbols here!" ? Ofc, i need to protect this for the '~n~', '~r~~' etc...
Reply
#2

use strcmp ..
Reply
#3

Yeah, but when i use a requirement like this:

pawn Код:
if(!strcmp(text, "~", true))
My command is not work when player use a "~b~" (changing color symbols), so that is a not good think, i want some special.
Reply
#4

https://sampwiki.blast.hk/wiki/Strcmp

look at length (optional) part
Reply
#5

I think they mean strfind
https://sampwiki.blast.hk/wiki/Strfind

edit: just read your post properly.

You can use a loop to count the ~ in the string, and check it is finding an even number of them.
A better way to solve the problem would be to change the color input, ie the text the player enters to something like
[b] ( blue ) [r] ( red ) etc, and use strfind to make sure there are no ~ in the text.
Then you process the string to replace these sets of symbols with the correctly formatted textdraw symbols , and then send them to the server.
Reply
#6

Quote:
Originally Posted by Rachael
Посмотреть сообщение
I think they mean strfind
https://sampwiki.blast.hk/wiki/Strfind
That will not work!
It wouldn't allow you to execute anything that contains '~', but you need it for colors though.
Reply
#7

I edited my post above.

Something like this ( untested ) might work.
pawn Код:
stock FormatColors( string[] )
{
    new
        pos,
        sub[164]
    ;
    format( sub , sizeof(sub) , "%s" , string );
    pos = strfind( sub , "[g]" , true );
    while( pos != -1 )
    {
        strdel( sub , pos , pos + 3 , sizeof(sub) );
        strins( sub , "~g~" , pos );
        pos = strfind( sub , "[g]" , true );
    }
    pos = strfind( sub , "[r]" , true );
    while( pos != -1 )
    {
        strdel( sub , pos , pos + 3 , sizeof(sub) );
        strins( sub , "~r~" , pos );
        pos = strfind( sub , "[r]" , true );
    }      
    return sub;
}
Obviously you would have to add all the symbols yo wanted to allow.
Reply
#8

SOLVED.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)