Need help with my Jetpack command.
#1

I am trying to learn PAWNO.
I have errors compiling it
Код:
C:\Users\USER\Documents\samp03e_svr_R2_win32\pawno\Test.pwn(41) : error 001: expected token: ")", but found "["
C:\Users\USER\Documents\samp03e_svr_R2_win32\pawno\Test.pwn(41) : error 029: invalid expression, assumed zero
C:\Users\USER\Documents\samp03e_svr_R2_win32\pawno\Test.pwn(41) : warning 215: expression has no effect
C:\Users\USER\Documents\samp03e_svr_R2_win32\pawno\Test.pwn(41) : error 001: expected token: ";", but found "]"
C:\Users\USER\Documents\samp03e_svr_R2_win32\pawno\Test.pwn(41) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Also, I need to know if this command will work.

PHP код:
CMD:jetpack(playeridparams[])
{
if(
PlayerInfo[playerid][pAdmin] >= 2) return SendClientMessage(playerid"You're not an Administrator Level 2");
    {
    else if(
IsPlayerConnected(playerid) new targetid[MAX_PLAYER_NAME]; new string[256];
        {
        if(
sscanf(params,"u",targetid))SendClientMessage(playerid,"Usage: /jetpack (ID/Name);");
            {
            
GetPlayerName(playeridtargetid);
            
format(string,sizeof(string),"An administrator has given a jetpack to %s"targetid);
            
SendClientMessageToAll(-1string);
            
GivePlayerJetpack(targetid);
  return 
1;
 } 
Reply
#2

This should work:

pawn Код:
CMD:jetpack(playerid, params[])
{
new targetid[MAX_PLAYER_NAME]; new string[256];
if(PlayerInfo[playerid][pAdmin] >= 2) return SendClientMessage(playerid, "You're not an Administrator Level 2");
    {
    else if(IsPlayerConnected(playerid)
        {
        if(sscanf(params,"u",targetid)) SendClientMessage(playerid,"Usage: /jetpack (ID/Name);");
            {
            GetPlayerName(playerid, targetid);
            format(string,sizeof(string),"An administrator has given a jetpack to %s", targetid);
            SendClientMessageToAll(-1, string);
            GivePlayerJetpack(targetid);
  return 1;
 }
Reply
#3

I have the same errors.
Reply
#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
#5

Quote:
Originally Posted by XtremeR
Посмотреть сообщение
This should work:

pawn Код:
CMD:jetpack(playerid, params[])
{
new targetid[MAX_PLAYER_NAME]; new string[256];
if(PlayerInfo[playerid][pAdmin] >= 2) return SendClientMessage(playerid, "You're not an Administrator Level 2");
    {
    else if(IsPlayerConnected(playerid)
        {
        if(sscanf(params,"u",targetid)) SendClientMessage(playerid,"Usage: /jetpack (ID/Name);");
            {
            GetPlayerName(playerid, targetid);
            format(string,sizeof(string),"An administrator has given a jetpack to %s", targetid);
            SendClientMessageToAll(-1, string);
            GivePlayerJetpack(targetid);
  return 1;
 }
No it wont.

This will:

pawn Код:
CMD:jetpack(playerid, params[])
{
new targetidname[MAX_PLAYER_NAME],targetid; new string[256];
if(PlayerInfo[playerid][pAdmin] >= 2)
    {
    if(IsPlayerConnected(playerid))
        {
        if(!sscanf(params,"u",targetid))
            {
            GetPlayerName(targetid, targetidname, sizeof(targetidname));
            format(string,sizeof(string),"An administrator has given a jetpack to %s", targetidname);
            SendClientMessageToAll(-1, string);
            GivePlayerJetpack(targetid);
            }
            else return SendClientMessage(playerid,1,"Usage: /jetpack (ID/Name);");
        }
    }
    else return SendClientMessage(playerid, "You're not an Administrator Level 2");
  return 1;
 }
I just can't imagine how many errors you would get with XtremeR's code.
This will help him:

1-Missing closing brackets
2-You had a else if without and if statement above
3-Your returning messages would not do anything
4-GetPlayerName missed something
5-Forgot a closing ) after IsPlayerConnected
6-Where sscanf check the intered text, it would be inversed

EDIT:The man above me was faster, but anyways. Your last change, "GivePlayerJetpack" removed, maybe he has a function for it where it sets the special action in
Reply
#6

It worked now.
Can you help me to fix it_

I am newbie.
PHP код:
CMD:giveweapon(playeridparams[])
{
if(
IsPlayerConnected(playerid) new weapid; new targetid[MAX_PLAYER_NAME]; new string[256];
    {
    if(
sscanf(params,"ui",targetidweapid))SendClientMessage(playerid,-1,"Usage: /giveweapon (ID) (WeapID");
        {
        
GetPlayerName(playeridtargetid);
        
format(string,sizeof(string),"An administrator has given a weapon to %s"targetid);
        
SendClientMessageToAll(-1string);
        
GivePlayerWeapon(playeridweapid);
 return 
1;
  } 
Reply
#7

Which line have errors?
Reply
#8

Thanks lelemaster.
Can you help me with this>
PHP код:
CMD:giveweapon(playeridparams[])
{
if(
IsPlayerConnected(playerid) new weapid; new targetid[MAX_PLAYER_NAME]; new string[256];
    {
    if(
sscanf(params,"ui",targetidweapid))SendClientMessage(playerid,-1,"Usage: /giveweapon (ID) (WeapID");
        {
        
GetPlayerName(playeridtargetid);
        
format(string,sizeof(string),"An administrator has given a weapon to %s"targetid);
        
SendClientMessageToAll(-1string);
        
GivePlayerWeapon(playeridweapid);
 return 
1;
  } 
Thanks in advance, and sorry, I'm learning.
Reply
#9

pawn Код:
CMD:giveweapon(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new weapid; new targetidname[MAX_PLAYER_NAME], targetid; new string[256];
    if(!sscanf(params,"ui",targetid, weapid))
        {
        GetPlayerName(targetid,targetidname, sizeof(targetidname));
        format(string,sizeof(string),"An administrator has given a weapon to %s", targetidname);
        SendClientMessageToAll(-1, string);
        GivePlayerWeapon(targetid, weapid, 1); // forgot ammo
        }
        else return SendClientMessage(playerid,-1,"Usage: /giveweapon (ID) (WeapID");
    }
 return 1;
  }
Reply
#10

You have the same mistakes in that command as you did with the last one. If you're 'learning', then read what I told you the first time and apply the same fixes with this command. That is how you will learn, not by copying and pasting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)