added risk element into pilot job

added parameters into "/pilot [NORMAL/HARDER/STOP]"
fixed all related bugs according to bangs
This commit is contained in:
Steven Howard 2018-09-15 21:15:24 +01:00
parent 5bc7b36b1c
commit 5548bd4544

View File

@ -73,6 +73,7 @@ new
p_PilotCancelTimer [ MAX_PLAYERS ] = { 0xFFFF, ... }, p_PilotCancelTimer [ MAX_PLAYERS ] = { 0xFFFF, ... },
p_PilotLoadTimer [ MAX_PLAYERS ] = { 0xFFFF, ... }, p_PilotLoadTimer [ MAX_PLAYERS ] = { 0xFFFF, ... },
p_PilotCargo [ MAX_PLAYERS ], p_PilotCargo [ MAX_PLAYERS ],
p_PilotDifficulty [ MAX_PLAYERS ],
p_PilotVehicle [ MAX_PLAYERS ], p_PilotVehicle [ MAX_PLAYERS ],
p_PilotTimeElapsed [ MAX_PLAYERS ], p_PilotTimeElapsed [ MAX_PLAYERS ],
Float: p_PilotDistance [ MAX_PLAYERS ], Float: p_PilotDistance [ MAX_PLAYERS ],
@ -86,11 +87,20 @@ hook OnPlayerDisconnect( playerid, reason )
return 1; return 1;
} }
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
StopPlayerPilotWork( playerid );
return 1;
}
hook OnPlayerUpdateEx( playerid ) hook OnPlayerUpdateEx( playerid )
{ {
new player_vehicle = GetPlayerVehicleID( playerid ); new player_vehicle = GetPlayerVehicleID( playerid );
// check if the player has detached their trailer
if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER && player_vehicle && p_hasPilotJob{ playerid } && p_PilotVehicle[ playerid ] != player_vehicle && p_PilotCancelTimer[ playerid ] == 0xFFFF ) { if ( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER && player_vehicle && p_hasPilotJob{ playerid } && p_PilotVehicle[ playerid ] != player_vehicle && p_PilotCancelTimer[ playerid ] == 0xFFFF ) {
cancelPlayerPilotWork( playerid, player_vehicle, .ticks = 60 ); cancelPlayerPilotWork( playerid, player_vehicle, .ticks = 60 );
} }
@ -101,7 +111,7 @@ hook OnPlayerUpdateEx( playerid )
hook OnPlayerStateChange( playerid, newstate, oldstate ) hook OnPlayerStateChange( playerid, newstate, oldstate )
{ {
if ( newstate != PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_DRIVER && p_hasPilotJob{ playerid } ) { if ( newstate != PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_DRIVER && p_hasPilotJob{ playerid } ) {
cancelPlayerPilotWork( playerid, GetPlayerVehicleID( playerid ), .ticks = 60 ); cancelPlayerPilotWork( playerid, GetPlayerVehicleID( playerid ), .ticks = 0 );
} }
else if ( newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER && p_hasPilotJob{ playerid } ) { else if ( newstate == PLAYER_STATE_DRIVER && oldstate != PLAYER_STATE_DRIVER && p_hasPilotJob{ playerid } ) {
@ -110,7 +120,8 @@ hook OnPlayerStateChange( playerid, newstate, oldstate )
} }
else if ( newstate == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid) && !p_hasPilotJob{ playerid }) { else if ( newstate == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid) && !p_hasPilotJob{ playerid }) {
if ( IsVehiclePlane( GetPlayerVehicleID( playerid ) ) ) { if ( IsVehiclePlane( GetPlayerVehicleID( playerid ) ) )
{
ShowPlayerHelpDialog( playerid, 3000, "You can begin a pilot job by typing ~g~~h~/pilot" ); ShowPlayerHelpDialog( playerid, 3000, "You can begin a pilot job by typing ~g~~h~/pilot" );
} }
} }
@ -126,8 +137,6 @@ hook OnPlayerEnterDynRaceCP( playerid, checkpointid )
DestroyDynamicRaceCP ( p_PilotCheckPoint[ playerid ] ); DestroyDynamicRaceCP ( p_PilotCheckPoint[ playerid ] );
KillTimer ( p_PilotPositionTimer[ playerid ] ); KillTimer ( p_PilotPositionTimer[ playerid ] );
GivePlayerWantedLevel( playerid, 6 );
if ( p_PilotRoute[ playerid ] { 0 } != INVALID_PILOT_ROUTE ) if ( p_PilotRoute[ playerid ] { 0 } != INVALID_PILOT_ROUTE )
{ {
static aPlayer[ 1 ]; aPlayer[ 0 ] = playerid; static aPlayer[ 1 ]; aPlayer[ 0 ] = playerid;
@ -141,6 +150,9 @@ hook OnPlayerEnterDynRaceCP( playerid, checkpointid )
TogglePlayerControllable(playerid, false); TogglePlayerControllable(playerid, false);
if ( p_PilotDifficulty[ playerid ] == RISK_FACTOR_HARD)
GivePlayerWantedLevel( playerid, 6 );
ShowPlayerHelpDialog( playerid, 5000, "Please wait while your cargo is getting loaded into your vehicle!" ); ShowPlayerHelpDialog( playerid, 5000, "Please wait while your cargo is getting loaded into your vehicle!" );
p_PilotMapIcon [ playerid ] = CreateDynamicMapIconEx( g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_X ], g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_Y ], g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_Z ], 51, 0, MAPICON_GLOBAL, 6000.0, { -1 }, { -1 }, aPlayer ); p_PilotMapIcon [ playerid ] = CreateDynamicMapIconEx( g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_X ], g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_Y ], g_DropOffLocations[ p_PilotRoute[ playerid ] { 1 } ] [ E_Z ], 51, 0, MAPICON_GLOBAL, 6000.0, { -1 }, { -1 }, aPlayer );
@ -152,6 +164,11 @@ hook OnPlayerEnterDynRaceCP( playerid, checkpointid )
else if ( p_PilotRoute[ playerid ] { 1 } != INVALID_PILOT_ROUTE ) else if ( p_PilotRoute[ playerid ] { 1 } != INVALID_PILOT_ROUTE )
{ {
new new
iCashEarned;
if ( p_PilotDifficulty[ playerid ] == RISK_FACTOR_EASY)
iCashEarned = floatround( p_PilotDistance[ playerid ] * 1.0 + PILOT_BONUS );
else
iCashEarned = floatround( p_PilotDistance[ playerid ] * 2.0 + PILOT_BONUS ); iCashEarned = floatround( p_PilotDistance[ playerid ] * 2.0 + PILOT_BONUS );
TextDrawHideForPlayer( playerid, p_TruckingTD[ playerid ] ); TextDrawHideForPlayer( playerid, p_TruckingTD[ playerid ] );
@ -161,6 +178,7 @@ hook OnPlayerEnterDynRaceCP( playerid, checkpointid )
ShowPlayerHelpDialog( playerid, 5000, "You have earned ~y~%s ~w~for exporting %s!", cash_format( iCashEarned ), g_CargoName[ p_PilotCargo[ playerid ] ] ); ShowPlayerHelpDialog( playerid, 5000, "You have earned ~y~%s ~w~for exporting %s!", cash_format( iCashEarned ), g_CargoName[ p_PilotCargo[ playerid ] ] );
p_PilotDifficulty [ playerid ] = -1;
p_PilotDistance [ playerid ] = 0.0; p_PilotDistance [ playerid ] = 0.0;
p_hasPilotJob [ playerid ] = false; p_hasPilotJob [ playerid ] = false;
p_PilotCheckPoint [ playerid ] = 0xFFFF; p_PilotCheckPoint [ playerid ] = 0xFFFF;
@ -193,15 +211,13 @@ stock getClosestPilotRoute( playerid, &Float: distance = FLOAT_INFINITY )
stock StopPlayerPilotWork( playerid ) stock StopPlayerPilotWork( playerid )
{ {
if ( !p_hasPilotJob { playerid } )
return SendError( playerid, "You cannot cancel a pilot job that hasn't started.");
DestroyDynamicRaceCP ( p_PilotCheckPoint[ playerid ] ); DestroyDynamicRaceCP ( p_PilotCheckPoint[ playerid ] );
DestroyDynamicMapIcon ( p_PilotMapIcon[ playerid ] ); DestroyDynamicMapIcon ( p_PilotMapIcon[ playerid ] );
KillTimer ( p_PilotCancelTimer[ playerid ] ); KillTimer ( p_PilotCancelTimer[ playerid ] );
KillTimer ( p_PilotPositionTimer[ playerid ] ); KillTimer ( p_PilotPositionTimer[ playerid ] );
p_PilotDifficulty [ playerid ] = -1;
p_PilotDistance [ playerid ] = 0.0; p_PilotDistance [ playerid ] = 0.0;
p_hasPilotJob { playerid } = false; p_hasPilotJob { playerid } = false;
p_PilotCheckPoint [ playerid ] = 0xFFFF; p_PilotCheckPoint [ playerid ] = 0xFFFF;
@ -213,8 +229,7 @@ stock StopPlayerPilotWork( playerid )
p_PilotCargo [ playerid ] = -1; p_PilotCargo [ playerid ] = -1;
p_PilotVehicle [ playerid ] = INVALID_VEHICLE_ID; p_PilotVehicle [ playerid ] = INVALID_VEHICLE_ID;
TextDrawHideForPlayer( playerid, p_TruckingTD[ playerid ] ); TextDrawHideForPlayer( playerid, p_TruckingTD[ playerid ] ), 1;
return SendServerMessage( playerid, "Your pilot mission has been stopped." );
} }
stock IsVehiclePlane ( vehicleid ) stock IsVehiclePlane ( vehicleid )
@ -254,6 +269,7 @@ function cancelPlayerPilotWork( playerid, vehicleid, ticks )
if ( ticks < 1 || !IsPlayerConnected( playerid ) || !IsPlayerSpawned( playerid ) ) if ( ticks < 1 || !IsPlayerConnected( playerid ) || !IsPlayerSpawned( playerid ) )
{ {
StopPlayerPilotWork( playerid ); StopPlayerPilotWork( playerid );
return SendServerMessage( playerid, "Your pilot mission has been stopped." );
} }
else else
{ {
@ -282,17 +298,19 @@ function OnPilotLoadCargo( playerid )
CMD:pilot( playerid, params[ ] ) CMD:pilot( playerid, params[ ] )
{ {
new new
szDifficulty[ 7 ],
iVehicle = GetPlayerVehicleID( playerid ); iVehicle = GetPlayerVehicleID( playerid );
if ( p_Class[ playerid ] != CLASS_CIVILIAN ) return SendError( playerid, "You must be an ordinary civilian to use this command." ); if ( p_Class[ playerid ] != CLASS_CIVILIAN ) return SendError( playerid, "You must be an ordinary civilian to use this command." );
else if ( strmatch( params, "STOP" ))
{
return StopPlayerPilotWork( playerid ), 1;
}
else if ( !strmatch( params, "WORK" )) return SendUsage( playerid, "/pilot [WORK/STOP]" );
else if ( GetPlayerState( playerid ) != PLAYER_STATE_DRIVER ) return SendError( playerid, "You must be a driver of a vehicle to work." ); else if ( GetPlayerState( playerid ) != PLAYER_STATE_DRIVER ) return SendError( playerid, "You must be a driver of a vehicle to work." );
else if ( !iVehicle ) return SendError( playerid, "You are not in any vehicle." ); else if ( !iVehicle ) return SendError( playerid, "You are not in any vehicle." );
else else if ( sscanf( params, "S(normal)[7]", szDifficulty ) ) return SendUsage( playerid, "/pilot [NORMAL/HARDER/STOP]" );
else if ( strmatch( szDifficulty, "stop" ))
{
StopPlayerPilotWork( playerid );
return SendServerMessage( playerid, "Your pilot mission has been stopped." );
}
else if ( strmatch( szDifficulty, "normal" ) || strmatch( szDifficulty, "harder" ))
{ {
if ( IsVehiclePlane( iVehicle )) if ( IsVehiclePlane( iVehicle ))
{ {
@ -307,6 +325,7 @@ CMD:pilot( playerid, params[ ] )
p_hasPilotJob { playerid } = true; p_hasPilotJob { playerid } = true;
p_WorkCooldown [ playerid ] = g_iTime + 60; p_WorkCooldown [ playerid ] = g_iTime + 60;
p_PilotVehicle [ playerid ] = GetPlayerVehicleID( playerid ); p_PilotVehicle [ playerid ] = GetPlayerVehicleID( playerid );
p_PilotDifficulty [ playerid ] = ( strmatch( szDifficulty, "harder" ) ? RISK_FACTOR_HARD : RISK_FACTOR_EASY );
p_PilotCargo [ playerid ] = random( sizeof( g_CargoName ) ); p_PilotCargo [ playerid ] = random( sizeof( g_CargoName ) );
p_PilotRoute [ playerid ] { 0 } = random ( sizeof ( g_AirportLocations ) ); p_PilotRoute [ playerid ] { 0 } = random ( sizeof ( g_AirportLocations ) );