From be16355bee3f062800862409247a74f3a9c4a9d3 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Wed, 10 Oct 2018 12:00:29 +1100 Subject: [PATCH] make hide from radar last one minute --- gamemodes/irresistible/cnr/features/perks.pwn | 110 +++++++++++++----- gamemodes/irresistible/cnr/player.pwn | 4 +- gamemodes/sf-cnr.pwn | 63 +++++----- 3 files changed, 113 insertions(+), 64 deletions(-) diff --git a/gamemodes/irresistible/cnr/features/perks.pwn b/gamemodes/irresistible/cnr/features/perks.pwn index bf1adb6..1d1c4d1 100644 --- a/gamemodes/irresistible/cnr/features/perks.pwn +++ b/gamemodes/irresistible/cnr/features/perks.pwn @@ -8,14 +8,66 @@ /* ** Includes ** */ #include < YSI\y_hooks > +/* ** Variables ** */ +static stock + bool: p_OffRadar [ MAX_PLAYERS char ], + p_OffRadarTimestamp [ MAX_PLAYERS ], + p_OffRadarVisible [ MAX_PLAYERS ] +; + /* ** Hooks ** */ +hook OnPlayerDisconnect( playerid, reason ) +{ + p_OffRadar{ playerid } = false; + return 1; +} + +hook OnPlayerSpawn( playerid ) +{ + p_OffRadar{ playerid } = false; + return 1; +} + +hook OnPlayerUpdateEx( playerid ) +{ + if ( IsPlayerHiddenFromRadar( playerid ) ) + { + new + current_time = GetServerTime( ); + + // Expire stealth mode after 30 seconds + if ( p_OffRadarTimestamp[ playerid ] != 0 && current_time > p_OffRadarTimestamp[ playerid ] ) { + p_OffRadar{ playerid } = false; + SetPlayerColorToTeam( playerid ); + SendServerMessage( playerid, "Your hide from radar perk has now expired." ); + } + + // Stealth mode after getting shot + else if ( p_OffRadarVisible[ playerid ] != 0 && current_time > p_OffRadarVisible[ playerid ] ) { + SetPlayerColorToTeam( playerid ), p_OffRadarVisible[ playerid ] = 0; + } + } + return 1; +} + +hook OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float: fX, Float: fY, Float: fZ ) +{ + if ( hittype == BULLET_HIT_TYPE_PLAYER ) { + // Exposing stealth mode player + if ( IsPlayerHiddenFromRadar( playerid ) ) { + SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0xFF ) ), p_OffRadarVisible[ playerid ] = g_iTime + 2; + } + } + return 1; +} + hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { if ( dialogid == DIALOG_PERKS && response ) { switch( listitem ) { - case 0: ShowPlayerDialog( playerid, DIALOG_PERKS_P, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Game Perks", ""COL_WHITE"Item Name\t"COL_WHITE"Total Level Req.\t"COL_WHITE"Cost ($)\nUnlimited Ammunition\t"COL_GOLD"50\t"COL_GREEN"$9,900\nStealth Mode\t"COL_GOLD"75\t"COL_GREEN"$15,000", "Select", "Back" ); + case 0: ShowPlayerDialog( playerid, DIALOG_PERKS_P, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Game Perks", ""COL_WHITE"Item Name\t"COL_WHITE"Total Level Req.\t"COL_WHITE"Cost ($)\nHide From Radar\t"COL_GOLD"75\t"COL_GREEN"$25,000\nUnlimited Ammunition\t"COL_GOLD"50\t"COL_GREEN"$9,900", "Select", "Back" ); case 1: ShowPlayerDialog( playerid, DIALOG_PERKS_V, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Game Perks", ""COL_WHITE"Item Name\t"COL_WHITE"Total Level Req.\t"COL_WHITE"Cost ($)\nFix & Flip vehicle\t"COL_GOLD"75\t"COL_GREEN"$9,900\nRepair Vehicle\t"COL_GOLD"75\t"COL_GREEN"$7,500\nAdd NOS\t"COL_GOLD"50\t"COL_GREEN"$3,000\nFlip vehicle\t"COL_GOLD"40\t"COL_GREEN"$2,500", "Select", "Back" ); } } @@ -30,6 +82,32 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) switch( listitem ) { case 0: + { + if ( total_level < 75 ) { + return SendError( playerid, "Your total level must be at least 75 to use this (/level)." ); + } + + if ( GetPlayerCash( playerid ) < 25000 ) { + return SendError( playerid, "You do not have enough money for this item ($25,000)." ); + } + + if ( GetPlayerClass( playerid ) != CLASS_CIVILIAN ) { + return SendError( playerid, "You need to be a civilian to use this perk." ); + } + + p_OffRadar{ playerid } = true; + p_OffRadarTimestamp[ playerid ] = GetServerTime( ) + 60; + + GivePlayerCash( playerid, -25000 ); + + SendServerMessage( playerid, "You have hidden yourself from the radar (1 minute) for $25,000." ); + ShowPlayerHelpDialog( playerid, 3000, "~g~~h~Hide from radar ~w~will be deactivate in 1 minute." ); + + SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0x00 ) ); + Beep( playerid ); + } + + case 1: { if ( total_level < 50 ) { return SendError( playerid, "Your total level must be at least 50 to use this (/level)." ); @@ -52,31 +130,6 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) SetPlayerArmedWeapon( playerid, 0 ); Beep( playerid ); } - - case 1: - { - if ( total_level < 75 ) { - return SendError( playerid, "Your total level must be at least 75 to use this (/level)." ); - } - - if ( GetPlayerCash( playerid ) < 11500 ) { - return SendError( playerid, "You do not have enough money for this item ($11,500)." ); - } - - if ( p_OffRadar{ playerid } ) { - return SendError( playerid, "You have already purchased this item." ); - } - - p_OffRadar{ playerid } = true; - - GivePlayerCash( playerid, -11500 ); - - SendServerMessage( playerid, "You have brought stealth mode for $15,000." ); - ShowPlayerHelpDialog( playerid, 3000, "~g~~h~Stealth mode ~w~will be deactivate once you respawn." ); - - SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0x00 ) ); - Beep( playerid ); - } } } else if ( dialogid == DIALOG_PERKS_V ) @@ -171,3 +224,8 @@ CMD:perks( playerid, params[ ] ) } return ShowPlayerDialog( playerid, DIALOG_PERKS, DIALOG_STYLE_LIST, "{FFFFFF}Game Perks", "Player Perks\nVehicle Perks", "Select", "Cancel" ); } + +/* ** Functions ** */ +stock IsPlayerHiddenFromRadar( playerid ) { + return p_OffRadar{ playerid }; +} diff --git a/gamemodes/irresistible/cnr/player.pwn b/gamemodes/irresistible/cnr/player.pwn index ea5e718..f99c91c 100644 --- a/gamemodes/irresistible/cnr/player.pwn +++ b/gamemodes/irresistible/cnr/player.pwn @@ -205,7 +205,6 @@ new p_LastPlayerState [ MAX_PLAYERS char ], p_RespondDelay [ MAX_PLAYERS ], p_VisibleOnRadar [ MAX_PLAYERS ], - p_OffRadarVisible [ MAX_PLAYERS ], p_InGarage [ MAX_PLAYERS ] = { -1, ... }, p_WorkCooldown [ MAX_PLAYERS ], p_AntiSpammyTS [ MAX_PLAYERS ], @@ -240,8 +239,7 @@ new p_AimedAtPolice [ MAX_PLAYERS ], bool: p_PassiveModeDisabled [ MAX_PLAYERS char ], p_PassiveModeExpireTimer [ MAX_PLAYERS ] = { -1, ... }, - Text3D: p_PassiveModeLabel [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID }, - bool: p_OffRadar [ MAX_PLAYERS char ] + Text3D: p_PassiveModeLabel [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID } ; /* ** Getters And Setters** */ diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 1f3d2c6..ce157c8 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -2131,11 +2131,6 @@ public ZoneTimer( ) // CIA Visible On Radar after firing a shot if ( p_VisibleOnRadar[ playerid ] != 0 && p_VisibleOnRadar[ playerid ] < g_iTime ) SetPlayerColorToTeam( playerid ), p_VisibleOnRadar[ playerid ] = 0; - - // Stealth mode after getting shot - if ( p_OffRadarVisible[ playerid ] != 0 && p_OffRadarVisible[ playerid ] < g_iTime ) - SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0x00 ) ), p_OffRadarVisible[ playerid ] = 0; - } return 1; } @@ -2852,8 +2847,6 @@ public OnPlayerSpawn( playerid ) StopSound( playerid ); CancelEdit( playerid ); - p_OffRadar{ playerid } = false; - // Approved spawn? if ( !approveClassSpawned( playerid ) ) { SendClientMessageToAdmins( -1, ""COL_PINK"[ABNORMAL SPAWN]"COL_GREY" %s(%d) - %d skin - %d ping - %s IP", ReturnPlayerName( playerid ), playerid, GetPlayerSkin( playerid ), GetPlayerPing( playerid ), ReturnPlayerIP( playerid ) ); @@ -3089,10 +3082,6 @@ public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:f if ( p_Class[ playerid ] == CLASS_POLICE && p_Class[ hitid ] != CLASS_POLICE && !p_WantedLevel[ hitid ] && GetPlayerState( hitid ) != PLAYER_STATE_WASTED && ! IsPlayerInEvent( playerid ) ) return ShowPlayerHelpDialog( playerid, 2000, "You cannot hurt innocent civilians, you're a ~b~cop~w~~h~!" ), 0; - // Exposing stealth mode player - if ( p_OffRadar{ playerid } ) - SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0xFF ) ), p_OffRadarVisible[ playerid ] = g_iTime + 2; - // CIA Exposure when weapon is shot if ( p_Class[ playerid ] == CLASS_POLICE && p_inFBI{ playerid } && p_inCIA{ playerid } && !p_inArmy{ playerid } ) SetPlayerColor( playerid, setAlpha( COLOR_CIA, 0xFF ) ), p_VisibleOnRadar[ playerid ] = g_iTime + 2; @@ -11657,8 +11646,8 @@ thread OnAttemptPlayerLogin( playerid, password[ ] ) p_PingImmunity{ playerid } = cache_get_field_content_int( 0, "PING_IMMUNE", dbHandle ); p_HitsComplete[ playerid ] = cache_get_field_content_int( 0, "CONTRACTS", dbHandle ); p_TruckedCargo[ playerid ] = cache_get_field_content_int( 0, "TRUCKED", dbHandle ); - p_PilotMissions[ playerid ] = cache_get_field_content_int( 0, "PILOT", dbHandle ); - p_TrainMissions[ playerid ] = cache_get_field_content_int( 0, "TRAIN", dbHandle ); + p_PilotMissions[ playerid ] = cache_get_field_content_int( 0, "PILOT", dbHandle ); + p_TrainMissions[ playerid ] = cache_get_field_content_int( 0, "TRAIN", dbHandle ); //p_CopTutorial{ playerid } = cache_get_field_content_int( 0, "COP_TUTORIAL", dbHandle ); p_Job{ playerid } = cache_get_field_content_int( 0, "JOB", dbHandle ); p_VIPJob{ playerid } = cache_get_field_content_int( 0, "VIP_JOB", dbHandle ); @@ -15177,14 +15166,9 @@ stock GivePlayerWantedLevel( playerid, wantedlevel, bool:loadingstats = false ) static szWanted[ 12 ]; - if ( !IsPlayerConnected( playerid ) ) + if ( ! IsPlayerConnected( playerid ) || IsPlayerNPC( playerid ) ) return 0; -#if defined __cnr__chuffsec - if ( IsPlayerSecurityDriver( playerid ) ) - return SetPlayerColor( playerid, COLOR_SECURITY ); -#endif - if ( IsPlayerJailed( playerid ) ) { SendClientMessageFormatted( playerid, -1, ""COL_GOLD"[WANTED LEVEL]{FFFFFF} As you're jailed, wanted levels will not append.", wantedlevel, p_WantedLevel[ playerid ] ); @@ -15200,10 +15184,8 @@ stock GivePlayerWantedLevel( playerid, wantedlevel, bool:loadingstats = false ) if ( ( wantedlevel < 0 && p_WantedLevel[ playerid ] < 6 ) || wantedlevel > 0 ) SetPlayerWantedLevel( playerid, p_WantedLevel[ playerid ] ); - if ( p_WantedLevel[ playerid ] ) + if ( p_WantedLevel[ playerid ] > 0 ) { - SetPlayerColor( playerid, COLOR_WANTED2 ); - if ( IsPlayerSpawned( playerid ) ) { format( szWanted, sizeof( szWanted ), "] %d ]", p_WantedLevel[ playerid ] ); @@ -15212,14 +15194,14 @@ stock GivePlayerWantedLevel( playerid, wantedlevel, bool:loadingstats = false ) ResetPlayerPassiveMode( playerid, .passive_disabled = true ); // remove passive mode if the player is wanted } } - else SetPlayerColorToTeam( playerid ), PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ), Uncuff( playerid ); + else + { + PlayerTextDrawHide( playerid, p_WantedLevelTD[ playerid ] ); + Uncuff( playerid ); + } - if ( p_WantedLevel[ playerid ] > 5 ) SetPlayerColor( playerid, COLOR_WANTED6 ); - if ( p_WantedLevel[ playerid ] > 11 ) SetPlayerColor( playerid, COLOR_WANTED12 ); - if ( p_WantedLevel[ playerid ] > 90 ) printf( "[wanted_level] %s - %d", ReturnPlayerName( playerid ), p_WantedLevel[ playerid ] ); - if ( IsPlayerAdminOnDuty( playerid ) ) SetPlayerColor( playerid, COLOR_PINK ); - - if ( p_OffRadar{ playerid } ) SetPlayerColor( playerid, setAlpha( GetPlayerColor( playerid ), 0x00 ) ); + // regulate player color + SetPlayerColorToTeam( playerid ); /*if ( p_WantedLevel[ playerid ] > 2000 ) // 8hska7082bmahu { @@ -15424,14 +15406,25 @@ stock SetPlayerColorToTeam( playerid ) if ( p_inArmy{ playerid } ) SetPlayerColor( playerid, COLOR_ARMY ); } case CLASS_FIREMAN: SetPlayerColor( playerid, COLOR_FIREMAN ); - case CLASS_MEDIC: SetPlayerColor( playerid, COLOR_MEDIC ); + case CLASS_MEDIC: SetPlayerColor( playerid, COLOR_MEDIC ); default: { - SetPlayerColor( playerid, COLOR_DEFAULT ); - if ( p_GangID[ playerid ] != INVALID_GANG_ID ) SetPlayerColor( playerid, g_gangData[ p_GangID[ playerid ] ] [ E_COLOR ] ); - if ( p_WantedLevel[ playerid ] > 1 ) SetPlayerColor( playerid, COLOR_WANTED2 ); - if ( p_WantedLevel[ playerid ] > 5 ) SetPlayerColor( playerid, COLOR_WANTED6 ); - if ( p_WantedLevel[ playerid ] > 11 ) SetPlayerColor( playerid, COLOR_WANTED12 ); + new + default_color = COLOR_DEFAULT; + + // set color according to wanted level + if ( p_WantedLevel[ playerid ] > 11 ) default_color = COLOR_WANTED12; + else if ( p_WantedLevel[ playerid ] > 5 ) default_color = COLOR_WANTED6; + else if ( p_WantedLevel[ playerid ] > 1 ) default_color = COLOR_WANTED2; + else if ( p_GangID[ playerid ] != INVALID_GANG_ID ) default_color = g_gangData[ p_GangID[ playerid ] ] [ E_COLOR ]; + + // set alpha for invisible players to 0 + if ( IsPlayerHiddenFromRadar( playerid ) ) { + default_color = setAlpha( default_color, 0x00 ); + } + + // force the color on the player + return SetPlayerColor( playerid, default_color ); } } return 1;