From d83e0c3120750374bc59c0b4a4780965fe489c91 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Fri, 9 Nov 2018 18:33:38 +1100 Subject: [PATCH] modulize the rewards point system --- .../irresistible/cnr/features/_features.pwn | 4 +- .../features/player_items/_player_items.pwn | 9 + .../cnr/features/{ => player_items}/shop.pwn | 0 .../cnr/features/visage/_visage.pwn | 1 + .../cnr/features/visage/rewardspoints.pwn | 264 ++++++++++++++++++ gamemodes/sf-cnr.pwn | 231 +-------------- 6 files changed, 282 insertions(+), 227 deletions(-) create mode 100644 gamemodes/irresistible/cnr/features/player_items/_player_items.pwn rename gamemodes/irresistible/cnr/features/{ => player_items}/shop.pwn (100%) create mode 100644 gamemodes/irresistible/cnr/features/visage/rewardspoints.pwn diff --git a/gamemodes/irresistible/cnr/features/_features.pwn b/gamemodes/irresistible/cnr/features/_features.pwn index 0907f5e..ac06774 100644 --- a/gamemodes/irresistible/cnr/features/_features.pwn +++ b/gamemodes/irresistible/cnr/features/_features.pwn @@ -14,11 +14,11 @@ #include "irresistible\cnr\features\business\_business.pwn" #include "irresistible\cnr\features\gangs\_gangs.pwn" #include "irresistible\cnr\features\robbery\_robbery.pwn" -#include "irresistible\cnr\features\visage\_visage.pwn" #include "irresistible\cnr\features\minijobs\_minijobs.pwn" +#include "irresistible\cnr\features\player_items\_player_items.pwn" +#include "irresistible\cnr\features\visage\_visage.pwn" // other -#include "irresistible\cnr\features\shop.pwn" #include "irresistible\cnr\features\toys.pwn" #include "irresistible\cnr\features\fps.pwn" #include "irresistible\cnr\features\radio.pwn" diff --git a/gamemodes/irresistible/cnr/features/player_items/_player_items.pwn b/gamemodes/irresistible/cnr/features/player_items/_player_items.pwn new file mode 100644 index 0000000..34b6531 --- /dev/null +++ b/gamemodes/irresistible/cnr/features/player_items/_player_items.pwn @@ -0,0 +1,9 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc Pekaj + * Module: cnr\features\player\_player_items.pwn + * Purpose: encloses all player item modules & components (cnr) + */ + +/* ** Includes ** */ +#include "irresistible\cnr\features\player_items\shop.pwn" diff --git a/gamemodes/irresistible/cnr/features/shop.pwn b/gamemodes/irresistible/cnr/features/player_items/shop.pwn similarity index 100% rename from gamemodes/irresistible/cnr/features/shop.pwn rename to gamemodes/irresistible/cnr/features/player_items/shop.pwn diff --git a/gamemodes/irresistible/cnr/features/visage/_visage.pwn b/gamemodes/irresistible/cnr/features/visage/_visage.pwn index 7e6348e..ea5e28a 100644 --- a/gamemodes/irresistible/cnr/features/visage/_visage.pwn +++ b/gamemodes/irresistible/cnr/features/visage/_visage.pwn @@ -14,3 +14,4 @@ #include "irresistible\cnr\features\visage\apartments.pwn" #include "irresistible\cnr\features\visage\boxing.pwn" #include "irresistible\cnr\features\visage\slot_machines.pwn" +#include "irresistible\cnr\features\visage\rewardspoints.pwn" diff --git a/gamemodes/irresistible/cnr/features/visage/rewardspoints.pwn b/gamemodes/irresistible/cnr/features/visage/rewardspoints.pwn new file mode 100644 index 0000000..8686ea9 --- /dev/null +++ b/gamemodes/irresistible/cnr/features/visage/rewardspoints.pwn @@ -0,0 +1,264 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc Pekaj + * Module: cnr\features\visage\rewardspoints.pwn + * Purpose: rewards points system for gambling + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Definitions ** */ +#define CASINO_REWARDS_PAYOUT_PERCENT 20.0 +#define CASINO_REWARDS_DIVISOR 10.0 // 1000 points becomes 1 point +#define CASINO_REWARDS_COST_MP 1.0 // half of the price (since it costs (1/payout_percent) times more) + +/* ** Variables ** */ +enum E_REWARDS_DATA +{ + E_NAME[ 32 ], Float: E_POINTS +}; + +static stock + g_casinoRewardsItems[ ] [ E_REWARDS_DATA ] = { + { "10 Explosive Bullets", 12500.0 }, + { "Highroller Access", 200000.0 } + }, + E_SHOP_ITEMS: g_casinoRewardsShopItems[ ] = { + SHOP_ITEM_TIE, + SHOP_ITEM_SCISSOR, + SHOP_ITEM_ROPES, + SHOP_ITEM_FOIL, + SHOP_ITEM_BOBBY_PIN, + SHOP_ITEM_MONEY_CASE, + SHOP_ITEM_DRILL, + SHOP_ITEM_METAL_MELTER, + SHOP_ITEM_WEED_SEED, + SHOP_ITEM_FIREWORKS + }, + Float: p_CasinoRewardsPoints [ MAX_PLAYERS ], + bool: p_IsCasinoHighRoller [ MAX_PLAYERS char ], + Text3D: p_RewardsLabel_4Drags [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, + Text3D: p_RewardsLabel_Caligs [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, + Text3D: p_RewardsLabel_Visage [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, + p_HighrollersBarrier [ MAX_PLAYERS ] [ 2 ] +; + +/* ** Hooks ** */ +hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) +{ + if ( dialogid == DIALOG_CASINO_REWARDS && response ) + { + if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You cannot use this while you're in jail." ); + + new + x = 0; + + if ( listitem >= sizeof( g_casinoRewardsShopItems ) ) + { + // printf("Listitem %d, sizeof %d\n", listitem, sizeof( g_casinoRewardsShopItems) ); + new rewards_item = listitem - sizeof( g_casinoRewardsShopItems ); + new Float: rewards_points = g_casinoRewardsItems[ rewards_item ] [ E_POINTS ]; + + if ( p_CasinoRewardsPoints[ playerid ] < rewards_points ) + return SendError( playerid, "You need %s rewards points for this item.", points_format( rewards_points ) ); + + switch ( rewards_item ) + { + case 0: + { + p_ExplosiveBullets[ playerid ] += 10; + ShowPlayerHelpDialog( playerid, 3000, "Press ~r~~k~~CONVERSATION_NO~~w~ to activate explosive bullets." ); + } + case 1: // highroller + { + if ( p_IsCasinoHighRoller{ playerid } ) return SendError( playerid, "You are already considered a casino highroller." ); + mysql_single_query( sprintf( "UPDATE `USERS` SET `VISAGE_HIGHROLLER`=1 WHERE `ID`=%d", p_AccountID[ playerid ] ) ); + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; + p_IsCasinoHighRoller{ playerid } = true; + } + } + + p_CasinoRewardsPoints[ playerid ] -= rewards_points; + mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); + SendServerMessage( playerid, "You have bought "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE" rewards points.", g_casinoRewardsItems[ rewards_item ] [ E_NAME ], points_format( rewards_points ) ); + return ShowPlayerRewardsMenu( playerid ); + } + else + { + for ( new i = 0; i < sizeof ( g_shopItemData ); i ++ ) if ( IsCasinoRewardsShopItem( g_shopItemData[ i ] [ E_ID ] ) ) + { + if ( x == listitem ) + { + new Float: rewards_cost = ( float( g_shopItemData[ i ] [ E_PRICE ] ) * CASINO_REWARDS_COST_MP ) / CASINO_REWARDS_DIVISOR; + + if ( p_CasinoRewardsPoints[ playerid ] < rewards_cost ) + return SendError( playerid, "You need %s rewards points for this item.", points_format( rewards_cost ) ); + + // shop limits + if ( g_shopItemData[ i ] [ E_LIMIT ] == 1 ) + { + if ( g_shopItemData[ i ] [ E_ID ] == SHOP_ITEM_DRILL ) { + if ( p_drillStrength[ playerid ] == MAX_DRILL_STRENGTH ) return SendError( playerid, "You have already purchased this item." ); + p_drillStrength[ playerid ] = MAX_DRILL_STRENGTH; + } else if ( g_shopItemData[ i ] [ E_ID ] == SHOP_ITEM_MONEY_CASE ) { + if ( p_MoneyBag{ playerid } == true ) return SendError( playerid, "You have already purchased this item." ); + if ( p_Class[ playerid ] != CLASS_POLICE ) SetPlayerAttachedObject( playerid, 1, 1210, 7, 0.302650, -0.002469, -0.193321, 296.124053, 270.396881, 8.941717, 1.000000, 1.000000, 1.000000 ); + p_MoneyBag{ playerid } = true; + } + } + else + { + new iCurrentQuantity = GetShopItemAmount( playerid, i ); + new iLimit = g_shopItemData[ i ] [ E_LIMIT ] + ( 2 * p_VIPLevel[ playerid ] ); + + if ( iCurrentQuantity >= iLimit ) + return SendError( playerid, "You cannot buy more of this item with your rewards points." ); + + SetPlayerShopItemAmount( playerid, i, iCurrentQuantity + 1 ); + } + + // deduct points + p_CasinoRewardsPoints[ playerid ] -= rewards_cost; + mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); + SendServerMessage( playerid, "You have bought 1x "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE" rewards points.", g_shopItemData[ i ] [ E_NAME ], points_format( rewards_cost ) ); + return ShowPlayerRewardsMenu( playerid ); + } + x ++; + } + } + return 1; + } + else if ( dialogid == DIALOG_CASINO_BAR && response ) + { + if ( p_CasinoRewardsPoints[ playerid ] < 20.0 ) return SendError( playerid, "You need 20.0 casino rewards points to buy an item from the casino's bar." ); + + // what did they buy + switch ( listitem ) + { + case 0: SetPlayerSpecialAction( playerid, 20 ), SendServerMessage( playerid, "You have bought a beer for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); + case 1: SetPlayerSpecialAction( playerid, 21 ), SendServerMessage( playerid, "You have bought a cigar for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); + case 2: SetPlayerSpecialAction( playerid, 22 ), SendServerMessage( playerid, "You have bought wine for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); + } + + // update account + p_CasinoRewardsPoints[ playerid ] -= 20.0; + mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); + return 1; + } + return 1; +} + +hook OnPlayerUpdateEx( playerid ) +{ + if ( ! IsPlayerSpawned( playerid ) ) + return 1; + + // Update casino labels + UpdateDynamic3DTextLabelText( p_RewardsLabel_Caligs[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); + UpdateDynamic3DTextLabelText( p_RewardsLabel_4Drags[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); + UpdateDynamic3DTextLabelText( p_RewardsLabel_Visage[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); + + // Remove invalid visage highrollers + if ( ! p_IsCasinoHighRoller{ playerid } && IsPlayerInHighRoller( playerid ) ) { + SetPlayerPos( playerid, 2597.8943, 1603.1852, 1506.1733 ); + SendError( playerid, "You need to be a Highroller to access this area. Get access through Casino Rewards." ); + } + return 1; +} + +hook OnPlayerConnect( playerid ) +{ + // Create casino label + DestroyDynamic3DTextLabel( p_RewardsLabel_Caligs[ playerid ] ); + DestroyDynamic3DTextLabel( p_RewardsLabel_4Drags[ playerid ] ); + DestroyDynamic3DTextLabel( p_RewardsLabel_Visage[ playerid ] ); + p_RewardsLabel_Caligs[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 2157.6294, 1599.4355, 1006.1797, 20.0, .playerid = playerid ); + p_RewardsLabel_4Drags[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 1951.7191, 997.55550, 992.85940, 20.0, .playerid = playerid ); + p_RewardsLabel_Visage[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 2604.1323, 1570.1182, 1508.3530, 20.0, .playerid = playerid ); + + // Create highroller objects + p_HighrollersBarrier[ playerid ] [ 0 ] = CreateDynamicObject( 19545, 2592.604980, 1610.016967, 1499.139038, 90.000000, 90.000000, 0.000000, .worldid = VISAGE_WORLD, .playerid = playerid ); + p_HighrollersBarrier[ playerid ] [ 1 ] = CreateDynamicObject( 19545, 2592.604003, 1595.026000, 1499.140991, 90.000000, 90.000000, 0.000000, .worldid = VISAGE_WORLD, .playerid = playerid ); + SetDynamicObjectMaterial( p_HighrollersBarrier[ playerid ] [ 0 ], 0, 11751, "enexmarkers", "enex", -9170 ); + SetDynamicObjectMaterial( p_HighrollersBarrier[ playerid ] [ 1 ], 0, 11751, "enexmarkers", "enex", -9170 ); + return 1; +} + +hook OnPlayerDisconnect( playerid, reason ) +{ + p_IsCasinoHighRoller{ playerid } = false; + p_CasinoRewardsPoints[ playerid ] = 0.0; + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; + return 1; +} + +hook OnPlayerLogin( playerid ) +{ + if ( p_IsCasinoHighRoller{ playerid } ) { + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; + DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; + } + return 1; +} + +/* ** Commands ** */ +CMD:casino( playerid, params[ ] ) +{ + if ( strmatch( params, "rewards" ) ) { + if ( ! IsPlayerInCasino( playerid ) ) return SendError( playerid, "You need to be in a casino to use this feature." ); + return ShowPlayerRewardsMenu( playerid ); + } else if ( strmatch( params, "points" ) ) { + return SendServerMessage( playerid, "You currently have "COL_GOLD"%s"COL_WHITE" casino rewards points.", points_format( p_CasinoRewardsPoints[ playerid ] ) ); + } + return SendUsage( playerid, "/casino [REWARDS/POINTS]" ); +} + +/* ** Functions ** */ +stock GivePlayerCasinoRewardsPoints( playerid, bet_amount, Float: house_edge ) { + if ( bet_amount < 0 ) bet_amount *= -1; // profit or loss, does not matter + // printf("(%f * ((%f * 100.0) * (%f / 100.0))) / %f\n",bet_amount, house_edge, CASINO_REWARDS_PAYOUT_PERCENT, CASINO_REWARDS_DIVISOR); + new Float: final_points = ( bet_amount * ( ( house_edge / 100.0 ) * ( CASINO_REWARDS_PAYOUT_PERCENT / 100.0 ) ) ) / CASINO_REWARDS_DIVISOR; + p_CasinoRewardsPoints[ playerid ] += final_points; + mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS`=%f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); + return 1; +} + +stock ShowPlayerRewardsMenu( playerid ) +{ + static szString[ 800 ]; + + if ( szString[ 0 ] == '\0' ) + { + strcat( szString, ""COL_WHITE"Item\t"COL_WHITE"Purpose\t"COL_WHITE"Rewards Points\n" ); + for( new i; i < sizeof( g_shopItemData ); i++ ) if ( IsCasinoRewardsShopItem( g_shopItemData[ i ] [ E_ID ] ) ) { + new Float: rewards_cost = ( float( g_shopItemData[ i ] [ E_PRICE ] ) * CASINO_REWARDS_COST_MP ) / CASINO_REWARDS_DIVISOR; + format( szString, sizeof( szString ), "%s%s\t"COL_GREY"%s\t"COL_GOLD"%s points\n", szString, g_shopItemData[ i ] [ E_NAME ], g_shopItemData[ i ] [ E_USAGE ], points_format( rewards_cost ) ); + } + for ( new i = 0; i < sizeof( g_casinoRewardsItems ); i ++ ) { + format( szString, sizeof( szString ), "%s%s\t \t"COL_GOLD"%s points\n", szString, g_casinoRewardsItems[ i ] [ E_NAME ], points_format( g_casinoRewardsItems[ i ] [ E_POINTS ] ) ); + } + } + return ShowPlayerDialog( playerid, DIALOG_CASINO_REWARDS, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Casino Rewards Items", szString, "Buy", "Cancel" ); +} + +stock IsCasinoRewardsShopItem( E_SHOP_ITEMS: itemid ) { + for ( new i = 0; i < sizeof( g_casinoRewardsShopItems ); i ++ ) if ( itemid == g_casinoRewardsShopItems[ i ] ) { + return true; + } + return false; +} + +stock Float: GetPlayerCasinoRewardsPoints( playerid ) { + return p_CasinoRewardsPoints[ playerid ]; +} + +stock SetPlayerCasinoRewardsPoints( playerid, Float: rewards ) { + p_CasinoRewardsPoints[ playerid ] = rewards; +} + +stock SetPlayerCasinoHighroller( playerid, bool: toggle ) { + p_IsCasinoHighRoller{ playerid } = toggle; +} diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 2116f87..aa91d88 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -200,41 +200,6 @@ new p_C4Amount [ MAX_PLAYERS ] ; -/* ** Casino Rewards Points ** */ -#define CASINO_REWARDS_PAYOUT_PERCENT 20.0 -#define CASINO_REWARDS_DIVISOR 10.0 // 1000 points becomes 1 point -#define CASINO_REWARDS_COST_MP 1.0 // half of the price (since it costs (1/payout_percent) times more) - -enum E_REWARDS_DATA -{ - E_NAME[ 32 ], Float: E_POINTS -} - -new - g_casinoRewardsItems[ ] [ E_REWARDS_DATA ] = { - { "10 Explosive Bullets", 12500.0 }, - { "Highroller Access", 200000.0 } - }, - E_SHOP_ITEMS: g_casinoRewardsShopItems[ ] = { - SHOP_ITEM_TIE, - SHOP_ITEM_SCISSOR, - SHOP_ITEM_ROPES, - SHOP_ITEM_FOIL, - SHOP_ITEM_BOBBY_PIN, - SHOP_ITEM_MONEY_CASE, - SHOP_ITEM_DRILL, - SHOP_ITEM_METAL_MELTER, - SHOP_ITEM_WEED_SEED, - SHOP_ITEM_FIREWORKS - }, - Float: p_CasinoRewardsPoints [ MAX_PLAYERS ], - bool: p_IsCasinoHighRoller [ MAX_PLAYERS char ], - Text3D: p_RewardsLabel_4Drags [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, - Text3D: p_RewardsLabel_Caligs [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, - Text3D: p_RewardsLabel_Visage [ MAX_PLAYERS ] = { Text3D: INVALID_3DTEXT_ID, ... }, - p_HighrollersBarrier [ MAX_PLAYERS ] [ 2 ] -; - /* ** Admin Ban Codes ** */ enum E_BAN_CODE { @@ -652,11 +617,6 @@ public OnServerUpdateTimer( ) // Generally Updated textdraws PlayerTextDrawSetString( playerid, p_LocationTD[ playerid ], GetPlayerArea( playerid ) ); - // Update casino labels - UpdateDynamic3DTextLabelText( p_RewardsLabel_Caligs[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); - UpdateDynamic3DTextLabelText( p_RewardsLabel_4Drags[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); - UpdateDynamic3DTextLabelText( p_RewardsLabel_Visage[ playerid ], COLOR_GOLD, sprintf( "[CASINO REWARDS]\n\n"COL_WHITE"You have %s rewards points!", points_format( p_CasinoRewardsPoints[ playerid ] ) ) ); - // Toggle total coin bar if ( ! IsPlayerSettingToggled( playerid, SETTING_COINS_BAR ) ) PlayerTextDrawSetString( playerid, p_CoinsTD[ playerid ], sprintf( "%05.3f", p_IrresistibleCoins[ playerid ] ) ); @@ -677,12 +637,6 @@ public OnServerUpdateTimer( ) //if ( IsPlayerDetained( playerid ) && isNotNearPlayer( playerid, p_DetainedBy[ playerid ] ) && ( g_iTime - p_TiedAtTimestamp[ playerid ] ) >= 8 ) // Uncuff( playerid ); - // Remove invalid visage highrollers - if ( ! p_IsCasinoHighRoller{ playerid } && IsPlayerInHighRoller( playerid ) ) { - SetPlayerPos( playerid, 2597.8943, 1603.1852, 1506.1733 ); - SendError( playerid, "You need to be a Highroller to access this area. Get access through Casino Rewards." ); - } - // Surfing a criminal vehicle if ( p_WantedLevel[ playerid ] < 6 && p_Class[ playerid ] != CLASS_POLICE ) { @@ -1304,20 +1258,6 @@ public OnPlayerConnect( playerid ) // Create player textdraws and remove buildings removeExcessiveBuildings( playerid ); - // Create casino label - DestroyDynamic3DTextLabel( p_RewardsLabel_Caligs[ playerid ] ); - DestroyDynamic3DTextLabel( p_RewardsLabel_4Drags[ playerid ] ); - DestroyDynamic3DTextLabel( p_RewardsLabel_Visage[ playerid ] ); - p_RewardsLabel_Caligs[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 2157.6294, 1599.4355, 1006.1797, 20.0, .playerid = playerid ); - p_RewardsLabel_4Drags[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 1951.7191, 997.55550, 992.85940, 20.0, .playerid = playerid ); - p_RewardsLabel_Visage[ playerid ] = CreateDynamic3DTextLabel( "[CASINO REWARDS]", COLOR_GOLD, 2604.1323, 1570.1182, 1508.3530, 20.0, .playerid = playerid ); - - // Create highroller objects - p_HighrollersBarrier[ playerid ] [ 0 ] = CreateDynamicObject( 19545, 2592.604980, 1610.016967, 1499.139038, 90.000000, 90.000000, 0.000000, .worldid = VISAGE_WORLD, .playerid = playerid ); - p_HighrollersBarrier[ playerid ] [ 1 ] = CreateDynamicObject( 19545, 2592.604003, 1595.026000, 1499.140991, 90.000000, 90.000000, 0.000000, .worldid = VISAGE_WORLD, .playerid = playerid ); - SetDynamicObjectMaterial( p_HighrollersBarrier[ playerid ] [ 0 ], 0, 11751, "enexmarkers", "enex", -9170 ); - SetDynamicObjectMaterial( p_HighrollersBarrier[ playerid ] [ 1 ], 0, 11751, "enexmarkers", "enex", -9170 ); - // Reset some variables p_Spawned { playerid } = false; p_GangID [ playerid ] = INVALID_GANG_ID; @@ -1616,7 +1556,6 @@ public OnPlayerDisconnect( playerid, reason ) p_AddedEmail { playerid } = false; p_TicketTimestamp[ playerid ] = 0; p_ExtraAssetSlots{ playerid } = 0; - p_CasinoRewardsPoints[ playerid ] = 0.0; p_OwnedBusinesses[ playerid ] = 0; p_ExplosiveBullets[ playerid ] = 0; p_GangSplitProfits[ playerid ] = 0; @@ -1628,7 +1567,6 @@ public OnPlayerDisconnect( playerid, reason ) p_TrainMissions[ playerid ] = 0; p_HydrogenChloride{ playerid } = 0; p_Methamphetamine{ playerid } = 0; - p_IsCasinoHighRoller{ playerid } = false; p_PawnStoreExport[ playerid ] = 0xFFFF; p_LastEnteredEntrance[ playerid ] = -1; p_ViewingGangTalk[ playerid ] = -1; @@ -1667,8 +1605,6 @@ public OnPlayerDisconnect( playerid, reason ) DestroyDynamicMapIcon( p_PawnStoreMapIcon[ playerid ] ); p_PawnStoreMapIcon[ playerid ] = 0xFFFF; jailDoors( playerid, .remove = true, .set_closed = false ); - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; switch( reason ) { @@ -3174,25 +3110,12 @@ CMD:changename( playerid, params[ ] ) { return 1; } -CMD:casino( playerid, params[ ] ) -{ - if ( strmatch( params, "rewards" ) ) { - if ( ! IsPlayerInCasino( playerid ) ) return SendError( playerid, "You need to be in a casino to use this feature." ); - return ShowPlayerRewardsMenu( playerid ); - } else if ( strmatch( params, "points" ) ) { - return SendServerMessage( playerid, "You currently have "COL_GOLD"%s"COL_WHITE" casino rewards points.", points_format( p_CasinoRewardsPoints[ playerid ] ) ); - } - return SendUsage( playerid, "/casino [REWARDS/POINTS]" ); -} - - CMD:suggest( playerid, params[ ] ) return cmd_feedback( playerid, params ); CMD:feedback( playerid, params[ ] ) { return ShowPlayerDialog( playerid, DIALOG_FEEDBACK, DIALOG_STYLE_INPUT, ""COL_GOLD"Server Feedback", ""COL_WHITE"Let us know how you think we can make the server better to play! Impactful feedback is rewarded.\n\n Be as serious and straight forward as you wish. You can rant if you need to. Be impactful.", "Submit", "Close" ); } - CMD:notes( playerid, params[ ] ) return cmd_mynotes( playerid, params ); CMD:myvipnotes( playerid, params[ ] ) return cmd_mynotes( playerid, params ); CMD:vipnotes( playerid, params[ ] ) return cmd_mynotes( playerid, params ); @@ -8159,9 +8082,8 @@ thread OnAttemptPlayerLogin( playerid, password[ ] ) p_IrresistibleCoins[ playerid ] = cache_get_field_content_float( 0, "COINS", dbHandle ); p_ExtraAssetSlots{ playerid } = cache_get_field_content_int( 0, "EXTRA_SLOTS", dbHandle ); p_forcedAnticheat[ playerid ] = cache_get_field_content_int( 0, "FORCE_AC", dbHandle ); - - p_CasinoRewardsPoints[ playerid ] = cache_get_field_content_float( 0, "CASINO_REWARDS", dbHandle ); - p_IsCasinoHighRoller{ playerid } = !!cache_get_field_content_int( 0, "VISAGE_HIGHROLLER", dbHandle ); + SetPlayerCasinoRewardsPoints( playerid, cache_get_field_content_float( 0, "CASINO_REWARDS", dbHandle ) ); + SetPlayerCasinoHighroller( playerid, !!cache_get_field_content_int( 0, "VISAGE_HIGHROLLER", dbHandle ) ); p_Fireworks[ playerid ] = cache_get_field_content_int( 0, "FIREWORKS", dbHandle ); p_ExplosiveBullets[ playerid ] = cache_get_field_content_int( 0, "EXPLOSIVE_BULLETS", dbHandle ); p_AddedEmail{ playerid } = !!cache_get_field_content_int( 0, "USED_EMAIL", dbHandle ); @@ -8187,12 +8109,6 @@ thread OnAttemptPlayerLogin( playerid, password[ ] ) return 1; } - // highroller object - if ( p_IsCasinoHighRoller{ playerid } ) { - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; - } - // Load some other variables too p_OwnedHouses [ playerid ] = GetPlayerOwnedHouses( playerid ); p_OwnedBusinesses [ playerid ] = GetPlayerOwnedBusinesses( playerid ); @@ -8952,106 +8868,6 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) } } } - if ( dialogid == DIALOG_CASINO_REWARDS && response ) - { - if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You cannot use this while you're in jail." ); - - new - x = 0; - - if ( listitem >= sizeof( g_casinoRewardsShopItems ) ) - { - // printf("Listitem %d, sizeof %d\n", listitem, sizeof( g_casinoRewardsShopItems) ); - new rewards_item = listitem - sizeof( g_casinoRewardsShopItems ); - new Float: rewards_points = g_casinoRewardsItems[ rewards_item ] [ E_POINTS ]; - - if ( p_CasinoRewardsPoints[ playerid ] < rewards_points ) - return SendError( playerid, "You need %s rewards points for this item.", points_format( rewards_points ) ); - - switch ( rewards_item ) - { - case 0: - { - p_ExplosiveBullets[ playerid ] += 10; - ShowPlayerHelpDialog( playerid, 3000, "Press ~r~~k~~CONVERSATION_NO~~w~ to activate explosive bullets." ); - } - case 1: // highroller - { - if ( p_IsCasinoHighRoller{ playerid } ) return SendError( playerid, "You are already considered a casino highroller." ); - mysql_single_query( sprintf( "UPDATE `USERS` SET `VISAGE_HIGHROLLER`=1 WHERE `ID`=%d", p_AccountID[ playerid ] ) ); - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 0 ] ), p_HighrollersBarrier[ playerid ] [ 0 ] = -1; - DestroyDynamicObject( p_HighrollersBarrier[ playerid ] [ 1 ] ), p_HighrollersBarrier[ playerid ] [ 1 ] = -1; - p_IsCasinoHighRoller{ playerid } = true; - } - } - - p_CasinoRewardsPoints[ playerid ] -= rewards_points; - mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); - SendServerMessage( playerid, "You have bought "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE" rewards points.", g_casinoRewardsItems[ rewards_item ] [ E_NAME ], points_format( rewards_points ) ); - return ShowPlayerRewardsMenu( playerid ); - } - else - { - for ( new i = 0; i < sizeof ( g_shopItemData ); i ++ ) if ( IsCasinoRewardsShopItem( g_shopItemData[ i ] [ E_ID ] ) ) - { - if ( x == listitem ) - { - new Float: rewards_cost = ( float( g_shopItemData[ i ] [ E_PRICE ] ) * CASINO_REWARDS_COST_MP ) / CASINO_REWARDS_DIVISOR; - - if ( p_CasinoRewardsPoints[ playerid ] < rewards_cost ) - return SendError( playerid, "You need %s rewards points for this item.", points_format( rewards_cost ) ); - - // shop limits - if ( g_shopItemData[ i ] [ E_LIMIT ] == 1 ) - { - if ( g_shopItemData[ i ] [ E_ID ] == SHOP_ITEM_DRILL ) { - if ( p_drillStrength[ playerid ] == MAX_DRILL_STRENGTH ) return SendError( playerid, "You have already purchased this item." ); - p_drillStrength[ playerid ] = MAX_DRILL_STRENGTH; - } else if ( g_shopItemData[ i ] [ E_ID ] == SHOP_ITEM_MONEY_CASE ) { - if ( p_MoneyBag{ playerid } == true ) return SendError( playerid, "You have already purchased this item." ); - if ( p_Class[ playerid ] != CLASS_POLICE ) SetPlayerAttachedObject( playerid, 1, 1210, 7, 0.302650, -0.002469, -0.193321, 296.124053, 270.396881, 8.941717, 1.000000, 1.000000, 1.000000 ); - p_MoneyBag{ playerid } = true; - } - } - else - { - new iCurrentQuantity = GetShopItemAmount( playerid, i ); - new iLimit = g_shopItemData[ i ] [ E_LIMIT ] + ( 2 * p_VIPLevel[ playerid ] ); - - if ( iCurrentQuantity >= iLimit ) - return SendError( playerid, "You cannot buy more of this item with your rewards points." ); - - SetPlayerShopItemAmount( playerid, i, iCurrentQuantity + 1 ); - } - - // deduct points - p_CasinoRewardsPoints[ playerid ] -= rewards_cost; - mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); - SendServerMessage( playerid, "You have bought 1x "COL_GREY"%s"COL_WHITE" for "COL_GOLD"%s"COL_WHITE" rewards points.", g_shopItemData[ i ] [ E_NAME ], points_format( rewards_cost ) ); - return ShowPlayerRewardsMenu( playerid ); - } - x ++; - } - } - return 1; - } - if ( dialogid == DIALOG_CASINO_BAR && response ) - { - if ( p_CasinoRewardsPoints[ playerid ] < 20.0 ) return SendError( playerid, "You need 20.0 casino rewards points to buy an item from the casino's bar." ); - - // what did they buy - switch ( listitem ) - { - case 0: SetPlayerSpecialAction( playerid, 20 ), SendServerMessage( playerid, "You have bought a beer for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); - case 1: SetPlayerSpecialAction( playerid, 21 ), SendServerMessage( playerid, "You have bought a cigar for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); - case 2: SetPlayerSpecialAction( playerid, 22 ), SendServerMessage( playerid, "You have bought wine for "COL_GOLD"20.0 casino rewards points"COL_WHITE"." ); - } - - // update account - p_CasinoRewardsPoints[ playerid ] -= 20.0; - mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS` = %f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); - return 1; - } if ( ( dialogid == DIALOG_VIP_LOCKER ) && response ) { if ( IsPlayerJailed( playerid ) ) @@ -9822,7 +9638,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) if ( p_WantedLevel[ playerid ] ) return SendError( playerid, "You cannot travel while you are wanted." ); if ( GetPlayerCash( playerid ) < AIR_TRAVEL_COST ) return SendError( playerid, "You need %s to travel between cities.", cash_format( AIR_TRAVEL_COST ) ); - new bool: using_rewards = p_CasinoRewardsPoints[ playerid ] > 5.0; + new bool: using_rewards = GetPlayerCasinoRewardsPoints( playerid ) > 5.0; // set position switch ( listitem ) @@ -9846,8 +9662,8 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) // check for rewards if ( using_rewards ) { - p_CasinoRewardsPoints[ playerid ] -= 5.0; - mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS`=%f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); + SetPlayerCasinoRewardsPoints( playerid, GetPlayerCasinoRewardsPoints( playerid ) - 5.0 ); + mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS`=%f WHERE `ID`=%d", GetPlayerCasinoRewardsPoints( playerid ), p_AccountID[ playerid ] ) ); } else { @@ -13200,44 +13016,9 @@ stock DCC_SendUserMessage( DCC_User: user, const message[ ] ) } #endif - -stock GivePlayerCasinoRewardsPoints( playerid, bet_amount, Float: house_edge ) { - if ( bet_amount < 0 ) bet_amount *= -1; // profit or loss, does not matter - // printf("(%f * ((%f * 100.0) * (%f / 100.0))) / %f\n",bet_amount, house_edge, CASINO_REWARDS_PAYOUT_PERCENT, CASINO_REWARDS_DIVISOR); - new Float: final_points = ( bet_amount * ( ( house_edge / 100.0 ) * ( CASINO_REWARDS_PAYOUT_PERCENT / 100.0 ) ) ) / CASINO_REWARDS_DIVISOR; - p_CasinoRewardsPoints[ playerid ] += final_points; - mysql_single_query( sprintf( "UPDATE `USERS` SET `CASINO_REWARDS`=%f WHERE `ID`=%d", p_CasinoRewardsPoints[ playerid ], p_AccountID[ playerid ] ) ); - return 1; -} - -stock ShowPlayerRewardsMenu( playerid ) -{ - static szString[ 800 ]; - - if ( szString[ 0 ] == '\0' ) - { - strcat( szString, ""COL_WHITE"Item\t"COL_WHITE"Purpose\t"COL_WHITE"Rewards Points\n" ); - for( new i; i < sizeof( g_shopItemData ); i++ ) if ( IsCasinoRewardsShopItem( g_shopItemData[ i ] [ E_ID ] ) ) { - new Float: rewards_cost = ( float( g_shopItemData[ i ] [ E_PRICE ] ) * CASINO_REWARDS_COST_MP ) / CASINO_REWARDS_DIVISOR; - format( szString, sizeof( szString ), "%s%s\t"COL_GREY"%s\t"COL_GOLD"%s points\n", szString, g_shopItemData[ i ] [ E_NAME ], g_shopItemData[ i ] [ E_USAGE ], points_format( rewards_cost ) ); - } - for ( new i = 0; i < sizeof( g_casinoRewardsItems ); i ++ ) { - format( szString, sizeof( szString ), "%s%s\t \t"COL_GOLD"%s points\n", szString, g_casinoRewardsItems[ i ] [ E_NAME ], points_format( g_casinoRewardsItems[ i ] [ E_POINTS ] ) ); - } - } - return ShowPlayerDialog( playerid, DIALOG_CASINO_REWARDS, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Casino Rewards Items", szString, "Buy", "Cancel" ); -} - -stock IsCasinoRewardsShopItem( E_SHOP_ITEMS: itemid ) { - for ( new i = 0; i < sizeof( g_casinoRewardsShopItems ); i ++ ) if ( itemid == g_casinoRewardsShopItems[ i ] ) { - return true; - } - return false; -} - stock ShowPlayerAirportMenu( playerid ) { - if ( p_CasinoRewardsPoints[ playerid ] >= 5.0 ) { + if ( GetPlayerCasinoRewardsPoints( playerid ) >= 5.0 ) { return ShowPlayerDialog( playerid, DIALOG_AIRPORT, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Airport", ""COL_WHITE"City\t"COL_WHITE"Casino Rewards Points\nSan Fierro\t"COL_GOLD"5.00 points\nLas Venturas\t"COL_GOLD"5.00 points\nLos Santos\t"COL_GOLD"5.00 points", "Travel", "Cancel" ); } return ShowPlayerDialog( playerid, DIALOG_AIRPORT, DIALOG_STYLE_TABLIST_HEADERS, "{FFFFFF}Airport", ""COL_WHITE"City\t"COL_WHITE"Cost\nSan Fierro\t"COL_GOLD"$2,000\nLas Venturas\t"COL_GOLD"$2,000\nLos Santos\t"COL_GOLD"$2,000", "Travel", "Cancel" );