SA-MP Forums Archive
Anty TextDraw crashing in /news - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Anty TextDraw crashing in /news (/showthread.php?tid=285735)



Anty TextDraw crashing in /news - Dodus - 25.09.2011

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


Re: Anty TextDraw crashing in /news - iJumbo - 25.09.2011

use strcmp ..


Re: Anty TextDraw crashing in /news - Dodus - 25.09.2011

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.


Re: Anty TextDraw crashing in /news - iJumbo - 25.09.2011

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

look at length (optional) part


Re: Anty TextDraw crashing in /news - Rachael - 25.09.2011

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.


Re: Anty TextDraw crashing in /news - [MWR]Blood - 25.09.2011

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.


Re: Anty TextDraw crashing in /news - Rachael - 25.09.2011

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.


Re: Anty TextDraw crashing in /news - Dodus - 25.09.2011

SOLVED.