Complling.
#1

i want compile this code:
Код:
COMMAND:giveweapon(playerid, params[])
{
	if(!adminLevel(playerid, 3))
		return 0;
		
	new otherID, msg[128], weaponid;
	if(sscanf(params, "ud", otherID, weaponid))
	{
		Usage(playerid, "giveweapon <playerid> <weaponid>");
	}
		else
		{			
			if(!isConnected(otherID))
			{
				Server(playerid, "That player isn't logged in!");
				return 1;
			}
			
			if(isHigher(playerid, otherID))
				Server(playerid, "You can't use this command to that player.");
			else
			{
				format(msg, sizeof(msg), "give %s a weapon(%d).", GetName(otherID), weaponid);
				changeAlog(playerid, msg);
				GivePlayerWeapon(otherID, weaponid, 9999999);
				format(msg, sizeof(msg), "Administrator give you a weapon.");
				Server(otherID, msg);
				format(msg, sizeof(msg), "You have given "CHAT_YELLOW"%s(%d)"CHAT_WHITE" weapon(%d).", GetName(otherID), otherID, weaponid);
				Server(playerid, msg);
			}
		}
	}
	return 1;
}
But i got this:
Код:
C:\Documents and Settings\Administrateur\Bureau\Copie de CZ\pawno\include\cnr/admin.inc(33) : warning 209: function "cmd_giveweapon" should return a value
C:\Documents and Settings\Administrateur\Bureau\Copie de CZ\pawno\include\cnr/admin.inc(34) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#2

Extra closed bracket. Remove a bracket above the last return 1;
Reply
#3

u mean like this ?
PHP код:
COMMAND:giveweapon(playeridparams[])
{
    if(!
adminLevel(playerid3))
        return 
0;
        
    new 
otherIDmsg[128], weaponid;
    if(
sscanf(params"ud"otherIDweaponid))
    {
        
Usage(playerid"giveweapon <playerid> <weaponid>");
    }
        else
        {            
            if(!
isConnected(otherID))
            {
                
Server(playerid"That player isn't logged in!");
                return 
1;
            }
            
            if(
isHigher(playeridotherID))
                
Server(playerid"You can't use this command to that player.");
            else
            {
                
format(msgsizeof(msg), "give %s a weapon(%d)."GetName(otherID), weaponid);
                
changeAlog(playeridmsg);
                
GivePlayerWeapon(otherIDweaponid9999999);
                
format(msgsizeof(msg), "Administrator give you a weapon.");
                
Server(otherIDmsg);
                
format(msgsizeof(msg), "You have given "CHAT_YELLOW"%s(%d)"CHAT_WHITE" weapon(%d)."GetName(otherID), otherIDweaponid);
                
Server(playeridmsg);
            }
        }
    return 
1;

??
Reply
#4

Yes, like this. Compiling the script would solve your query unless something else would cause other errors.

Anyway, try avoid too many if/else because it makes the code less readable. Something like this would be simple enough (assuming "Server" and "Usage" return a value (specifically anything but zero)).

pawn Код:
COMMAND:giveweapon(playerid, params[])
{
    if (!adminLevel(playerid, 3)) return 0;

    new otherID, weaponid;
    if (sscanf(params, "ud", otherID, weaponid)) return Usage(playerid, "giveweapon <playerid> <weaponid>");
    if (otherID == INVALID_PLAYER_ID) return Server(playerid, "That player isn't logged in!");
    if (isHigher(playerid, otherID)) return Server(playerid, "You can't use this command to that player.");

    new msg[50];
    format(msg, sizeof(msg), "give %s a weapon(%d).", GetName(otherID), weaponid);
    changeAlog(playerid, msg);
 
    GivePlayerWeapon(otherID, weaponid, 9999999);
    Server(otherID, "Administrator give you a weapon.");
 
    format(msg, sizeof(msg), "You have given "CHAT_YELLOW"%s(%d)"CHAT_WHITE" weapon(%d).", GetName(otherID), otherID, weaponid);
    Server(playerid, msg);
    return 1;
}
and why "isConnected" when there's a native for that? Which is not needed in our case, sscanf returns 65535 (INVALID_PLAYER_ID) if player specified is not connected.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)