modulize roadblock system

This commit is contained in:
Lorenc Pekaj 2018-10-10 14:35:08 +11:00
parent 2e0d92f2a7
commit f392745ec6
2 changed files with 210 additions and 179 deletions

View File

@ -0,0 +1,210 @@
/*
* Irresistible Gaming (c) 2018
* Developed by Lorenc Pekaj
* Module:
* Purpose:
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Definitions ** */
#define MAX_ROADBLOCKS ( 32 )
/* ** Variables ** */
enum E_ROADBLOCK_DATA
{
E_OBJECT_ID, Text3D: E_LABEL, E_CREATOR,
Float: E_X, Float: E_Y, Float: E_Z
};
enum E_ROADBLOCK_OBJ_DATA
{
E_NAME[ 17 ], E_MODEL, Float: E_OFFSET
};
static stock
g_roadblockData [ MAX_ROADBLOCKS ] [ E_ROADBLOCK_DATA ],
Iterator: roadblocks < MAX_ROADBLOCKS >,
g_roadblockObjectData [ ] [ E_ROADBLOCK_OBJ_DATA ] =
{
{ "Small Roadblock", 1459, 0.2 },
{ "Medium Roadblock", 978, 0.5 },
{ "Big Roadblock", 981, 0.2 },
{ "Detour Sign", 1425, 0.6 },
{ "Will Be Sign", 3265, 0.9 },
{ "Line Closed Sign", 3091, 0.5 }
}
;
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason )
{
ClearPlayerRoadblocks( playerid, .distance_check = false );
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
ClearPlayerRoadblocks( playerid, .distance_check = false );
return 1;
}
hook OnPlayerUpdateEx( playerid )
{
if ( IsPlayerSpawned( playerid ) && GetPlayerClass( playerid ) == CLASS_POLICE ) {
ClearPlayerRoadblocks( playerid );
}
return 1;
}
/* ** Commands ** */
CMD:drball( playerid, params[ ] )
{
if ( ! p_inFBI{ playerid } && ! p_AdminLevel[ playerid ] )
return SendError( playerid, "You are not in the FBI." );
new
removed = 0;
foreach ( new handle : roadblocks )
{
if ( ! p_AdminLevel[ playerid ] && g_roadblockData[ handle ] [ E_CREATOR ] != playerid )
continue;
new
cur = handle;
destroyRoadBlockStrip( handle, .remove_iter = false );
Iter_SafeRemove( roadblocks, cur, handle );
removed ++;
}
if ( removed ) {
return SendServerMessage( playerid, "You have removed all your roadblocks." );
} else {
return SendError( playerid, "There are no roadblocks to remove by you." );
}
}
CMD:drb( playerid, params[ ] )
{
new
rbID
;
if ( !p_inFBI{ playerid } ) return SendError( playerid, "You are not in the FBI." );
else if ( GetPlayerScore( playerid ) < 250 ) return SendError( playerid, "You need at least 250 score to use this feature." );
else if ( sscanf( params, "d", rbID ) ) return SendUsage( playerid, "/drb [ROADBLOCK_ID]" );
else if ( rbID < 0 || rbID > MAX_ROADBLOCKS ) return SendError( playerid, "Invalid road block ID." );
else if ( Iter_Contains( roadblocks, rbID ) ) return SendError( playerid, "Invalid road block ID." );
else if ( g_roadblockData[ rbID ] [ E_CREATOR ] != playerid ) return SendError( playerid, "You have not created this spike strip." );
else
{
destroyRoadBlockStrip( rbID, .remove_iter = true );
SendServerMessage( playerid, "You have succesfully destroyed a road block." );
}
return 1;
}
CMD:crb( playerid, params[ ] )
{
new
iRoadBlock;
if ( GetPlayerInterior( playerid ) != 0 || GetPlayerVirtualWorld( playerid ) != 0 ) return SendError( playerid, "You cannot use this command inside buildings." );
else if ( IsPlayerKidnapped( playerid ) ) return SendError( playerid, "You are kidnapped, you cannot do this." );
else if ( IsPlayerTied( playerid ) ) return SendError( playerid, "You are tied, you cannot do this." );
else if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You are jailed, you cannot do this." );
else if ( !p_inFBI{ playerid } ) return SendError( playerid, "You are not in the FBI." );
else if ( IsPlayerInAnyVehicle( playerid ) ) return SendError( playerid, "You cannot use this command while in a vehicle." );
else if ( IsPlayerInWater( playerid ) ) return SendError( playerid, "You cannot use this command since you're in water." );
else if ( isnull( params ) ) return SendUsage( playerid, "/crb [SMALL/MEDIUM/BIG/CONE/DETOUR/WILL BE SIGN/LINE CLOSED]" );
else
{
for( iRoadBlock = 0; iRoadBlock < sizeof( g_roadblockObjectData ); iRoadBlock++ )
if ( strfind( g_roadblockObjectData[ iRoadBlock ] [ E_NAME ], params, true ) != -1 )
break;
if ( iRoadBlock >= sizeof( g_roadblockObjectData ) )
return SendError( playerid, "You have typed in an invalid roadblock." );
new
iTmp = createRoadBlockStrip( playerid, iRoadBlock );
if ( iTmp != -1 )
SendServerMessage( playerid, "You have succesfully placed a "COL_GREY"%s"COL_WHITE".", g_roadblockObjectData[ iRoadBlock ] [ E_NAME ] );
else
SendError( playerid, "Failed to place a road block due to a unexpected error." );
}
return 1;
}
/* ** Functions ** */
stock destroyRoadBlockStrip( rbid, bool: remove_iter = false )
{
if ( ! Iter_Contains( roadblocks, rbid ) )
return 0;
DestroyDynamicObject( g_roadblockData[ rbid ] [ E_OBJECT_ID ] );
DestroyDynamic3DTextLabel( g_roadblockData[ rbid ] [ E_LABEL ] );
g_roadblockData[ rbid ] [ E_LABEL ] = Text3D: INVALID_3DTEXT_ID;
g_roadblockData[ rbid ] [ E_OBJECT_ID ] = INVALID_OBJECT_ID;
if ( remove_iter ) Iter_Remove( roadblocks, rbid );
return 1;
}
stock createRoadBlockStrip( playerid, type )
{
new
ID = Iter_Free( roadblocks ),
Float: X, Float: Y, Float: Z, Float: Degree
;
if ( ID != ITER_NONE )
{
GetXYInFrontOfPlayer( playerid, X, Y, Z, 2.0 );
GetPlayerFacingAngle( playerid, Degree );
g_roadblockData[ ID ] [ E_CREATOR ] = playerid;
g_roadblockData[ ID ] [ E_X ] = X;
g_roadblockData[ ID ] [ E_Y ] = Y;
g_roadblockData[ ID ] [ E_Z ] = Z;
DestroyDynamicObject( g_roadblockData[ ID ] [ E_OBJECT_ID ] );
DestroyDynamic3DTextLabel( g_roadblockData[ ID ] [ E_LABEL ] );
g_roadblockData[ ID ] [ E_OBJECT_ID ] = CreateDynamicObject( g_roadblockObjectData[ type ] [ E_MODEL ], X, Y, Z - g_roadblockObjectData[ type ] [ E_OFFSET ], 0, 0, Degree + 180.0 );
g_roadblockData[ ID ] [ E_LABEL ] = CreateDynamic3DTextLabel( sprintf( "%s(%d)\n"COL_GREY"Placed by %s!", g_roadblockObjectData[ type ] [ E_NAME ], ID, ReturnPlayerName( playerid ) ), COLOR_GOLD, X, Y, Z, 20.0 );
Streamer_Update( playerid );
Iter_Add( roadblocks, ID );
}
return ID;
}
stock ClearPlayerRoadblocks( playerid, bool: distance_check = true )
{
// remove roadblocks
foreach ( new handle : roadblocks ) if ( g_roadblockData[ handle ] [ E_CREATOR ] == playerid )
{
if ( distance_check && GetPlayerDistanceFromPoint( playerid, g_roadblockData[ handle ] [ E_X ], g_roadblockData[ handle ] [ E_Y ], g_roadblockData[ handle ] [ E_Z ] ) < 100.0 ) {
continue;
}
new
cur = handle;
destroyRoadBlockStrip( handle, .remove_iter = false );
Iter_SafeRemove( roadblocks, cur, handle );
}
return 1;
}

