Help with code!
#1

Hello,
Today, i make this piece of code to improve my laggy OnPlayerEnterVehicle-function. The problem is it don't work:

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
	  new
		m = GetVehicleModel(GetPlayerVehicleID(playerid));
		switch(m)
		{
		    case 599, 598, 597, 596, 523, 497: { if(gTeam[playerid] != TEAM_POLICE) RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for cops."); } // 596,597,598,599
   		    case 416: { if(gTeam[playerid] != TEAM_PARAMEDIC) RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!"); }
	    	    case 537, 538, 449: { if(gTeam[playerid] != TEAM_TAXI) RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for transport-service employees!"); }
		    default: { SendClientMessage(playerid, COLOR_WHITE, "Je ben in een onbekende auto gestapt!"); }
			}
			}
			return 1;
			}
Can anyone figure out what's wrong?
Greetz,
sean5874
Reply
#2

You're missing brackets... Example:

pawn Код:
case 416: { if(gTeam[playerid] != TEAM_PARAMEDIC) RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!"); }
It should be:

pawn Код:
case 416: { if(gTeam[playerid] != TEAM_PARAMEDIC) { RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!"); }}
Reply
#3

Thanks, but this don't solve the problem.
Reply
#4

Quote:
Originally Posted by XGh0stz
It should be:

pawn Код:
case 416: { if(gTeam[playerid] != TEAM_PARAMEDIC) { RemovePlayerFromVehicle(playerid); SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!"); }}
Actually, it should be:
pawn Код:
case 416:
       if(gTeam[playerid] != TEAM_PARAMEDIC) {
             RemovePlayerFromVehicle(playerid);
             SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!");
       }
break;
Learn to indent your code properly.
Reply
#5

It's still not working.
Reply
#6

Try this:
pawn Код:
case 416:
{
       if(gTeam[playerid] != TEAM_PARAMEDIC) {
             RemovePlayerFromVehicle(playerid);
             SendClientMessage(playerid, COLOR_RED, "This vehicle is only for paramedics!");
       }
}
Reply
#7

LOL, thanx James, you got a point there, indenting code is extremly important so others may view your script more clearly...

But over looking this code again, I notice you have this under OnVehicleEnter, try moving it to OnPlayerStateChange instead
Reason: OnVehicleEnter triggers when the player first opens the door to a vehicle which means he would not have the state of a driver during the check
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)