From 395bd7c86f4598a14baa36f0800586aa60e5ff5c Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Mon, 3 Dec 2018 23:22:27 +1100 Subject: [PATCH] press F to pickup furniture --- gamemodes/irresistible/README.md | 2 + .../cnr/features/houses/burglar.pwn | 256 +++++++++--------- .../cnr/features/houses/house.pwn | 2 + gamemodes/sf-cnr.pwn | 17 +- 4 files changed, 140 insertions(+), 137 deletions(-) diff --git a/gamemodes/irresistible/README.md b/gamemodes/irresistible/README.md index 2595d84..0a47c0b 100644 --- a/gamemodes/irresistible/README.md +++ b/gamemodes/irresistible/README.md @@ -44,3 +44,5 @@ - Called when a player leaves a gang - `OnPlayerEnterHouse( playerid, houseid )` - Called when a player enters a house +- `OnPlayerAttemptBurglary( playerid, houseid, businessid )` + - Called when a player attempts to break into a business/house diff --git a/gamemodes/irresistible/cnr/features/houses/burglar.pwn b/gamemodes/irresistible/cnr/features/houses/burglar.pwn index 76474ab..a9304aa 100644 --- a/gamemodes/irresistible/cnr/features/houses/burglar.pwn +++ b/gamemodes/irresistible/cnr/features/houses/burglar.pwn @@ -42,8 +42,10 @@ hook OnPlayerDriveVehicle( playerid, vehicleid ) if ( model == 498 && p_Class[ playerid ] != CLASS_POLICE ) { - format( szSmallString, sizeof( szSmallString ), "vburg_%d_items", vehicleid ); - if ( GetGVarInt( szSmallString ) > 0 ) + new num_furniture = GetGVarInt( sprintf( "vburg_%d_items", vehicleid ) ); + new cash_value = GetGVarInt( sprintf( "vburg_%d_cash", vehicleid ) ); + + if ( num_furniture > 0 ) { new Float: X, Float: Y, Float: Z, @@ -53,7 +55,7 @@ hook OnPlayerDriveVehicle( playerid, vehicleid ) Beep( playerid ); GameTextForPlayer( playerid, "Go to the truck blip on your radar for money!", 3000, 1 ); - SendServerMessage( playerid, "Note! You have %d stolen goods that you can export for money!", GetGVarInt( szSmallString ) ); + SendServerMessage( playerid, "You have %d stolen goods that you can export for "COL_GOLD"%s"COL_WHITE"!", num_furniture, cash_format( cash_value ) ); static szCity[ MAX_ZONE_NAME ], @@ -94,12 +96,12 @@ hook OnPlayerStateChange( playerid, newstate, oldstate ) { if ( newstate != PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_DRIVER ) // Driver has a new state? { - if ( p_PawnStoreExport[ playerid ] != 0xFFFF ) + if ( p_PawnStoreExport[ playerid ] != -1 ) { DestroyDynamicMapIcon( p_PawnStoreMapIcon[ playerid ] ); - p_PawnStoreMapIcon[ playerid ] = 0xFFFF; + p_PawnStoreMapIcon[ playerid ] = -1; DestroyDynamicRaceCP( p_PawnStoreExport[ playerid ] ); - p_PawnStoreExport[ playerid ] = 0xFFFF; + p_PawnStoreExport[ playerid ] = -1; } } return 1; @@ -114,34 +116,21 @@ hook OnPlayerEnterDynRaceCP( playerid, checkpointid ) new vehicleid = GetPlayerVehicleID( playerid ); if ( GetVehicleModel( vehicleid ) == 498 ) { - new - szItems[ 18 ], - cashEarned, - items, score - ; - format( szItems, sizeof( szItems ), "vburg_%d_items", vehicleid ); - for( new i; i < GetGVarInt( szItems ) + 1; i++ ) - { - format( szSmallString, sizeof( szSmallString ), "vburg_%d_%d", vehicleid, i ); - if ( GetGVarInt( szSmallString ) != 0 ) - { - cashEarned += floatround( float( g_houseFurniture[ GetGVarInt( szSmallString ) ] [ E_COST ] ) * 0.5 ); - DeleteGVar( szSmallString ); - } - } - items = GetGVarInt( szItems ); - score = floatround( items / 2 ); + new cash_earned = GetGVarInt( sprintf( "vburg_%d_cash", vehicleid ) ); + new num_furniture = GetGVarInt( sprintf( "vburg_%d_items", vehicleid ) ); + new score = floatround( num_furniture / 2 ); + GivePlayerScore( playerid, score == 0 ? 1 : score ); - //GivePlayerExperience( playerid, E_BURGLAR, float( items ) * 0.2 ); + //GivePlayerExperience( playerid, E_BURGLAR, float( num_furniture ) * 0.2 ); DestroyDynamicMapIcon( p_PawnStoreMapIcon[ playerid ] ); - p_PawnStoreMapIcon[ playerid ] = 0xFFFF; + p_PawnStoreMapIcon[ playerid ] = -1; DestroyDynamicRaceCP( p_PawnStoreExport[ playerid ] ); - p_PawnStoreExport[ playerid ] = 0xFFFF; - GivePlayerCash( playerid, cashEarned ); - StockMarket_UpdateEarnings( E_STOCK_PAWN_STORE, cashEarned, 1.0 ); - GivePlayerWantedLevel( playerid, items * 2 ); - SendServerMessage( playerid, "You have sold %d furniture item(s) to the Pawn Store, earning you "COL_GOLD"%s"COL_WHITE".", GetGVarInt( szItems ), cash_format( cashEarned ) ); - DeleteGVar( szItems ); + p_PawnStoreExport[ playerid ] = -1; + GivePlayerCash( playerid, cash_earned ); + StockMarket_UpdateEarnings( E_STOCK_PAWN_STORE, cash_earned, 1.0 ); + GivePlayerWantedLevel( playerid, num_furniture * 2 ); + SendServerMessage( playerid, "You have sold %d furniture item(s) to the Pawn Store, earning you "COL_GOLD"%s"COL_WHITE".", num_furniture, cash_format( cash_earned ) ); + ResetVehicleBurglaryData( vehicleid ); } } return 1; @@ -200,6 +189,54 @@ hook OnProgressCompleted( playerid, progressid, params ) return 1; } +hook OnPlayerEnterHouse( playerid, houseid ) +{ + // alert burglar of any furniture + if ( ! IsPlayerHomeOwner( playerid, houseid ) && IsPlayerJob( playerid, JOB_BURGLAR ) && GetPlayerClass( playerid ) == CLASS_CIVILIAN ) { + if ( Iter_Count( housefurniture[ houseid ] ) ) { + ShowPlayerHelpDialog( playerid, 4000, "This house has furniture to rob.~n~~n~Type ~g~~h~/burglar steal~w~ near the furniture you want to steal." ); + } else { + ShowPlayerHelpDialog( playerid, 4000, "~r~This house has no furniture to rob." ); + } + } + return 1; +} + +hook OnPlayerAttemptBurglary( playerid, houseid, businessid ) +{ + new current_time = GetServerTime( ); + new crackpw_cooldown = GetPVarInt( playerid, "crack_housepw_cool" ); + + if ( crackpw_cooldown > current_time ) { + return SendError( playerid, "You are unable to attempt a house break-in for %d seconds.", crackpw_cooldown - current_time ), 0; + } + + print("Attempt Breakin"); + + if ( IsValidHouse( houseid ) ) + { + if ( current_time > g_houseData[ houseid ] [ E_CRACKED_TS ] && g_houseData[ houseid ] [ E_CRACKED ] ) + g_houseData[ houseid ] [ E_CRACKED ] = false; // The Virus Is Disabled. + + if ( g_houseData[ houseid ] [ E_CRACKED_WAIT ] > current_time ) + return print("1"), SendError( playerid, "This house had its password recently had a cracker run through. Come back later." ), 0; + + if ( g_houseData[ houseid ] [ E_CRACKED ] || g_houseData[ houseid ] [ E_BEING_CRACKED ] ) + return print("2"), SendError( playerid, "This house is currently being cracked or is already cracked." ), 0; + + if ( IsHouseOnFire( houseid ) ) + return print("3"), SendError( playerid, "This house is on fire, you cannot crack it!" ), 0; + + print("Attempt Breakin2"); + g_houseData[ houseid ] [ E_BEING_CRACKED ] = true; + p_HouseCrackingPW[ playerid ] = houseid; + SetPVarInt( playerid, "crack_housepw_cool", current_time + 40 ); + ShowProgressBar( playerid, "Cracking Password", PROGRESS_CRACKING, 7500, COLOR_WHITE ); + return 1; + } + return 1; +} + hook OnVehicleCreated( vehicleid, model_id ) { if ( model_id == 498 ) @@ -248,34 +285,88 @@ hook OnPlayerEnterDynArea( playerid, areaid ) return SendError( playerid, "You aren't holding anything!" ); } - format( szSmallString, sizeof( szSmallString ), "vburg_%d_items", attached_vehicle ); + new stolen_furniture_count = GetGVarInt( sprintf( "vburg_%d_items", attached_vehicle ) ); - if ( GetGVarInt( szSmallString ) >= MAX_BURGLARY_SLOTS ) { + if ( stolen_furniture_count >= MAX_BURGLARY_SLOTS ) { return SendError( playerid, "You can only carry %d items in this vehicle.", MAX_BURGLARY_SLOTS ); } - new + static Float: angle; GetVehicleZAngle( attached_vehicle, angle ); - SetGVarInt( szSmallString, GetGVarInt( szSmallString ) + 1 ); - SetGVarInt( sprintf( "vburg_%d_%d", attached_vehicle, GetGVarInt( szSmallString ) ), GetPVarInt( playerid, "stolen_fid" ) ); + new stolen_furniture_id = GetPVarInt( playerid, "stolen_fid" ); + new stolen_furniture_value = floatround( float( g_houseFurniture[ stolen_furniture_id ] [ E_COST ] ) * 0.5 ); + new stolen_cash_accumulative = GetGVarInt( sprintf( "vburg_%d_cash", attached_vehicle ) ); + + SetGVarInt( sprintf( "vburg_%d_items", attached_vehicle ), stolen_furniture_count + 1 ); + SetGVarInt( sprintf( "vburg_%d_cash", attached_vehicle ), stolen_cash_accumulative + stolen_furniture_value ); RemovePlayerAttachedObject( playerid, 3 ); ClearAnimations( playerid ); SetPlayerSpecialAction( playerid, SPECIAL_ACTION_NONE ); - DeletePVar( playerid, "stolen_fid" ); SetPlayerFacingAngle( playerid, angle ); - SendServerMessage( playerid, "You have placed a "COL_GREY"%s"COL_WHITE" in this Boxville. "COL_ORANGE"[%d/%d]", g_houseFurniture[ GetPVarInt( playerid, "stolen_fid" ) ] [ E_NAME ], GetGVarInt( szSmallString ), MAX_BURGLARY_SLOTS ); + SendServerMessage( playerid, "You have placed a "COL_GREY"%s"COL_WHITE" in this Boxville. "COL_ORANGE"[%d/%d]", g_houseFurniture[ stolen_furniture_id ] [ E_NAME ], stolen_furniture_count + 1, MAX_BURGLARY_SLOTS ); + ApplyAnimation( playerid, "CARRY", "putdwn105", 4.0, 0, 0, 0, 0, 0 ); + DeletePVar( playerid, "stolen_fid" ); return 1; } } return 1; } +hook OnPlayerKeyStateChange( playerid, newkeys, oldkeys ) +{ + if ( PRESSED( KEY_SECONDARY_ATTACK ) && IsPlayerJob( playerid, JOB_BURGLAR ) && GetPlayerClass( playerid ) == CLASS_CIVILIAN ) + { + new + houseid = GetPlayerEnteredHouse( playerid ); + + if ( IsValidHouse( houseid ) && ! IsPlayerHomeOwner( playerid, houseid ) ) + { + new Float: distance = 99999.99, furniture_slot = ITER_NONE; + new objectid = GetClosestFurniture( houseid, playerid, distance, furniture_slot ); + new modelid = Streamer_GetIntData( STREAMER_TYPE_OBJECT, objectid, E_STREAMER_MODEL_ID ); + new furniture_id = getFurnitureID( modelid ); + + if ( objectid == INVALID_OBJECT_ID || furniture_slot == ITER_NONE ) + return SendError( playerid, "No furniture is in this house." ); + + if ( distance > 3.0 ) + return SendError( playerid, "You are not close to any furniture." ); + + if ( g_houseFurniture[ furniture_id ] [ E_CATEGORY ] != FC_ELECTRONIC && g_houseFurniture[ furniture_id ] [ E_CATEGORY ] != FC_WEAPONS ) + return ShowPlayerHelpDialog( playerid, 3000, "The furniture you're near is not an electronic." ); + + if ( IsPlayerAttachedObjectSlotUsed( playerid, 3 ) ) + return ShowPlayerHelpDialog( playerid, 3000, "Your hands are busy at the moment." ); + + if ( IsPointToPoint( 150.0, g_houseData[ houseid ] [ E_EX ], g_houseData[ houseid ] [ E_EY ], g_houseData[ houseid ] [ E_EZ ], -2480.1426, 5.5302, 25.6172 ) ) + return ShowPlayerHelpDialog( playerid, 3000, "~r~This house is protected from burglaries." ); + + new Float: playerZ, Float: furnitureZ; + GetPlayerPos( playerid, playerZ, playerZ, playerZ ); + GetDynamicObjectPos( objectid, furnitureZ, furnitureZ, furnitureZ ); + + // apply animation + if ( playerZ - furnitureZ <= 0.0 ) ApplyAnimation( playerid, "CARRY", "liftup105", 4.0, 0, 0, 0, 0, 0 ); + else if ( playerZ - furnitureZ <= 0.45 ) ApplyAnimation( playerid, "CARRY", "liftup05", 4.0, 0, 0, 0, 0, 0 ); + else ApplyAnimation( playerid, "CARRY", "liftup", 4.0, 0, 0, 0, 0, 0 ); + + // Alert + SendServerMessage( playerid, "You have stolen a "COL_GREY"%s"COL_WHITE". Store it in a Boxville to transport the item.", g_houseFurniture[ furniture_id ] [ E_NAME ] ); + SetPlayerSpecialAction( playerid, SPECIAL_ACTION_CARRY ); + SetPVarInt( playerid, "stolen_fid", furniture_id ); + SetPlayerAttachedObject( playerid, 3, 1220, 5, 0.043999, 0.222999, 0.207000, 14.400002, 15.799994, 0.000000, 0.572999, 0.662000, 0.665000 ); + } + + } + return 1; +} + /* ** Commands ** */ CMD:burglar( playerid, params[ ] ) { @@ -285,7 +376,6 @@ CMD:burglar( playerid, params[ ] ) if ( isnull( params ) ) return SendUsage( playerid, "/burglar [CRACKPW/STEAL/STORE]" ); else if ( strmatch( params, "crackpw" ) ) { - if ( GetPVarInt( playerid, "crackpw_cool" ) > g_iTime ) return SendError( playerid, "You must wait 40 seconds before using this command again." ); // businesses /*foreach ( new handle : business ) @@ -316,81 +406,6 @@ CMD:burglar( playerid, params[ ] ) return 1; } }*/ - - // houses - foreach ( new i : houses ) - { - if ( IsPlayerInDynamicCP( playerid, g_houseData[ i ] [ E_CHECKPOINT ] [ 0 ] ) && !strmatch( g_houseData[ i ] [ E_OWNER ], ReturnPlayerName( playerid ) ) ) - { - if ( g_iTime > g_houseData[ i ] [ E_CRACKED_TS ] && g_houseData[ i ] [ E_CRACKED ] ) g_houseData[ i ] [ E_CRACKED ] = false; // The Virus Is Disabled. - - if ( g_houseData[ i ] [ E_CRACKED_WAIT ] > g_iTime ) - return SendError( playerid, "This house had its password recently had a cracker run through. Come back later." ); - - if ( strmatch( g_houseData[ i ] [ E_PASSWORD ], "N/A" ) ) - return SendError( playerid, "This house does not require cracking as it doesn't have a password." ); - - if ( g_houseData[ i ] [ E_CRACKED ] || g_houseData[ i ] [ E_BEING_CRACKED ] ) - return SendError( playerid, "This house is currently being cracked or is already cracked." ); - - if ( IsHouseOnFire( i ) ) - return SendError( playerid, "This house is on fire, you cannot crack it!" ), 1; - - g_houseData[ i ] [ E_BEING_CRACKED ] = true; - p_HouseCrackingPW[ playerid ] = i; - SetPVarInt( playerid, "crackpw_cool", g_iTime + 40 ); - ShowProgressBar( playerid, "Cracking Password", PROGRESS_CRACKING, 7500, COLOR_WHITE ); - return 1; - } - } - - // businesses - SendError( playerid, "You are not standing in any house or business checkpoint." ); - } - else if ( strmatch( params, "steal" ) ) - { - new houseid = p_InHouse[ playerid ]; - - if ( houseid == -1 ) - return SendError( playerid, "You're not inside any house." ); - - if ( IsPlayerHomeOwner( playerid, houseid ) ) - return SendError( playerid, "You can't steal a piece of furniture from your house!" ); - - new Float: distance = 99999.99, furniture_slot = ITER_NONE; - new objectid = GetClosestFurniture( houseid, playerid, distance, furniture_slot ); - new modelid = Streamer_GetIntData( STREAMER_TYPE_OBJECT, objectid, E_STREAMER_MODEL_ID ); - new furniture_id = getFurnitureID( modelid ); - - if ( objectid == INVALID_OBJECT_ID || furniture_slot == ITER_NONE ) - return SendError( playerid, "No furniture is in this house." ); - - if ( distance > 3.0 ) - return SendError( playerid, "You are not close to any furniture." ); - - if ( g_houseFurniture[ furniture_id ] [ E_CATEGORY ] != FC_ELECTRONIC && g_houseFurniture[ furniture_id ] [ E_CATEGORY ] != FC_WEAPONS ) - return SendError( playerid, "The furniture you're near is not an electronic." ); - - if ( IsPlayerAttachedObjectSlotUsed( playerid, 3 ) ) - return SendError( playerid, "Your hands are busy at the moment." ); - - if ( IsPointToPoint( 150.0, g_houseData[ houseid ] [ E_EX ], g_houseData[ houseid ] [ E_EY ], g_houseData[ houseid ] [ E_EZ ], -2480.1426, 5.5302, 25.6172 ) ) - return SendError( playerid, "This house is prohibited from burglarly features as it is too close to the Pawn Store." ); - - new Float: playerZ, Float: furnitureZ; - GetPlayerPos( playerid, playerZ, playerZ, playerZ ); - GetDynamicObjectPos( objectid, furnitureZ, furnitureZ, furnitureZ ); - - // apply animation - if ( playerZ - furnitureZ <= 0.0 ) ApplyAnimation( playerid, "CARRY", "liftup105", 4.0, 0, 0, 0, 0, 0 ); - else if ( playerZ - furnitureZ <= 0.45 ) ApplyAnimation( playerid, "CARRY", "liftup05", 4.0, 0, 0, 0, 0, 0 ); - else ApplyAnimation( playerid, "CARRY", "liftup", 4.0, 0, 0, 0, 0, 0 ); - - // Alert - SendServerMessage( playerid, "You have stolen a "COL_GREY"%s"COL_WHITE". Store it in a Boxville to transport the item.", g_houseFurniture[ furniture_id ] [ E_NAME ] ); - SetPlayerSpecialAction( playerid, SPECIAL_ACTION_CARRY ); - SetPVarInt( playerid, "stolen_fid", furniture_id ); - SetPlayerAttachedObject( playerid, 3, 1220, 5, 0.043999, 0.222999, 0.207000, 14.400002, 15.799994, 0.000000, 0.572999, 0.662000, 0.665000 ); } else SendUsage( playerid, "/burglar [CRACKPW/STEAL]" ); return 1; @@ -436,17 +451,8 @@ CMD:bruteforce( playerid, params[ ] ) stock ResetVehicleBurglaryData( vehicleid ) { - if ( GetVehicleModel( vehicleid ) != 498 ) - return 0; - - new szString[ 18 ]; - - for( new i; i < MAX_BURGLARY_SLOTS; i++ ) { - format( szString, sizeof( szString ), "vburg_%d_%d", vehicleid, i ), DeleteGVar( szString ); - } - - format( szString, sizeof( szString ), "vburg_%d_items", vehicleid ); - DeleteGVar( szString ); + DeleteGVar( sprintf( "vburg_%d_cash", vehicleid ) ); + DeleteGVar( sprintf( "vburg_%d_items", vehicleid ) ); return 1; } diff --git a/gamemodes/irresistible/cnr/features/houses/house.pwn b/gamemodes/irresistible/cnr/features/houses/house.pwn index b465261..a425668 100644 --- a/gamemodes/irresistible/cnr/features/houses/house.pwn +++ b/gamemodes/irresistible/cnr/features/houses/house.pwn @@ -24,6 +24,8 @@ /* ** Macros ** */ #define IsPlayerHomeOwner(%0,%1) ( strmatch( g_houseData[ %1 ] [ E_OWNER ], ReturnPlayerName( %0 ) ) ) +#define IsValidHouse(%0) ( 0 <= %0 < MAX_HOUSES && Iter_Contains( houses, %0 ) ) +#define GetPlayerEnteredHouse(%0) ( p_InHouse[ %0 ] ) /* ** Variables ** */ enum E_HOUSE_DATA diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index b43683b..262c678 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -6607,24 +6607,17 @@ public OnPlayerEnterDynamicCP( playerid, checkpointid ) new is_owner = strmatch( g_houseData[ i ] [ E_OWNER ], ReturnPlayerName( playerid ) ); - new is_locked = ! g_houseData[ i ] [ E_CRACKED ] && !strmatch( g_houseData[ i ] [ E_PASSWORD ], "N/A" ) && ! is_owner; - - if ( ! CallLocalFunction( "OnPlayerTryEnterHouse", "ddd", playerid, i, is_locked ) ) + if ( ! g_houseData[ i ] [ E_CRACKED ] && ! strmatch( g_houseData[ i ] [ E_PASSWORD ], "N/A" ) && ! is_owner ) { + if ( IsPlayerJob( playerid, JOB_BURGLAR ) || GetPlayerClass( playerid ) == CLASS_POLICE ) { + CallLocalFunction( "OnPlayerAttemptBurglary", "ddd", playerid, houseid, -1 ); // attempting a break in as a burglar/cop + } + p_PasswordedHouse[ playerid ] = i; ShowPlayerDialog( playerid, DIALOG_HOUSE_PW, DIALOG_STYLE_PASSWORD, "{FFFFFF}House Authentication", ""COL_GREEN"This house is password locked!\n"COL_WHITE"You may only enter this house if you enter the correct password.", "Enter", "Cancel" ); return 1; } - // alert burglar of any furniture - if ( ! is_owner && p_Job{ playerid } == JOB_BURGLAR && p_Class[ playerid ] == CLASS_CIVILIAN ) { - if ( Iter_Count( housefurniture[ i ] ) ) { - ShowPlayerHelpDialog( playerid, 4000, "This house has furniture to rob.~n~~n~Type ~g~~h~/burglar steal~w~ near the furniture you want to steal." ); - } else { - ShowPlayerHelpDialog( playerid, 4000, "~r~This house has no furniture to rob." ); - } - } - p_InHouse[ playerid ] = i; UpdatePlayerEntranceExitTick( playerid ); SetPlayerVirtualWorld( playerid, g_houseData[ i ] [ E_WORLD ] );