[PAWN] warning 209: function "cmd_ammute" should return a value
#1

Hey all,
I got a little problem I can't fix, maybe you can help me?
I get this warning when I compile. (I know the script would still run if it's got a problem, but I hate warnings :P)
Код:
C:\Users\Gebruiker\Documents\GTA San Andreas\samp servers\Fast Hustler Roleplay V2.0\gamemodes\UGRP.pwn(63951) : warning 209: function "cmd_ammute" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Here's that piece of script:
Код:
CMD:ammute(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][pHelper] >= 2)
	{
		new string[128], giveplayerid;
		if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /ammute [playerid]");

		if(IsPlayerConnected(giveplayerid))
		{
				if(PlayerInfo[giveplayerid][pAdmin] >= 1)
				{
					return SendClientMessageEx(playerid, COLOR_LIGHTRED, "You can't /ammute admins");
				}
				if(PlayerInfo[giveplayerid][pAMMute] == 0)
				{
					PlayerInfo[giveplayerid][pAMMute] = 1;
					format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
					Log("logs/admin.log", string);
					ABroadCast(COLOR_LIGHTRED,string,2);
					}

					if(PlayerInfo[playerid][pAdmin] == 1)
					{
						format(string, sizeof(string), "AdmCmd: %s was muted from placing /ad's by Admin.", GetPlayerNameEx(giveplayerid));
						SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
						SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "You were just muted from Advertisements [/ad] by an Admin.");
					}
					else
					{
						format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
						SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
						format(string, sizeof(string), "You were just muted from /am by %s.", GetPlayerNameEx(playerid));
						SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, string);
					}

					SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "Remember, /am may only be used for messages when you really need an admin and may not be used for trolling, PM, and other useless things unless stated otherwise by an admin.");

					format(string, sizeof(string), "AdmCmd: %s was just muted from using /am due to misuse.", GetPlayerNameEx(giveplayerid));
					SendClientMessageToAllEx(COLOR_LIGHTRED, string);
					return 1;
				}
		}
} //WARNING ON THIS LINE!
Reply
#2

No warnings now.

pawn Код:
CMD:ammute(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][pHelper] >= 2)
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /ammute [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
                if(PlayerInfo[giveplayerid][pAdmin] >= 1)
                {
                    return SendClientMessageEx(playerid, COLOR_LIGHTRED, "You can't /ammute admins");
                }
                if(PlayerInfo[giveplayerid][pAMMute] == 0)
                {
                    PlayerInfo[giveplayerid][pAMMute] = 1;
                    format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
                    Log("logs/admin.log", string);
                    ABroadCast(COLOR_LIGHTRED,string,2);
                    }

                    if(PlayerInfo[playerid][pAdmin] == 1)
                    {
                        format(string, sizeof(string), "AdmCmd: %s was muted from placing /ad's by Admin.", GetPlayerNameEx(giveplayerid));
                        SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
                        SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "You were just muted from Advertisements [/ad] by an Admin.");
                    }
                    else
                    {
                        format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
                        SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
                        format(string, sizeof(string), "You were just muted from /am by %s.", GetPlayerNameEx(playerid));
                        SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, string);
                    }

                    SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "Remember, /am may only be used for messages when you really need an admin and may not be used for trolling, PM, and other useless things unless stated otherwise by an admin.");

                    format(string, sizeof(string), "AdmCmd: %s was just muted from using /am due to misuse.", GetPlayerNameEx(giveplayerid));
                    SendClientMessageToAllEx(COLOR_LIGHTRED, string);
                    return 1;
                }

        }
return 1;
}
Reply
#3

pawn Код:
CMD:ammute(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][pHelper] >= 2)
    {
        new string[128], giveplayerid;
        if(sscanf(params, "u", giveplayerid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /ammute [playerid]");

        if(IsPlayerConnected(giveplayerid))
        {
                if(PlayerInfo[giveplayerid][pAdmin] >= 1)
                {
                    return SendClientMessageEx(playerid, COLOR_LIGHTRED, "You can't /ammute admins");
                }
                if(PlayerInfo[giveplayerid][pAMMute] == 0)
                {
                    PlayerInfo[giveplayerid][pAMMute] = 1;
                    format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
                    Log("logs/admin.log", string);
                    ABroadCast(COLOR_LIGHTRED,string,2);
                    }

                    if(PlayerInfo[playerid][pAdmin] == 1)
                    {
                        format(string, sizeof(string), "AdmCmd: %s was muted from placing /ad's by Admin.", GetPlayerNameEx(giveplayerid));
                        SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
                        SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "You were just muted from Advertisements [/ad] by an Admin.");
                    }
                    else
                    {
                        format(string, sizeof(string), "AdmCmd: %s was muted from using /am by %s.", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid));
                        SendDutyAdvisorMessage(TEAM_AZTECAS_COLOR, string);
                        format(string, sizeof(string), "You were just muted from /am by %s.", GetPlayerNameEx(playerid));
                        SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, string);
                    }

                    SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, "Remember, /am may only be used for messages when you really need an admin and may not be used for trolling, PM, and other useless things unless stated otherwise by an admin.");

                    format(string, sizeof(string), "AdmCmd: %s was just muted from using /am due to misuse.", GetPlayerNameEx(giveplayerid));
                    SendClientMessageToAllEx(COLOR_LIGHTRED, string);
                    return 1;
                }
        }
return 1;
}
use this ^
EDIT: too late
Reply
#4

Your command should return a value which you didnt assign in the command, as a result you got the warning, use the code by BroZeus.
Reply
#5

Thank you!
Reply
#6

I know you have solved your issue. But here is a useful tutorial on reading warning and error messages.

Step 1) open your eyes and read the message, for tutorial purposes, we'll use your warning:
UGRP.pwn(63951) : warning 209: function "cmd_ammute" should return a value
Step 2) analyze the message.
NEAR line 63951 a certain problem was found, warning 209.
This warning states clearly that function "cmd_ammute" should return a value.
Step 3) find the issue.
So apparently cmd_ammute doesn't always return a value. If you'd look at your code you would see that if the first if statement is not true, no return value is ever given.
Step 4) solve the issue.
As said before, we need to return a value when the first if statement fails. So we'd need to place this return statement after the if statement. This would be on line 63951 which happens to the line the compiler warned about. Now the following question would arise: what value will you return. For this you need to know how command are processed. When you return 1, it means the command was processed successfully. When you return 0, a message will be shown the command failed to execute. Looking back at the if-statement, the return value we are adding on the said line is returned when the player does not have the permission to run this command. For that reason I would return 0.

Sorry for typo's; typing on a phone is tedious work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)