From 08474974bf387a5988c0c3ac0163f7fb3282d63b Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Mon, 15 Oct 2018 15:19:36 +1100 Subject: [PATCH] wanted level in module and hooked functions (completely server sided). You can use GetPlayerWantedLevel, SetPlayerWantedLevel or GivePlayerWantedLevel --- gamemodes/irresistible/cnr/_cnr.pwn | 1 + gamemodes/irresistible/cnr/player.pwn | 1 - gamemodes/irresistible/cnr/wanted_level.pwn | 111 ++++++++++++++++++++ gamemodes/sf-cnr.pwn | 80 ++------------ 4 files changed, 119 insertions(+), 74 deletions(-) create mode 100644 gamemodes/irresistible/cnr/wanted_level.pwn diff --git a/gamemodes/irresistible/cnr/_cnr.pwn b/gamemodes/irresistible/cnr/_cnr.pwn index d3269d1..55270e7 100644 --- a/gamemodes/irresistible/cnr/_cnr.pwn +++ b/gamemodes/irresistible/cnr/_cnr.pwn @@ -17,6 +17,7 @@ #include "irresistible\cnr\dialog_ids.pwn" #include "irresistible\cnr\entrances.pwn" #include "irresistible\cnr\checkpoints.pwn" +#include "irresistible\cnr\wanted_level.pwn" // reliant on core definitions #include "irresistible\cnr\vip\_vip.pwn" diff --git a/gamemodes/irresistible/cnr/player.pwn b/gamemodes/irresistible/cnr/player.pwn index 22da95f..6642329 100644 --- a/gamemodes/irresistible/cnr/player.pwn +++ b/gamemodes/irresistible/cnr/player.pwn @@ -28,7 +28,6 @@ new p_AdminJailed [ MAX_PLAYERS char ], p_JailTimer [ MAX_PLAYERS ], bool: p_Jailed [ MAX_PLAYERS char ], - p_WantedLevel [ MAX_PLAYERS ], bool: p_Tazed [ MAX_PLAYERS char ], p_LastVehicle [ MAX_PLAYERS ] = { INVALID_VEHICLE_ID, ... }, bool: p_Cuffed [ MAX_PLAYERS char ], diff --git a/gamemodes/irresistible/cnr/wanted_level.pwn b/gamemodes/irresistible/cnr/wanted_level.pwn new file mode 100644 index 0000000..51e10a6 --- /dev/null +++ b/gamemodes/irresistible/cnr/wanted_level.pwn @@ -0,0 +1,111 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc Pekaj + * Module: + * Purpose: + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Definitions ** */ + +/* ** Variables ** */ +new + p_WantedLevel [ MAX_PLAYERS ]; + +/* ** Hooks ** */ +hook OnPlayerConnect( playerid ) +{ + ClearPlayerWantedLevel( playerid ); + return 1; +} + +#if defined AC_INCLUDED +hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart ) +#else +hook OnPlayerDeath( playerid, killerid, reason ) +#endif +{ + ClearPlayerWantedLevel( playerid ); + return 1; +} + +/* ** Hooked Functions ** */ +stock CNR_GetPlayerWantedLevel( playerid ) +{ + return p_WantedLevel[ playerid ]; // force the variable +} + +#if defined _ALS_GetPlayerWantedLevel + #undef GetPlayerWantedLevel +#else + #define _ALS_GetPlayerWantedLevel +#endif + +#define GetPlayerWantedLevel CNR_GetPlayerWantedLevel + +stock CNR_SetPlayerWantedLevel( playerid, level ) +{ + if ( ( p_WantedLevel[ playerid ] = level ) < 0 ) // prevent negative wanted level + p_WantedLevel[ playerid ] = 0; + + if ( p_WantedLevel[ playerid ] > 0 ) + { + if ( IsPlayerSpawned( playerid ) ) + { + PlayerTextDrawSetString( playerid, p_WantedLevelTD[ playerid ], sprintf( "] %d ]", p_WantedLevel[ playerid ] ) ); + if ( ! IsPlayerMovieMode( playerid ) ) PlayerTextDrawShow( playerid, p_WantedLevelTD[ playerid ] ); + ResetPlayerPassiveMode( playerid, .passive_disabled = true ); // remove passive mode if the player is wanted + } + } + else + { + PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ); + Uncuff( playerid ); // player is not wanted, so auto uncuff + } + + // regulate player color + SetPlayerColorToTeam( playerid ); + + /*if ( p_WantedLevel[ playerid ] > 2000 ) { // 8hska7082bmahu + p_WantedLevel[ playerid ] = 2000; + SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[WANTED LEVEL]{FFFFFF} Your wanted level has reached its maximum. Further wanted levels will not append.", wantedlevel, p_WantedLevel[ playerid ] ); + + format( szBigString, 256, "[0xA1] %s(%d) :: %d :: %d\r\n", ReturnPlayerName( playerid ), playerid, p_WantedLevel[ playerid ], g_iTime ); + AddFileLogLine( "security.txt", szBigString ); + return 1; + }*/ + + // set it to the variable value + return SetPlayerWantedLevel( playerid, p_WantedLevel[ playerid ] ); +} + +#if defined _ALS_SetPlayerWantedLevel + #undef SetPlayerWantedLevel +#else + #define _ALS_SetPlayerWantedLevel +#endif + +#define SetPlayerWantedLevel CNR_SetPlayerWantedLevel + +/* ** Functions ** */ +stock GivePlayerWantedLevel( playerid, level ) +{ + if ( ! IsPlayerConnected( playerid ) || IsPlayerNPC( playerid ) || IsPlayerJailed( playerid ) || level == 0 ) + return 0; + + new + current_wanted = GetPlayerWantedLevel( playerid ); + + SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[CRIME]{FFFFFF} Your wanted level has been %s by %d! Wanted level: %d", current_wanted + level > current_wanted ? ( "increased" ) : ( "decreased" ), level < 0 ? level * -1 : level, current_wanted ); + return SetPlayerWantedLevel( playerid, current_wanted + level ); +} + +stock ClearPlayerWantedLevel( playerid ) +{ + PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ); + p_WantedLevel[ playerid ] = 0; + SetPlayerWantedLevel( playerid, 0 ); + SetPlayerColorToTeam( playerid ); +} diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 72daabc..636673f 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -1901,7 +1901,6 @@ public OnPlayerConnect( playerid ) mysql_function_query( dbHandle, Query, true, "OnPlayerBanCheck", "i", playerid ); TogglePlayerClock( playerid, 1 ); - ClearPlayerWantedLevel( playerid ); SetPlayerColor( playerid, COLOR_GREY ); ResetPlayerCash( playerid ); @@ -2260,7 +2259,6 @@ public OnPlayerDisconnect( playerid, reason ) DestroyDynamicRaceCP( p_MiningExport[ playerid ] ); p_MiningExport[ playerid ] = 0xFFFF; p_ContractedAmount[ playerid ] = 0; - ClearPlayerWantedLevel( playerid ); Delete3DTextLabel( p_InfoLabel[ playerid ] ); p_InfoLabel[ playerid ] = Text3D: INVALID_3DTEXT_ID; p_LabelColor[ playerid ] = COLOR_GREY; @@ -2412,12 +2410,12 @@ public OnPlayerSpawn( playerid ) // Show welcome messsage ShowPlayerHelpDialog( playerid, 10000, "Welcome %s!~n~~n~If you have any questions, ~g~/ask!~w~~h~~n~~n~If you see anyone being unfair, report them with ~r~/report!~w~~n~~n~Have fun playing and don't forget to invite your friends! :)", ReturnPlayerName( playerid ) ); } - else + /*else { // Reset wanted level when a player spawns if ( p_LastPlayerState{ playerid } != PLAYER_STATE_SPECTATING ) ClearPlayerWantedLevel( playerid ); - } + }*/ if ( p_Jailed{ playerid } ) // Because some people can still exit the jail and play... return SetPlayerHealth( playerid, INVALID_PLAYER_ID ), SetPlayerPosToPrison( playerid ); @@ -3253,8 +3251,6 @@ public OnPlayerDeath( playerid, killerid, reason ) p_Deaths[ playerid ] ++; // Usually other events do nothing GivePlayerSeasonalXP( playerid, -10.0 ); // Deduct points, it's meant to be hard!!! } - - ClearPlayerWantedLevel( playerid ); return 1; } @@ -8916,7 +8912,6 @@ public OnPlayerStateChange(playerid, newstate, oldstate) p_LastPlayerState{ playerid } = oldstate; - if ( oldstate == PLAYER_STATE_SPECTATING ) { ResetPlayerWeapons( playerid ); @@ -10131,7 +10126,11 @@ thread OnAttemptPlayerLogin( playerid, password[ ] ) SetPlayerCash ( playerid, iCash ); SetPlayerScore ( playerid, iScore ); SetPlayerFightingStyle ( playerid, iFightStyle ); - GivePlayerWantedLevel ( playerid, iWanted, true ); + + if ( iWanted ) { + SetPlayerWantedLevel( playerid, iWanted ); + SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[RESUME]{FFFFFF} Your wanted level has been set to %d as you are resuming your life.", GetPlayerWantedLevel( playerid ) ); + } p_AdminLevel[ playerid ] = cache_get_field_content_int( 0, "ADMINLEVEL", dbHandle ); p_BankMoney[ playerid ] = cache_get_field_content_int( 0, "BANKMONEY", dbHandle ); @@ -13556,71 +13555,6 @@ stock IsPlayerInPoliceCar( playerid ) return false; } -stock GivePlayerWantedLevel( playerid, wantedlevel, bool:loadingstats = false ) -{ - static - szWanted[ 12 ]; - - if ( ! IsPlayerConnected( playerid ) || IsPlayerNPC( playerid ) ) - return 0; - - if ( IsPlayerJailed( playerid ) ) - { - SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[WANTED LEVEL]{FFFFFF} As you're jailed, wanted levels will not append.", wantedlevel, p_WantedLevel[ playerid ] ); - return 1; - } - - if ( wantedlevel == 0 ) - return 0; - - if ( ( p_WantedLevel[ playerid ] += wantedlevel ) < 0 ) - p_WantedLevel[ playerid ] = 0; // Negative wanted level? - - if ( ( wantedlevel < 0 && p_WantedLevel[ playerid ] < 6 ) || wantedlevel > 0 ) - SetPlayerWantedLevel( playerid, p_WantedLevel[ playerid ] ); - - if ( p_WantedLevel[ playerid ] > 0 ) - { - if ( IsPlayerSpawned( playerid ) ) - { - format( szWanted, sizeof( szWanted ), "] %d ]", p_WantedLevel[ playerid ] ); - PlayerTextDrawSetString( playerid, p_WantedLevelTD[ playerid ], szWanted ); - if ( ! p_inMovieMode{ playerid } ) PlayerTextDrawShow( playerid, p_WantedLevelTD[ playerid ] ); - ResetPlayerPassiveMode( playerid, .passive_disabled = true ); // remove passive mode if the player is wanted - } - } - else - { - PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ); - Uncuff( playerid ); - } - - // regulate player color - SetPlayerColorToTeam( playerid ); - - /*if ( p_WantedLevel[ playerid ] > 2000 ) // 8hska7082bmahu - { - p_WantedLevel[ playerid ] = 2000; - SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[WANTED LEVEL]{FFFFFF} Your wanted level has reached its maximum. Further wanted levels will not append.", wantedlevel, p_WantedLevel[ playerid ] ); - - format( szBigString, 256, "[0xA1] %s(%d) :: %d :: %d\r\n", ReturnPlayerName( playerid ), playerid, p_WantedLevel[ playerid ], g_iTime ); - AddFileLogLine( "security.txt", szBigString ); - return 1; - }*/ - - if ( !loadingstats ) SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[CRIME]{FFFFFF} Your wanted level has been modified by %d! Wanted level: %d", wantedlevel, p_WantedLevel[ playerid ] ); - else SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[RESUME]{FFFFFF} Your wanted level has been set to %d as you are resuming your life.", p_WantedLevel[ playerid ] ); - return 1; -} - -stock ClearPlayerWantedLevel( playerid ) -{ - PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ); - p_WantedLevel[ playerid ] = 0; - SetPlayerWantedLevel( playerid, 0 ); - SetPlayerColorToTeam( playerid ); -} - stock IsWeaponBanned( weaponid ) { return 0 <= weaponid < MAX_WEAPONS && ( weaponid == 36 || weaponid == 37 || weaponid == 38 || weaponid == 39 || weaponid == 44 || weaponid == 45 ); }