Checking for GameText text errors -
Luis- - 18.05.2015
Hey! I was wondering how I'd go about checking for small errors in a GameText text, like for example, if you are typing something like "~rRandom Text" the game would crash cause it's missing the last "~", I was wondering how I could send the player a message telling them that they're missing the "~".
Thanks.
Re: Checking for GameText text errors -
Vince - 18.05.2015
I think that already happens automatically. The server sends an automated message about "unmatched tilde".
Re: Checking for GameText text errors -
Abagail - 18.05.2015
you can use strfind to see if an ~ exists, and then use an IsEven function to check if there is an even amount by extract all the ~s and storing the length of the resulting string.
Re: Checking for GameText text errors -
Evocator - 18.05.2015
Quote:
Originally Posted by Vince
I think that already happens automatically. The server sends an automated message about "unmatched tilde".
|
No, that only happens with textdraws.
And yes, Luis- heres a function by JernejL AFAIK:
Код:
stock issafefortextdraw(str[])
{
new
safetil = -5;
for (new i = 0; i < strlen(str); i++)
{
if ((str[i] == 126) && (i > safetil))
{
if (i >= strlen(str) - 1)
return false;
if (str[i + 1] == 126)
return false;
if (str[i + 2] != 126)
return false;
safetil = i + 2;
}
}
return true;
}
//USAGE:
if (!issafefortextdraw("~rHELLO WORLD!")) {
print("Error: check for ~ errors.");
}
if (!issafefortextdraw("~r~HELLO WORLD!")) {
print("Its good!");
}
Respuesta: Checking for GameText text errors -
admantis - 18.05.2015
A simple method:
PHP код:
isSafeForTextdraw(string[])
{
new tildeCount;
for(new idx, len = strlen(string); idx < len; idx++)
{
if(string[idx] == '~') tildeCount ++;
}
if((tildeCount) & 1) return 0;
return 1;
}
Count the amount of tildes and if it's odd, there's a missing tilde.
Re: Respuesta: Checking for GameText text errors -
PowerPC603 - 18.05.2015
Quote:
Originally Posted by admantis
A simple method:
PHP код:
isSafeForTextdraw(string[])
{
new tildeCount;
for(new idx, len = strlen(string); idx < len; idx++)
{
if(string[idx] == '~') tildeCount ++;
}
if((tildeCount) & 1) return 0;
return 1;
}
Count the amount of tildes and if it's odd, there's a missing tilde.
|
What if players type "~~rHello World"?
You have 2 tildes, but it doesn't close the "r", resulting in a crash.
Respuesta: Checking for GameText text errors -
admantis - 18.05.2015
Good point, never thought of that :P
Re: Checking for GameText text errors -
Gammix - 19.05.2015
Here is better version i made:
pawn Код:
IsSafeGameText(string[])
{
new count;
for(new num, len = strlen(string); num < len; num++)
{
if(string[num] == '~')
{
if((num + 1) < len)
{
if(string[(num + 1)] == '~') return false;
}
count += 1;
}
}
if((count % 2) > 0) return false;
return true;
}
On testing, i got the following results:
~~ - false
~r~ - true
~r~~ - false
~~~~ - false (even though the count is even but it have an additional check over that)
Re: Checking for GameText text errors -
M0HAMMAD - 19.05.2015
you can use sscanf and set Colors. /Text (Colors) (Text) [ /Text Red Hi ]
and then using strcmp to get if Colors was Red use: ~r~Hi