Whats wrong with this command?
#1

Hello!

This command is kinda bugged, it removes the object but i sends 10 messages saying the same
"[_Christmas_] %s(%d) has removed his santa hat. He doesn't like christmas"

PHP код:
    if(strcmp("/remao"cmdtexttrue,10)== 0// Remove Attached Objects
    
{
        for(new 
i=0i<MAX_PLAYER_ATTACHED_OBJECTSi++)
        {
            if(
IsPlayerAttachedObjectSlotUsed(playerid1)) RemovePlayerAttachedObject(playerid1);
            new 
pname[24];
            new 
string[128];
            
GetPlayerName(playerid,pname,sizeof(pname));
            
format(string,sizeof(string),"[_Christmas_] %s(%d) has removed his santa hat. He doesn't like christmas",pname,playerid);
            
SendClientMessageToAll(COLOR_CYAN,string);
         }
        return 
1;
    } 
Thanks in advance
Reply
#2

you forgot to create a { } block for more commands being executed in the if-statement:
Код:
	if(strcmp("/remao", cmdtext, true,10)== 0) // Remove Attached Objects
	{
		for(new i=0; i<MAX_PLAYER_ATTACHED_OBJECTS; i++)
		{
			if(IsPlayerAttachedObjectSlotUsed(playerid, i))
			{
				RemovePlayerAttachedObject(playerid, i);
				new pname[24];
				new string[128];
				GetPlayerName(playerid,pname,sizeof(pname));
				format(string,sizeof(string),"[_Christmas_] %s(%d) has removed his santa hat. He doesn't like christmas",pname,playerid);
				SendClientMessageToAll(COLOR_CYAN,string);
			}
		}
		return 1;
	}
but now, the (playerid,1) will get checked 10 times. isnt it supposed to be a (playerid,i) ? fixed it tho. idk if it works, just give it a try and tell us, if there are more bugs like only 1, not 2 attached objects being removed... or maybe all objects disappear, even if its not a santa hat? the script checks IF the object is used, not which one, but youll enhance that hehe
Reply
#3

Quote:
Originally Posted by Babul
Посмотреть сообщение
you forgot to create a { } block for more commands being executed in the if-statement:
Код:
	if(strcmp("/remao", cmdtext, true,10)== 0) // Remove Attached Objects
	{
		for(new i=0; i<MAX_PLAYER_ATTACHED_OBJECTS; i++)
		{
			if(IsPlayerAttachedObjectSlotUsed(playerid, i))
			{
				RemovePlayerAttachedObject(playerid, i);
				new pname[24];
				new string[128];
				GetPlayerName(playerid,pname,sizeof(pname));
				format(string,sizeof(string),"[_Christmas_] %s(%d) has removed his santa hat. He doesn't like christmas",pname,playerid);
				SendClientMessageToAll(COLOR_CYAN,string);
			}
		}
		return 1;
	}
but now, the (playerid,1) will get checked 10 times. isnt it supposed to be a (playerid,i) ? fixed it tho. idk if it works, just give it a try and tell us, if there are more bugs like only 1, not 2 attached objects being removed... or maybe all objects disappear, even if its not a santa hat? the script checks IF the object is used, not which one, but youll enhance that hehe
Oh Thanks dude, i mean your code is working correctly!
+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)