Need help with my Jetpack command.
#4

Here is the fixed version of your command.
pawn Код:
CMD:jetpack(playerid, params[])
{
    if(!PlayerInfo[playerid][pAdmin] >= 2) return SendClientMessage(playerid, "You're not an Administrator Level 2");
    else {
            new targetid, new string[256], pname[MAX_PLAYER_NAME];
            if(sscanf(params,"u",targetid)) SendClientMessage(playerid,-1,"Usage: /jetpack (ID/Name)");
            {
                GetPlayerName(targetid,pname,26);
                format(string,sizeof(string),"An administrator has given a jetpack to %s", pname);
                SendClientMessageToAll(-1, string);
                SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
            }
    }
    return 1;
}
Changes and why I made them:
  • Identation - for basic readability and shizzle.

  • A '!' before your admin check - you were checking if the player was an admin, and then if they were, send a message saying they don't have permission. The '!' will check for the opposite (if they do not hold an admin level greater than or equal to 2).
  • Removed your IsPlayerConnected check - You don't need it, for one, because if the player wasn't connected then they wouldn't be able to perform the command in the first place. Two, it was creating a message as it was on the same line as where you defined your arrays.

  • Took [MAX_PLAYER_NAME] off of your targetid definition. You cannot mix array types. By giving targetid a length, you told the script it was a string. Except in your sscanf line you told the script to search for an integer (by using the 'u' specifier).

  • Added the pname string for use in GetPlayerName. View the example of usage on this function at https://sampwiki.blast.hk/wiki/GetPlayerName and you will quickly see why yours was incorrect.

  • Added your missing braces. A good tip is to create both your open and closing braces and then go back and add the code in between them, it's virtually impossible to forget them if you do it that way.
  • Changed 'targetid' to 'pname] in your format line - again, you cannot mix array types. '%s' calls for a string but targetid is an integer. I placed 'pname' here instead because GetPlayerName placed its result in that string.

  • I removed GivePlayerJetpack and replaced it with the SetPlayerSpecialAction line because, unless that is a custom made function by yourself, GivePlayerJetpack does not exist. SetPlayerSpecialAction is used to give out jetpacks.
I believe that's it, happy scripting!
Reply


Messages In This Thread
Need help with my Jetpack command. - by Magic_Time - 27.12.2012, 05:35
Re: Need help with my Jetpack command. - by XtremeR - 27.12.2012, 05:43
Re: Need help with my Jetpack command. - by Magic_Time - 27.12.2012, 05:48
Re: Need help with my Jetpack command. - by zDevon - 27.12.2012, 05:50
Re : Re: Need help with my Jetpack command. - by lelemaster - 27.12.2012, 05:53
Re: Need help with my Jetpack command. - by Magic_Time - 27.12.2012, 05:56
Re : Need help with my Jetpack command. - by lelemaster - 27.12.2012, 05:57
Re: Need help with my Jetpack command. - by Magic_Time - 27.12.2012, 06:01
Re : Re: Need help with my Jetpack command. - by lelemaster - 27.12.2012, 06:01
Re: Need help with my Jetpack command. - by zDevon - 27.12.2012, 06:12

Forum Jump:


Users browsing this thread: 2 Guest(s)