Making a weapon command, lots of errors
#1

Ok so I'm using zcmd and my code goes like
pawn Код:
zcmd(weap,playerid,params[])
{
    new weapon;
    if(!sscanf(params,"s",weapon))
    {
        switch(weapon)
        {
          case uzi: GivePlayerWeapon(playerid,28,500);
          case microsmg: GivePlayerWeapon(playerid,28,500);
          case m4: GivePlayerWeapon(playerid,31,500);
          case sniper: GivePlayerWeapon(playerid,34,500);
          case minigun: if(IsPlayerLuxAdmin(playerid))
        {
            GivePlayerWeapon(playerid,38,1500);
            }
            case knife: GivePlayerWeapon(playerid,4,1);
        }
        return 1;
    }
    else SendClientMessage(playerid,COLOR_RED,"USAGE: /weap [weapon name]");
    return 1;
}
Yet when I try compile, I get told
Код:
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1094) : error 017: undefined symbol "uzi"
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1095) : error 017: undefined symbol "microsmg"
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1096) : error 017: undefined symbol "m4"
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1097) : error 017: undefined symbol "sniper"
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1098) : error 017: undefined symbol "minigun"
G:\Program Files\Rockstar Games\SA-MP Server 0.3a\gamemodes\hydra.pwn(1102) : error 017: undefined symbol "knife"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
I see that you're not allowed to use words in cases, but I don't know how to fix it. Help please
Reply
#2

change them to case 1, case 2, case 3 ect.
Reply
#3

My aim was for people to be able to give the name of the weapon to spawn it instead of a number, that's why I did it like that.
Reply
#4

define the words to number then

#define Uzi 1
#define Sniper 1

ect
Reply
#5

Sorry, but I have no idea what you mean there
Reply
#6

bump
Reply
#7

if you look at the top of your gm script you will see some codes like this
Код:
#define
make a new #define like

Код:
#define uzi
#define sniper
#define minigun
#define microsmg
#define m4
at that at the top of your gm script
Reply
#8

pawn Код:
zcmd(weap, playerid, params[])
{
  new
    weapname[10];

  if(sscanf(params, "s", weapname)) return SendClientMessage(playerid, COLOR, "USAGE: /weap [weapon name]");
  else if(strcmp(weapname, "uzi", true) == 0) return GivePlayerWeapon(playerid, 28, 500);
  else if(strcmp(weapname, "microsmg", true) == 0) return GivePlayerWeapon(playerid, 28, 500);
  else if(strcmp(weapname, "m4", true) == 0) return GivePlayerWeapon(playerid, 31, 500);
  else if(strcmp(weapname, "sniper", true) == 0) return GivePlayerWeapon(playerid, 34, 500);
  else if(strcmp(weapname, "knife", true) == 0) return GivePlayerWeapon(playerid, 4, 1);
  else if(strcmp(weapname, "minigun", true) == 0)
  {
    if(IsPlayerLuxAdmin(playerid)) return GivePlayerWeapon(playerid, 38, 1500);
    else return SendClientMessage(playerid, COLOR, "You're not allowed to use that weapon!");
  }
  else SendClientMessage(playerid, COLOR_RED, "Invalid weapon name!");
  return 1;
}
Reply
#9

Thanks, that code works perfectly
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)