From 8c2dd222d2ce61fa553e704a407b7c996ccb3afc Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Tue, 9 Oct 2018 10:33:04 +1100 Subject: [PATCH] add toy model preview --- gamemodes/irresistible/cnr/dialog_ids.pwn | 2 +- gamemodes/irresistible/cnr/features/toys.pwn | 74 +++++++++++++++----- gamemodes/sf-cnr.pwn | 23 +++--- 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/gamemodes/irresistible/cnr/dialog_ids.pwn b/gamemodes/irresistible/cnr/dialog_ids.pwn index f1ff9d5..08028ea 100644 --- a/gamemodes/irresistible/cnr/dialog_ids.pwn +++ b/gamemodes/irresistible/cnr/dialog_ids.pwn @@ -47,7 +47,7 @@ #define DIALOG_GARAGE_INTERIORS 1035 #define DIALOG_GARAGE_INT_CONFIRM 1036 #define DIALOG_GANG_LIST 1037 -//#define DIALOG_LUMBERJACK 1038 +#define DIALOG_TOY_PREVIEW 1038 #define DIALOG_FIGHTSTYLE 1039 #define DIALOG_TOYS_MAIN 1040 #define DIALOG_TOYS 1041 diff --git a/gamemodes/irresistible/cnr/features/toys.pwn b/gamemodes/irresistible/cnr/features/toys.pwn index a88a828..a93c3ce 100644 --- a/gamemodes/irresistible/cnr/features/toys.pwn +++ b/gamemodes/irresistible/cnr/features/toys.pwn @@ -25,6 +25,8 @@ #define CATEGORY_MISC ( 10 ) #define CATEGORY_VIP ( 11 ) +#define MODEL_PREVIEW_TOY ( 15 ) + /* ** Variables ** */ enum E_ATTACHED_DATA { @@ -382,28 +384,55 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) { if ( x == listitem ) { - if ( p_ToyUnlocked[ playerid ] { g_ToyData[ id ] [ E_ID ] } ) - { - showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); - return SendError( playerid, "You have already bought this toy." ); - } - - if ( GetPlayerCash( playerid ) < g_ToyData[ id ] [ E_PRICE ] ) - { - showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); - return SendError( playerid, "You cannot afford this toy." ); - } - - UnlockPlayerToy( playerid, g_ToyData[ id ] [ E_ID ] ); - GivePlayerCash( playerid, -g_ToyData[ id ] [ E_PRICE ] ); - showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); - SendServerMessage( playerid, "You have bought a "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE".", g_ToyData[ id ] [ E_NAME ], cash_format( g_ToyData[ id ] [ E_PRICE ] ) ); + SetPVarInt( playerid, "toy_item", id ); + ShowPlayerDialog( playerid, DIALOG_TOY_PREVIEW, DIALOG_STYLE_TABLIST, "{FFFFFF}Purchase Toys", sprintf( "Purchase Toy\t"COL_GOLD"%s\nPreview Toy\t ", cash_format( g_ToyData[ id ] [ E_PRICE ] ) ), "Select", "Back" ); break; } x ++; } } } + else if ( dialogid == DIALOG_TOY_PREVIEW ) + { + if ( ! response ) + return showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); + + new + id = GetPVarInt( playerid, "toy_item" ); + + if ( ! ( 0 <= id < sizeof( g_ToyData ) ) ) + return SendError( playerid, "An error has occurred, please try again." ); + + switch ( listitem ) + { + // bought + case 0: + { + if ( p_ToyUnlocked[ playerid ] { g_ToyData[ id ] [ E_ID ] } ) + { + showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); + return SendError( playerid, "You have already bought this toy." ); + } + + if ( GetPlayerCash( playerid ) < g_ToyData[ id ] [ E_PRICE ] ) + { + showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); + return SendError( playerid, "You cannot afford this toy." ); + } + + UnlockPlayerToy( playerid, g_ToyData[ id ] [ E_ID ] ); + GivePlayerCash( playerid, -g_ToyData[ id ] [ E_PRICE ] ); + showToyCategoryItems( playerid, p_ToyCategorySelected{ playerid }, .pawnshop = true ); + SendServerMessage( playerid, "You have bought a "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE".", g_ToyData[ id ] [ E_NAME ], cash_format( g_ToyData[ id ] [ E_PRICE ] ) ); + } + + // preview + case 1: + { + return ShowPlayerModelPreview( playerid, MODEL_PREVIEW_TOY, "Toy Preview", g_ToyData[ id ] [ E_MODEL ] ); + } + } + } else if ( dialogid == DIALOG_TOYS_BONE || dialogid == DIALOG_TOYS_BONE_EDIT ) { new @@ -569,6 +598,19 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) return 1; } +hook OnPlayerEndModelPreview( playerid, handleid ) +{ + if ( handleid == MODEL_PREVIEW_TOY ) + { + new + id = GetPVarInt( playerid, "toy_item" ); + + SendServerMessage( playerid, "You have finished looking at this toy preview." ); + return ShowPlayerDialog( playerid, DIALOG_TOY_PREVIEW, DIALOG_STYLE_TABLIST, "{FFFFFF}Purchase Toys", sprintf( "Purchase Toy\t"COL_GOLD"%s\nPreview Toy\t ", cash_format( g_ToyData[ id ] [ E_PRICE ] ) ), "Select", "Back" ), Y_HOOKS_BREAK_RETURN_1; + } + return 1; +} + /* ** Commands ** */ CMD:toys( playerid, params[ ] ) { diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index e74ffc4..53ec47d 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -6840,18 +6840,17 @@ CMD:job( playerid, params[ ] ) CMD:jaillist( playerid, params[ ] ) { - new count = 0; - SendClientMessage( playerid, COLOR_GOLD, ".: Jail List :." ); - foreach(new i : Player) - { - if ( p_Jailed{ i } == true ) - { - SendClientMessageFormatted( playerid, -1, "%s (%d seconds)", ReturnPlayerName( i ), p_JailTime[ i ] ); - count++; - } - } - if ( count == 0 ) SendClientMessage( playerid, -1, "There are no players in jail." ); - return 1; + szBigString[ 0 ] = '\0'; + + foreach( new i : Player ) if ( IsPlayerJailed( i ) ) { + format( szBigString, sizeof( szBigString ), "%s%s%s(%d)\t%d seconds", szBigString, p_AdminJailed{ i } ? ( COL_RED ) : ( COL_WHITE ), ReturnPlayerName( i ), i, p_JailTime[ i ] ); + } + + if ( szBigString[ 0 ] == '\0' ) { + return SendError( playerid, "There are no players in jail." ); + } else { + return ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_TABLIST, ""COL_WHITE"Jail List", szBigString, "Close", "" ); + } } CMD:lastlogged( playerid, params[ ] )