31.05.2011, 00:24
This should work (compiled with no errors for me):
As for the method you're using, I think it could be improved. You're using OnPlayerEnterVehicle which is called when the player starts to enter a vehicle. You're checking whether they're inside the vehicle when they start to enter it. The best way to check whether a player has just entered a vehicle is by checking their state, using OnPlayerStateChange:
Personally, I'd do the same thing using arrays to make it neater:
pawn Код:
//20 Score Aircraft
if( (GetPlayerScore(playerid) < 20) && IsPlayerInVehicle(playerid, 519) )
{
SendClientMessage(playerid, COLOR_RED, "You need 20 flying minutes (20 Score) to use the Shamal!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 20) && IsPlayerInVehicle(playerid, 563) )
{
SendClientMessage(playerid, COLOR_RED, "You need 20 flying minutes (20 Score) to use the Raindance!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 20) && IsPlayerInVehicle(playerid, 548) )
{
SendClientMessage(playerid, COLOR_RED, "You need 20 flying minutes (20 Score) to use the Cargobob!");
RemovePlayerFromVehicle(playerid);
}
//40 Score Aircraft
else if( (GetPlayerScore(playerid) < 40) && IsPlayerInVehicle(playerid, 577) )
{
SendClientMessage(playerid, COLOR_RED, "You need 40 flying minutes (40 Score) to use the AT-400!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 40) && IsPlayerInVehicle(playerid, 592) )
{
SendClientMessage(playerid, COLOR_RED, "You need 40 flying minutes (40 Score) to use the Andromada!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 40) && IsPlayerInVehicle(playerid, 417) )
{
SendClientMessage(playerid, COLOR_RED, "You need 40 flying minutes (40 Score) to use the Leviathan!");
RemovePlayerFromVehicle(playerid);
}
//60 Score Aircraft
else if( (GetPlayerScore(playerid) < 60) && IsPlayerInVehicle(playerid, 520) )
{
SendClientMessage(playerid, COLOR_RED, "You need 60 flying minutes (60 Score) to use the Hydra!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 60) && IsPlayerInVehicle(playerid, 592) )
{
SendClientMessage(playerid, COLOR_RED, "You need 60 flying minutes (60 Score) to use the Rustler!");
RemovePlayerFromVehicle(playerid);
}
else if( (GetPlayerScore(playerid) < 60) && IsPlayerInVehicle(playerid, 425) )
{
SendClientMessage(playerid, COLOR_RED, "You need 60 flying minutes (60 Score) to use the Hunter!");
RemovePlayerFromVehicle(playerid);
}
pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
{
//The players state has changed from on foot to in a vehicle.
//Check whether it's the vehicle here.
}
return 1;
}
pawn Код:
enum cPlaneData_ENUM
{
//enum of variables for plane data, so we can access them easier
nScore,
nVeh,
szVehName[ 64 ],
};
new cPlaneData[ ][ cPlaneData_ENUM ] =
{
//nScore, nVeh, nVehName
//0 , 1, 2
{ 20, 519, "Shamal" },
{ 20, 563, "Raindance" },
{ 20, 548, "Cargobob" },
{ 40, 577, "AT-400" },
{ 40, 592, "Andromada" },
{ 40, 417, "Leviathan" },
{ 60, 520, "Hydra" },
{ 60, 592, "Rustler" },
{ 60, 425, "Hunter" }
};
public OnPlayerStateChange(playerid,newstate,oldstate)
{
//The players state changed
if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
{
//They're now a driver.
for( new i=0; i < sizeof cPlaneData; i++ )
{
//Loop through array for plane data
if( IsPlayerInVehicle(playerid, cPlaneData[ i ][ nVeh ]) )
{
//They're in the vehicle from the array
if( GetPlayerScore(playerid) < cPlaneData[ i ][ nScore ] )
{
//If the players score is less than the defined score for this vehicle
new szStr[ 128 ];
format( szStr, sizeof szStr, "You need %d flying minutes (%d Score) to use the %s!", cPlaneData[ i ][ nScore ], cPlaneData[ i ][ nScore ], cPlaneData[ i ][ szVehName ] );
//Send message and remove them.
SendClientMessage( playerid, COLOR_RED, szStr );
RemovePlayerFromVehicle( playerid );
}
}
}
}
return 1;
}