I want : when player enter on a bus pay the driver - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I want : when player enter on a bus pay the driver (
/showthread.php?tid=463351)
I want : when player enter on a bus pay the driver -
Kapone21 - 11.09.2013
I want:
When a player enter on a bus
if(HaveTicket[playerid] == 0) to eject him
if (HaveTicket[playerid] == 1) to give the driver of bus 100$ and say X has enered on bus
Re: I want : when player enter on a bus pay the driver -
Konstantinos - 11.09.2013
I think that GetPlayerVehicleID returns the vehicle id even if you're passenger. If it does, then this should work:
pawn Code:
public OnPlayerStateChange( playerid, newstate, oldstate )
{
if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_PASSENGER && GetVehicleModel( GetPlayerVehicleID( playerid ) ) == 431 )
{
if( HaveTicket[ playerid ] == 0 ) RemovePlayerFromVehicle( playerid );
else if( HaveTicket[ playerid ] == 1 )
{
new
driver = GetVehicleDriver( GetPlayerVehicleID( playerid ) ),
passenger_name[ MAX_PLAYER_NAME ],
msg[ 50 ]
;
if( driver != INVALID_PLAYER_ID ) GivePlayerMoney( driver, 100 );
// GivePlayerMoney( playerid, -100 ); // Take the money from the passenger as well
GetPlayerName( playerid, passenger_name, MAX_PLAYER_NAME );
format( msg, sizeof( msg ), "%s has entered the bus!", passenger_name );
SendClientMessageToAll( 0xFFFF00FF, msg );
}
}
return 1;
}
stock GetVehicleDriver( vehicleid )
{
for( new i = 0; i < MAX_PLAYERS; i++ )
{
if( !IsPlayerConnected( i ) ) continue;
if( IsPlayerInVehicle( i, vehicleid ) && GetPlayerState( i ) == PLAYER_STATE_DRIVER ) return i;
}
return INVALID_PLAYER_ID;
}