View File

@ -171,36 +171,6 @@ new
Iterator:gates<MAX_GATES> Iterator:gates<MAX_GATES>
; ;
/* ** Road Blocks ** */
#define MAX_ROADBLOCKS ( 32 )
enum E_ROADBLOCK_DATA
{
E_OBJECT_ID, Text3D: E_LABEL, E_CREATOR,
Float: E_X, Float: E_Y, Float: E_Z
};
enum E_ROADBLOCK_OBJ_DATA
{
E_NAME[ 17 ], E_MODEL, Float: E_OFFSET
};
new
g_roadblockData [ MAX_ROADBLOCKS ] [ E_ROADBLOCK_DATA ],
Iterator: roadblocks < MAX_ROADBLOCKS >,
g_roadblockObjectData [ ] [ E_ROADBLOCK_OBJ_DATA ] =
{
{ "Small Roadblock", 1459, 0.2 },
{ "Medium Roadblock", 978, 0.5 },
{ "Big Roadblock", 981, 0.2 },
{ "Detour Sign", 1425, 0.6 },
{ "Will Be Sign", 3265, 0.9 },
{ "Line Closed Sign", 3091, 0.5 }
}
;
/* ** ATM System ** */ /* ** ATM System ** */
#if defined MAX_FACILITIES #if defined MAX_FACILITIES
#define MAX_ATMS ( 48 + MAX_FACILITIES ) #define MAX_ATMS ( 48 + MAX_FACILITIES )
@ -1391,10 +1361,6 @@ public OnServerUpdateTimer( )
UpdateDynamic3DTextLabelText( p_RewardsLabel_4Drags[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); UpdateDynamic3DTextLabelText( p_RewardsLabel_4Drags[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) );
UpdateDynamic3DTextLabelText( p_RewardsLabel_Visage[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); UpdateDynamic3DTextLabelText( p_RewardsLabel_Visage[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) );
// Remove spike strips & roadblocks
if ( p_Class[ playerid ] == CLASS_POLICE )
ClearPlayerRoadblocks( playerid );
// Toggle total coin bar // Toggle total coin bar
if ( ! IsPlayerSettingToggled( playerid, SETTING_COINS_BAR ) ) if ( ! IsPlayerSettingToggled( playerid, SETTING_COINS_BAR ) )
PlayerTextDrawSetString( playerid, p_CoinsTD[ playerid ], sprintf( "%05.3f", p_IrresistibleCoins[ playerid ] ) ); PlayerTextDrawSetString( playerid, p_CoinsTD[ playerid ], sprintf( "%05.3f", p_IrresistibleCoins[ playerid ] ) );
@ -2498,7 +2464,6 @@ public OnPlayerDisconnect( playerid, reason )
LeavePlayerPaintball( playerid ); LeavePlayerPaintball( playerid );
resetPlayerStreaks( playerid ); resetPlayerStreaks( playerid );
RemovePlayerFromRace( playerid ); RemovePlayerFromRace( playerid );
ClearPlayerRoadblocks( playerid, .distance_check = false );
ResetPlayerPassiveMode( playerid ); ResetPlayerPassiveMode( playerid );
//p_Detained { playerid } = false; //p_Detained { playerid } = false;
p_Tied { playerid } = false; p_Tied { playerid } = false;
@ -3540,7 +3505,6 @@ public OnPlayerDeath( playerid, killerid, reason )
KillTimer( p_CuffAbuseTimer[ playerid ] ); KillTimer( p_CuffAbuseTimer[ playerid ] );
ResetPlayerPassiveMode( playerid ); ResetPlayerPassiveMode( playerid );
PlayerTextDrawHide( playerid, p_LocationTD[ playerid ] ); PlayerTextDrawHide( playerid, p_LocationTD[ playerid ] );
ClearPlayerRoadblocks( playerid, .distance_check = false );
p_Tazed{ playerid } = false; p_Tazed{ playerid } = false;
p_WeaponDealing{ playerid } = false; p_WeaponDealing{ playerid } = false;
p_WeaponDealer[ playerid ] = INVALID_PLAYER_ID; p_WeaponDealer[ playerid ] = INVALID_PLAYER_ID;
@ -7269,88 +7233,6 @@ CMD:bj( playerid, params[ ] )
return 1; return 1;
} }
CMD:drball( playerid, params[ ] )
{
new removed = 0;
new is_admin = p_AdminLevel[ playerid ];
if ( ! p_inFBI{ playerid } && ! is_admin )
return SendError( playerid, "You are not in the FBI." );
foreach ( new handle : roadblocks )
{
if ( ! is_admin && g_roadblockData[ handle ] [ E_CREATOR ] != playerid )
continue;
new
cur = handle;
destroyRoadBlockStrip( handle, .remove_iter = false );
Iter_SafeRemove( roadblocks, cur, handle );
removed ++;
}
if ( removed ) {
return SendServerMessage( playerid, "You have removed all your roadblocks." );
} else {
return SendError( playerid, "There are no roadblocks to remove by you." );
}
}
CMD:drb( playerid, params[ ] )
{
new
rbID
;
if ( !p_inFBI{ playerid } ) return SendError( playerid, "You are not in the FBI." );
else if ( GetPlayerScore( playerid ) < 250 ) return SendError( playerid, "You need at least 250 score to use this feature." );
else if ( sscanf( params, "d", rbID ) ) return SendUsage( playerid, "/drb [ROADBLOCK_ID]" );
else if ( rbID < 0 || rbID > MAX_ROADBLOCKS ) return SendError( playerid, "Invalid road block ID." );
else if ( Iter_Contains( roadblocks, rbID ) ) return SendError( playerid, "Invalid road block ID." );
else if ( g_roadblockData[ rbID ] [ E_CREATOR ] != playerid ) return SendError( playerid, "You have not created this spike strip." );
else
{
destroyRoadBlockStrip( rbID, .remove_iter = true );
SendServerMessage( playerid, "You have succesfully destroyed a road block." );
}
return 1;
}
CMD:crb( playerid, params[ ] )
{
new
iRoadBlock;
if ( GetPlayerInterior( playerid ) != 0 || GetPlayerVirtualWorld( playerid ) != 0 ) return SendError( playerid, "You cannot use this command inside buildings." );
else if ( IsPlayerKidnapped( playerid ) ) return SendError( playerid, "You are kidnapped, you cannot do this." );
else if ( IsPlayerTied( playerid ) ) return SendError( playerid, "You are tied, you cannot do this." );
else if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You are jailed, you cannot do this." );
else if ( !p_inFBI{ playerid } ) return SendError( playerid, "You are not in the FBI." );
else if ( IsPlayerInAnyVehicle( playerid ) ) return SendError( playerid, "You cannot use this command while in a vehicle." );
else if ( IsPlayerInWater( playerid ) ) return SendError( playerid, "You cannot use this command since you're in water." );
else if ( isnull( params ) ) return SendUsage( playerid, "/crb [SMALL/MEDIUM/BIG/CONE/DETOUR/WILL BE SIGN/LINE CLOSED]" );
else
{
for( iRoadBlock = 0; iRoadBlock < sizeof( g_roadblockObjectData ); iRoadBlock++ )
if ( strfind( g_roadblockObjectData[ iRoadBlock ] [ E_NAME ], params, true ) != -1 )
break;
if ( iRoadBlock >= sizeof( g_roadblockObjectData ) )
return SendError( playerid, "You have typed in an invalid roadblock." );
new
iTmp = createRoadBlockStrip( playerid, iRoadBlock );
if ( iTmp != -1 )
SendServerMessage( playerid, "You have succesfully placed a "COL_GREY"%s"COL_WHITE".", g_roadblockObjectData[ iRoadBlock ] [ E_NAME ] );
else
SendError( playerid, "Failed to place a road block due to a unexpected error." );
}
return 1;
}
CMD:report( playerid, params[ ] ) CMD:report( playerid, params[ ] )
{ {
new new
@ -15284,50 +15166,6 @@ stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, &Float:z, Float:distanc
y += (distance * floatcos(-a, degrees)); y += (distance * floatcos(-a, degrees));
} }
stock destroyRoadBlockStrip( rbid, bool: remove_iter = false )
{
if ( ! Iter_Contains( roadblocks, rbid ) )
return 0;
DestroyDynamicObject( g_roadblockData[ rbid ] [ E_OBJECT_ID ] );
DestroyDynamic3DTextLabel( g_roadblockData[ rbid ] [ E_LABEL ] );
g_roadblockData[ rbid ] [ E_LABEL ] = Text3D: INVALID_3DTEXT_ID;
g_roadblockData[ rbid ] [ E_OBJECT_ID ] = INVALID_OBJECT_ID;
if ( remove_iter ) Iter_Remove( roadblocks, rbid );
return 1;
}
stock createRoadBlockStrip( playerid, type )
{
new
ID = Iter_Free( roadblocks ),
Float: X, Float: Y, Float: Z, Float: Degree
;
if ( ID != ITER_NONE )
{
GetXYInFrontOfPlayer( playerid, X, Y, Z, 2.0 );
GetPlayerFacingAngle( playerid, Degree );
g_roadblockData[ ID ] [ E_CREATOR ] = playerid;
g_roadblockData[ ID ] [ E_X ] = X;
g_roadblockData[ ID ] [ E_Y ] = Y;
g_roadblockData[ ID ] [ E_Z ] = Z;
DestroyDynamicObject( g_roadblockData[ ID ] [ E_OBJECT_ID ] );
DestroyDynamic3DTextLabel( g_roadblockData[ ID ] [ E_LABEL ] );
g_roadblockData[ ID ] [ E_OBJECT_ID ] = CreateDynamicObject( g_roadblockObjectData[ type ] [ E_MODEL ], X, Y, Z - g_roadblockObjectData[ type ] [ E_OFFSET ], 0, 0, Degree + 180.0 );
g_roadblockData[ ID ] [ E_LABEL ] = CreateDynamic3DTextLabel( sprintf( "%s(%d)\n"COL_GREY"Placed by %s!", g_roadblockObjectData[ type ] [ E_NAME ], ID, ReturnPlayerName( playerid ) ), COLOR_GOLD, X, Y, Z, 20.0 );
Streamer_Update( playerid );
Iter_Add( roadblocks, ID );
}
return ID;
}
stock ChangeVehicleModel( vehicleid, objectid, Float: offset = 0.0 ) stock ChangeVehicleModel( vehicleid, objectid, Float: offset = 0.0 )
{ {
new new
@ -15367,23 +15205,6 @@ stock SetObjectFacePoint(iObjectID, Float: fX, Float: fY, Float: fOffset, bool:
} }
} }
stock ClearPlayerRoadblocks( playerid, bool: distance_check = true )
{
// remove roadblocks
foreach ( new handle : roadblocks ) if ( g_roadblockData[ handle ] [ E_CREATOR ] == playerid ) {
if ( distance_check && GetPlayerDistanceFromPoint( playerid, g_roadblockData[ handle ] [ E_X ], g_roadblockData[ handle ] [ E_Y ], g_roadblockData[ handle ] [ E_Z ] ) < 100.0 ) {
continue;
}
new
cur = handle;
destroyRoadBlockStrip( handle, .remove_iter = false );
Iter_SafeRemove( roadblocks, cur, handle );
}
return 1;
}
stock encode_tires( tires1, tires2, tires3, tires4 ) stock encode_tires( tires1, tires2, tires3, tires4 )
return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3); return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);