modulize bribes
This commit is contained in:
parent
f392745ec6
commit
233b913fe6
@ -543,6 +543,7 @@ CMD:reconnectchuff( playerid, params[ ] )
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined __cnr__features__bribes
|
||||
CMD:createbribe( playerid, params[ ] )
|
||||
{
|
||||
new
|
||||
@ -563,7 +564,9 @@ CMD:createbribe( playerid, params[ ] )
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined __cnr__features__bribes
|
||||
CMD:destroybribe( playerid, params[ ] )
|
||||
{
|
||||
new
|
||||
@ -573,7 +576,7 @@ CMD:destroybribe( playerid, params[ ] )
|
||||
if ( p_AdminLevel[ playerid ] < 5 ) return SendError( playerid, ADMIN_COMMAND_REJECT );
|
||||
else if ( sscanf( params, "d", bID ) ) return SendUsage( playerid, "/destroybribe [BRIBE_ID]" );
|
||||
else if ( bID < 0 || bID > MAX_BRIBES ) return SendError( playerid, "Invalid Bribe ID." );
|
||||
else if ( !Iter_Contains( BribeCount, bID ) ) return SendError( playerid, "Invalid Bribe ID." );
|
||||
else if ( ! Bribe_IsValid( bID ) ) return SendError( playerid, "Invalid Bribe ID." );
|
||||
else
|
||||
{
|
||||
SaveToAdminLog( playerid, bID, "destroyed bribe" );
|
||||
@ -583,6 +586,7 @@ CMD:destroybribe( playerid, params[ ] )
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
CMD:createcar( playerid, params[ ] )
|
||||
{
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "irresistible\cnr\features\spikestrips.pwn"
|
||||
#include "irresistible\cnr\features\perks.pwn"
|
||||
#include "irresistible\cnr\features\weapon_locker.pwn"
|
||||
#include "irresistible\cnr\features\bribes.pwn"
|
||||
|
||||
// disabled
|
||||
// #include "irresistible\cnr\features\eastereggs.pwn"
|
||||
|
153
gamemodes/irresistible/cnr/features/bribes.pwn
Normal file
153
gamemodes/irresistible/cnr/features/bribes.pwn
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Irresistible Gaming (c) 2018
|
||||
* Developed by Lorenc Pekaj
|
||||
* Module: cnr\features\bribes.pwn
|
||||
* Purpose: pickupable bribes that reduce a player's wanted level
|
||||
*/
|
||||
|
||||
/* ** Error checking ** */
|
||||
#if !defined __cnr__features__bribes
|
||||
#define __cnr__features__bribes
|
||||
#endif
|
||||
|
||||
/* ** Includes ** */
|
||||
#include < YSI\y_hooks >
|
||||
|
||||
/* ** Definitions ** */
|
||||
#define MAX_BRIBES ( 200 )
|
||||
#define MAX_BRIBE_WAIT ( 300 )
|
||||
|
||||
/* ** Variables ** */
|
||||
enum E_BRIBE_DATA
|
||||
{
|
||||
bool: E_DISABLED, E_PICKUP[ 2 ], Text3D: E_LABEL,
|
||||
Float: E_X, Float: E_Y, Float: E_Z,
|
||||
E_TIMESTAMP
|
||||
};
|
||||
|
||||
static stock
|
||||
g_bribeData [ MAX_BRIBES ] [ E_BRIBE_DATA ],
|
||||
Iterator: BribeCount < MAX_BRIBES >
|
||||
;
|
||||
|
||||
/* ** Hooks ** */
|
||||
hook OnScriptInit( )
|
||||
{
|
||||
mysql_function_query( dbHandle, "SELECT * FROM `BRIBES`", true, "OnBribeLoad", "" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
hook OnServerUpdate( )
|
||||
{
|
||||
foreach ( new bribeid : BribeCount ) if ( GetServerTime( ) > g_bribeData[ bribeid ] [ E_TIMESTAMP ] && g_bribeData[ bribeid ] [ E_DISABLED ] ) // Replenish Bribes
|
||||
{
|
||||
UpdateDynamic3DTextLabelText( g_bribeData[ bribeid ] [ E_LABEL ], COLOR_GOLD, sprintf( "Bribe(%d)", bribeid ) );
|
||||
g_bribeData[ bribeid ] [ E_DISABLED ] = false;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
hook OnPlayerPickUpDynPickup( playerid, pickupid )
|
||||
{
|
||||
if ( GetPlayerClass( playerid ) != CLASS_POLICE )
|
||||
{
|
||||
foreach ( new bribeid : BribeCount ) if ( g_bribeData[ bribeid ] [ E_PICKUP ] [ 0 ] == pickupid || g_bribeData[ bribeid ] [ E_PICKUP ] [ 1 ] == pickupid )
|
||||
{
|
||||
if ( !( g_bribeData[ bribeid ] [ E_DISABLED ] == true || p_WantedLevel[ playerid ] <= 0 || IsPlayerCuffed( playerid ) || GetPlayerState( playerid ) == PLAYER_STATE_SPECTATING ) ) // || IsPlayerDetained( playerid )
|
||||
{
|
||||
new
|
||||
iWanted = 2;
|
||||
|
||||
// Play a sound so it matches the vehicle pickup
|
||||
if ( g_bribeData[ bribeid ] [ E_PICKUP ] [ 0 ] == pickupid )
|
||||
PlayerPlaySound( playerid, 1138, 0.0, 0.0, 5.0 );
|
||||
|
||||
// Expire the bribe
|
||||
g_bribeData[ bribeid ] [ E_TIMESTAMP ] = GetServerTime( ) + MAX_BRIBE_WAIT;
|
||||
g_bribeData[ bribeid ] [ E_DISABLED ] = true;
|
||||
UpdateDynamic3DTextLabelText( g_bribeData[ bribeid ] [ E_LABEL ], COLOR_GOLD, sprintf( "Bribe(%d)\n"COL_RED"Currently Expired!", bribeid ) );
|
||||
|
||||
// Remove a custom wanted level
|
||||
if ( p_WantedLevel[ playerid ] > 1800 ) iWanted = 128;
|
||||
else if ( p_WantedLevel[ playerid ] > 1000 ) iWanted = 64;
|
||||
else if ( p_WantedLevel[ playerid ] > 500 ) iWanted = 32;
|
||||
else if ( p_WantedLevel[ playerid ] > 250 ) iWanted = 16;
|
||||
else if ( p_WantedLevel[ playerid ] > 100 ) iWanted = 8;
|
||||
else if ( p_WantedLevel[ playerid ] > 50 ) iWanted = 4;
|
||||
|
||||
return GivePlayerWantedLevel( playerid, p_WantedLevel[ playerid ] <= 1 ? -1 : -iWanted );
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ** SQL Threads ** */
|
||||
thread OnBribeLoad( )
|
||||
{
|
||||
new
|
||||
rows, fields, i = -1,
|
||||
loadingTick = GetTickCount( )
|
||||
;
|
||||
|
||||
cache_get_data( rows, fields );
|
||||
if ( rows )
|
||||
{
|
||||
while( ++i < rows )
|
||||
{
|
||||
CreateBribe(
|
||||
cache_get_field_content_float( i, "X", dbHandle ),
|
||||
cache_get_field_content_float( i, "Y", dbHandle ),
|
||||
cache_get_field_content_float( i, "Z", dbHandle ),
|
||||
cache_get_field_content_int( i, "ID", dbHandle )
|
||||
);
|
||||
}
|
||||
}
|
||||
printf( "[BRIBES]: %d bribes have been loaded. (Tick: %dms)", i, GetTickCount( ) - loadingTick );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ** Functions ** */
|
||||
stock CreateBribe( Float: fX, Float: fY, Float: fZ, iExistingID = ITER_NONE )
|
||||
{
|
||||
new
|
||||
bID = iExistingID != ITER_NONE ? iExistingID : Iter_Free(BribeCount);
|
||||
|
||||
if ( Iter_Contains( BribeCount, iExistingID ) )
|
||||
bID = ITER_NONE; // In the unlikelihood...
|
||||
|
||||
if ( bID != -1 )
|
||||
{
|
||||
Iter_Add( BribeCount, bID );
|
||||
g_bribeData[ bID ] [ E_X ] = fX;
|
||||
g_bribeData[ bID ] [ E_Y ] = fY;
|
||||
g_bribeData[ bID ] [ E_Z ] = fZ;
|
||||
g_bribeData[ bID ] [ E_PICKUP ] [ 0 ] = CreateDynamicPickup( 1247, 15, fX, fY, fZ );
|
||||
g_bribeData[ bID ] [ E_PICKUP ] [ 1 ] = CreateDynamicPickup( 19300, 14, fX, fY, fZ );
|
||||
g_bribeData[ bID ] [ E_LABEL ] = CreateDynamic3DTextLabel( sprintf( "Bribe(%d)", bID ), COLOR_GOLD, fX, fY, fZ, 15.0 );
|
||||
|
||||
if ( iExistingID == ITER_NONE ) {
|
||||
mysql_single_query( sprintf( "INSERT INTO `BRIBES` VALUES (%d,%f,%f,%f)", bID, fX, fY, fZ ) );
|
||||
}
|
||||
}
|
||||
return bID;
|
||||
}
|
||||
|
||||
stock DestroyBribe( bID )
|
||||
{
|
||||
if ( bID == -1 || ! Iter_Contains( BribeCount, bID ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Iter_Remove( BribeCount, bID );
|
||||
DestroyDynamic3DTextLabel( g_bribeData[ bID ] [ E_LABEL ] );
|
||||
DestroyDynamicPickup( g_bribeData[ bID ] [ E_PICKUP ] [ 0 ] );
|
||||
DestroyDynamicPickup( g_bribeData[ bID ] [ E_PICKUP ] [ 1 ] );
|
||||
mysql_single_query( sprintf( "DELETE FROM `BRIBES` WHERE `ID`=%d", bID ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
stock Bribe_IsValid( bribeid ) {
|
||||
return ( 0 <= bribeid < MAX_BRIBES ) && Iter_Contains( BribeCount, bribeid );
|
||||
}
|
@ -127,24 +127,6 @@ new stock
|
||||
DCC_Role: discordRoleVoice
|
||||
;
|
||||
|
||||
/* ** Bribe Data ** */
|
||||
#define MAX_BRIBES ( 200 )
|
||||
#define MAX_BRIBE_WAIT ( 300000 )
|
||||
|
||||
enum E_BRIBE_DATA
|
||||
{
|
||||
bool: E_DISABLED, E_PICKUP[ 2 ], Text3D: E_LABEL,
|
||||
Float: E_X, Float: E_Y, Float: E_Z,
|
||||
E_TIMESTAMP
|
||||
};
|
||||
|
||||
new
|
||||
g_bribeData [ MAX_BRIBES ] [ E_BRIBE_DATA ],
|
||||
|
||||
// Iterator
|
||||
Iterator:BribeCount< MAX_BRIBES >
|
||||
;
|
||||
|
||||
/* ** Gate System ** */
|
||||
#define MAX_GATES ( 300 )
|
||||
|
||||
@ -1028,7 +1010,7 @@ public OnGameModeInit()
|
||||
#endif
|
||||
|
||||
// mysql_function_query( dbHandle, "SELECT * FROM `HOUSES`", true, "OnHouseLoad", "" );
|
||||
mysql_function_query( dbHandle, "SELECT * FROM `BRIBES`", true, "OnBribeLoad", "" );
|
||||
// mysql_function_query( dbHandle, "SELECT * FROM `BRIBES`", true, "OnBribeLoad", "" );
|
||||
mysql_function_query( dbHandle, "SELECT * FROM `APARTMENTS`", true, "OnApartmentLoad", "" );
|
||||
// mysql_function_query( dbHandle, "SELECT * FROM `FURNITURE`", true, "OnFurnitureLoad", "" );
|
||||
mysql_function_query( dbHandle, "SELECT * FROM `GATES`", true, "OnGatesLoad", "" );
|
||||
@ -1685,10 +1667,6 @@ public OnServerUpdateTimer( )
|
||||
ClearInactiveWeaponDrops( g_iTime );
|
||||
#endif
|
||||
|
||||
// Replenish Bribes
|
||||
foreach(new bribeid : BribeCount) if ( ( GetTickCount( ) - g_bribeData[ bribeid ] [ E_TIMESTAMP ] ) > MAX_BRIBE_WAIT && g_bribeData[ bribeid ] [ E_DISABLED ] == true )
|
||||
UpdateDynamic3DTextLabelText( g_bribeData[ bribeid ] [ E_LABEL ], COLOR_GOLD, sprintf( "Bribe(%d)", bribeid ) ), g_bribeData[ bribeid ] [ E_DISABLED ] = false;
|
||||
|
||||
// Replenish Atms
|
||||
foreach ( new i : atms ) if ( g_atmData[ i ] [ E_DISABLED ] && g_iTime > g_atmData[ i ] [ E_TIMESTAMP ] ) {
|
||||
UpdateDynamic3DTextLabelText( g_atmData[ i ] [ E_LABEL ], COLOR_GOLD, "[ATM]\n"COL_GREY"100%" );
|
||||
@ -10264,34 +10242,6 @@ public OnPlayerPickUpDynamicPickup( playerid, pickupid )
|
||||
}
|
||||
}
|
||||
|
||||
// Bribes
|
||||
foreach(new bribeid : BribeCount) if ( g_bribeData[ bribeid ] [ E_PICKUP ] [ 0 ] == pickupid || g_bribeData[ bribeid ] [ E_PICKUP ] [ 1 ] == pickupid )
|
||||
{
|
||||
if ( !( g_bribeData[ bribeid ] [ E_DISABLED ] == true || p_WantedLevel[ playerid ] <= 0 || IsPlayerCuffed( playerid ) || GetPlayerState( playerid ) == PLAYER_STATE_SPECTATING ) ) // || IsPlayerDetained( playerid )
|
||||
{
|
||||
new
|
||||
iWanted = 2;
|
||||
|
||||
// Play a sound so it matches the vehicle pickup
|
||||
if ( g_bribeData[ bribeid ] [ E_PICKUP ] [ 0 ] == pickupid )
|
||||
PlayerPlaySound( playerid, 1138, 0.0, 0.0, 5.0 );
|
||||
|
||||
// Expire the bribe
|
||||
g_bribeData[ bribeid ] [ E_TIMESTAMP ] = GetTickCount( );
|
||||
g_bribeData[ bribeid ] [ E_DISABLED ] = true;
|
||||
UpdateDynamic3DTextLabelText( g_bribeData[ bribeid ] [ E_LABEL ], COLOR_GOLD, sprintf( "Bribe(%d)\n"COL_RED"Currently Expired!", bribeid ) );
|
||||
|
||||
// Remove a custom wanted level
|
||||
if ( p_WantedLevel[ playerid ] > 1800 ) iWanted = 128;
|
||||
else if ( p_WantedLevel[ playerid ] > 1000 ) iWanted = 64;
|
||||
else if ( p_WantedLevel[ playerid ] > 500 ) iWanted = 32;
|
||||
else if ( p_WantedLevel[ playerid ] > 250 ) iWanted = 16;
|
||||
else if ( p_WantedLevel[ playerid ] > 100 ) iWanted = 8;
|
||||
else if ( p_WantedLevel[ playerid ] > 50 ) iWanted = 4;
|
||||
|
||||
return GivePlayerWantedLevel( playerid, p_WantedLevel[ playerid ] <= 1 ? -1 : -iWanted );
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -15027,72 +14977,6 @@ stock IsPlayerFireman( playerid )
|
||||
return false;
|
||||
}
|
||||
|
||||
stock CreateBribe( Float: fX, Float: fY, Float: fZ, iExistingID = ITER_NONE )
|
||||
{
|
||||
new
|
||||
bID = iExistingID != ITER_NONE ? iExistingID : Iter_Free(BribeCount);
|
||||
|
||||
if ( Iter_Contains( BribeCount, iExistingID ) )
|
||||
bID = ITER_NONE; // In the unlikelihood...
|
||||
|
||||
if ( bID != -1 )
|
||||
{
|
||||
Iter_Add(BribeCount, bID);
|
||||
g_bribeData[ bID ] [ E_X ] = fX;
|
||||
g_bribeData[ bID ] [ E_Y ] = fY;
|
||||
g_bribeData[ bID ] [ E_Z ] = fZ;
|
||||
g_bribeData[ bID ] [ E_PICKUP ] [ 0 ] = CreateDynamicPickup( 1247, 15, fX, fY, fZ );
|
||||
g_bribeData[ bID ] [ E_PICKUP ] [ 1 ] = CreateDynamicPickup( 19300, 14, fX, fY, fZ );
|
||||
g_bribeData[ bID ] [ E_LABEL ] = CreateDynamic3DTextLabel( sprintf( "Bribe(%d)", bID ), COLOR_GOLD, fX, fY, fZ, 15.0 );
|
||||
|
||||
if ( iExistingID == ITER_NONE )
|
||||
mysql_single_query( sprintf( "INSERT INTO `BRIBES` VALUES (%d,%f,%f,%f)", bID, fX, fY, fZ ) );
|
||||
}
|
||||
return bID;
|
||||
}
|
||||
|
||||
stock DestroyBribe( bID )
|
||||
{
|
||||
if ( bID == -1 || !Iter_Contains( BribeCount, bID ) )
|
||||
return 0;
|
||||
|
||||
new
|
||||
query[ 40 ]
|
||||
;
|
||||
Iter_Remove(BribeCount, bID);
|
||||
DestroyDynamic3DTextLabel( g_bribeData[ bID ] [ E_LABEL ] );
|
||||
DestroyDynamicPickup( g_bribeData[ bID ] [ E_PICKUP ] [ 0 ] );
|
||||
DestroyDynamicPickup( g_bribeData[ bID ] [ E_PICKUP ] [ 1 ] );
|
||||
g_bribeData[ bID ] [ E_TIMESTAMP ] = -1;
|
||||
format( query, sizeof( query ), "DELETE FROM `BRIBES` WHERE `ID`=%d", bID );
|
||||
mysql_single_query( query );
|
||||
return 1;
|
||||
}
|
||||
|
||||
thread OnBribeLoad( )
|
||||
{
|
||||
new
|
||||
rows, fields, i = -1,
|
||||
loadingTick = GetTickCount( )
|
||||
;
|
||||
|
||||
cache_get_data( rows, fields );
|
||||
if ( rows )
|
||||
{
|
||||
while( ++i < rows )
|
||||
{
|
||||
CreateBribe(
|
||||
cache_get_field_content_float( i, "X", dbHandle ),
|
||||
cache_get_field_content_float( i, "Y", dbHandle ),
|
||||
cache_get_field_content_float( i, "Z", dbHandle ),
|
||||
cache_get_field_content_int( i, "ID", dbHandle )
|
||||
);
|
||||
}
|
||||
}
|
||||
printf( "[BRIBES]: %d bribes have been loaded. (Tick: %dms)", i, GetTickCount( ) - loadingTick );
|
||||
return 1;
|
||||
}
|
||||
|
||||
stock PutPlayerInEmptyVehicleSeat( vehicleid, playerid )
|
||||
{
|
||||
new
|
||||
|
Loading…
Reference in New Issue
Block a user