Problem command /ann
#1

I have a problem. When entering a command, for example: /ann Welco~k~me it gets a crash. Could it be fixed?

Код:
CMD:ann(playerid, params[]) 
{ 
	new text[128], ann_b[][] = {"~f~", "~k~", "~o~"};
	if(sscanf(params, "s[128]", text))
	{ 
		SendClientMessage(playerid, -1, "Usage: /ann [text]");
		return 1; 
	}

    for(new i, find; i < sizeof(ann_b); i++)
    {
        if((find = strfind(text, ann_b[i], true), find) != -1)
        {
        	SendClientMessage(playerid, -1, "Wrong!");
        	return 1;
        }
    }

	GameTextForAll(text, 10000, 4);
 	return 1;
}
Reply
#2

try this from my GM
Quote:

CMD:announce(playerid, params[], help)
{
#pragma unused help
if(PlayerInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!");
new string[128],style;
if(sscanf(params, "s[128]i",string,style)) return SCM(playerid, COLOR_RED, "Usage: /announce [Text] [Text Style 0-6]");
GameTextForAll(string,4000,style);
return 1;
}

aka GiDanAdmin System
Reply
#3

I'm not sure why you're even restricting the use of '~f~' and '~o~'... they're not even valid gametext keys.
https://sampwiki.blast.hk/wiki/GameTextStyle

Quote:

Be careful, using too many text colors or special characters in one gametext may crash every player the gametext is shown to. Additionally, avoid using an uneven usage of the ~ character.
Example: ~~r~Hello, ~g~how are ~y~~you?~

PHP код:
CMD:ann(playeridparams[])
{
    if(
isnull(params)) // If the player did not enter parameters...
        
return SendClientMessage(playerid, -1"Usage: /ann [text]"); // Send the player a usage message.
    
if(strfind(params"~k~"true) != -1// If we find a forbidden string in our text...
        
return SendClientMessage(playerid, -1"Wrong!"); // Send the player an error message.

    
new count 0// Store the count of tildes (~) in this variable.
    
for(new 0strlen(params); ji++) // Loop through the string to count all the tildes (~).
    
{
        if(
params[i] == '~'// If the character is a tilde...
            
count++; // Add 1 to our count.
    
}

    if((
count 2) != 0// If the number of tildes in our message is odd...
        
return SendClientMessage(playerid, -1"Odd number of tildes!"); // Send an error message to the player.

    
GameTextForAll(params100004); // Send the game text to all players.
    
return 1;

This basic command only stops the admin/player using '~k~' in the message as well as having unmatched tildes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)