only a single statement (or expression) can follow each "case"
#1

C:\Users\NASTIE\Desktop\ExtremePower\filterscripts \Checkpoint.pwn(703) : error 002: only a single statement (or expression) can follow each "case"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

I made a mechanic on server and when i press compile i get this one error

lines

Код:
if(dialogid == 5512 && response)
  {

    switch(listitem)
    {
      case 0:
      {
      new
		MaxPlayers = GetMaxPlayers();
      for(new forplayerid; forplayerid < MaxPlayers; forplayerid++)
	{
		if(!IsPlayerConnected(forplayerid)) continue;
		new
			VehicleID = GetPlayerVehicleID(forplayerid),
			Float:Health;
		if(VehicleID)
		{
      GetVehicleHealth(VehicleID, Health);
			if(Health < 500) return SendClientMessage(playerid, 0xFF0005FF, "Helti su ti preko 50 posto.");
			{
      if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0005FF, "Nemas dovoljno novaca!");
      GivePlayerMoney(playerid, -100);
      new vehicleid = GetPlayerVehicleID(playerid);
      SetVehicleHealth(vehicleid,1000.0);
      SendClientMessage(playerid,0x00FF0AFF,"Popravio si svoje vozilo i platio 100$.");
      }
    }
  }
      return 1;
}
Line 703 dont exist max lines are: 702
Reply
#2

Make life easier for yourself and put all that code after your first case into another custom function.

pawn Код:
//at top of script
forward MyFunc();

//anywhere
public MyFunc()
{
    new MaxPlayers = GetMaxPlayers();
    for(new forplayerid; forplayerid < MaxPlayers; forplayerid++)
    {
         if(!IsPlayerConnected(forplayerid)) continue;
         new VehicleID = GetPlayerVehicleID(forplayerid), Float:Health;
         if(VehicleID)
         {
             GetVehicleHealth(VehicleID, Health);
             if(Health < 500) return SendClientMessage(playerid, 0xFF0005FF, "Helti su ti preko 50 posto.");

             if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerid, 0xFF0005FF, "Nemas dovoljno novaca!");
             GivePlayerMoney(playerid, -100);
             new vehicleid = GetPlayerVehicleID(playerid); //compiler may throw an "already defined" error
             SetVehicleHealth(vehicleid,1000.0);
             SendClientMessage(playerid,0x00FF0AFF,"Popravio si svoje vozilo i platio 100$.");
         }
    }
    return 1;
}

//then your case code:
if(dialogid == 5512 && response)
  {

    switch(listitem)
    {
      case 0: MyFunc();
      //any other cases here...
    }
    return 1;
}
Hope that helps.
Reply
#3

its help, one more question OFF TOPIC FROM THIS ONE....

Код:
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0x00FF00AA,"You're in a vehicle.");
How to check if is player on foot, example i wanna to make when player enter checkpoint and if he is on foot to get message "you must be in vehicle"
Reply
#4

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
Reply
#5

Quote:
Originally Posted by biltong
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
tny
Reply
#6

Quote:
Originally Posted by biltong
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
Or..

pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) { }
When you call a function, like this one, it returns 1 if true, and 0 if false.
Note the '!'.. Putting that in front of it means '== 0', without it, it means '== 1'.
Reply
#7

Quote:
Originally Posted by PowerSurge
Quote:
Originally Posted by biltong
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
Or..

pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) { }
When you call a function, like this one, it returns 1 if true, and 0 if false.
Note the '!'.. Putting that in front of it means '== 0', without it, it means '== 1'.
That is new for me tny alot you learn me something
Reply
#8

Yeah that'll work too but I find I get warnings when I use "!" with variables
Ex:
pawn Код:
new IsPlayerDead[MAX_PLAYERS]
if(!IsPlayerDead[playerid])
{
   //code here
}
will give me a Tag mismatch error, while if I do
pawn Код:
new IsPlayerDead[MAX_PLAYERS]
if(! (IsPlayerDead[playerid]) )
{
   //code here
}
will compile fine. Watch out for that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)