JuSTaR

FXP HELP 5

Jan 20th, 2021
687
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <amxmodx>
  4. #include <amxmisc>
  5. #include <fvault>
  6.  
  7. #define PLUGIN "Jailbreak Jackpot"
  8. #define VERSION "0.2"
  9. #define AUTHOR "eldadz"
  10.  
  11. #define PREFIX "AMXX"
  12.  
  13. native get_user_cash( id );
  14. native set_user_cash( const client, cash );
  15.  
  16. enum _:enumCvar
  17. {
  18.     CVAR_DEPOSIT,
  19.     CVAR_PLAYERSMIN,
  20.     CVAR_CASHMIN,
  21.     CVAR_CASHMAX,
  22.     CVAR_SNIPER,
  23.     CVAR_SNIPERNUMBER,
  24. }
  25. enum _:enumJackpot
  26. {
  27.     JACKPOT_NAME[ 33 ],
  28.     JACKPOT_STEAM[ 35 ],
  29.     JACKPOT_CASHJACKPOT,
  30.     JACKPOT_CASH
  31. }
  32.  
  33. new g_aCvar[ enumCvar ];
  34.  
  35. new g_arrayPlayer[ 33 ][ enumJackpot ];
  36.  
  37. new Array:g_aJackpot, Trie:g_trieJackpot, g_intTotal;
  38.  
  39. new Float:g_fJackpotTimer;
  40.  
  41. new const g_szJackpot[] = "jackpot_vault_v2";
  42. new const g_szCashVault[] = "cash_vault";
  43.  
  44.  
  45. public plugin_init()
  46. {
  47.     register_plugin(PLUGIN, VERSION, AUTHOR)
  48.  
  49.     g_aCvar[ CVAR_DEPOSIT ] = register_cvar( "jp_deposit_min", "1000" );
  50.     g_aCvar[ CVAR_PLAYERSMIN ] = register_cvar( "jp_players_min", "2" );
  51.     g_aCvar[ CVAR_CASHMIN ] = register_cvar( "jp_cash_min", "50000" );
  52.     g_aCvar[ CVAR_CASHMAX ] = register_cvar( "jp_cash_max", "100000" );
  53.     g_aCvar[ CVAR_SNIPER ] = register_cvar( "jp_sniper", "0" );
  54.     g_aCvar[ CVAR_SNIPERNUMBER ] = register_cvar( "jp_sniper_per", "1.5" );
  55.  
  56.     register_clcmd("say /jackpot", "CmdMainJackpot");
  57.     register_clcmd("jackpot_amuont", "CmdDeposit");
  58.  
  59.     g_aJackpot = ArrayCreate( enumJackpot );
  60.     g_trieJackpot = TrieCreate();
  61.  
  62.     CmdSetupJackpot();
  63. }
  64.  
  65.  
  66. public plugin_cfg( )
  67. {
  68.     g_fJackpotTimer = float( GetTime() )
  69.     set_task( g_fJackpotTimer, "CmdActiveJackpot" )
  70. }
  71.  
  72. public client_authorized( iClient )
  73. {
  74.     LoadCash( iClient );
  75.     LoadUser( iClient );
  76. }
  77.  
  78. public client_disconnect( iClient )
  79. {
  80.     SaveCash( iClient );
  81.     SaveUser( iClient );
  82. }
  83. public CmdActiveJackpot()
  84. {  
  85.     g_fJackpotTimer = float( GetTime() )
  86.     set_task( g_fJackpotTimer, "CmdActiveJackpot" )
  87.  
  88.     static data[ enumJackpot ];
  89.     new bool:boolJackpot = CmdJacpotReady();
  90.  
  91.     if( boolJackpot )
  92.     {
  93.         new intWinner = CmdGetWinner();
  94.         new intJackpot = CmdGetJackpotCash();
  95.         ArrayGetArray( g_aJackpot, intWinner, data );
  96.  
  97.         client_print( 0, print_chat, "[ %s ] the winner is %s, he won %i$ cash %.2f%% chance.", PREFIX, data[ JACKPOT_STEAM ], intJackpot, 100 * (  float( data[ JACKPOT_CASHJACKPOT ] ) / float( intJackpot )  ));
  98.  
  99.         new intId = CmdisUserOnline( data[ JACKPOT_STEAM ] );
  100.        
  101.         if( CmdisUserOnline(  data[ JACKPOT_STEAM ]) != -1 )
  102.         {
  103.             new intId = CmdisUserOnline( data[ JACKPOT_STEAM ] );
  104.  
  105.             g_arrayPlayer[ intId ][ JACKPOT_CASH ] += intJackpot;
  106.             SaveCash( intId );
  107.             set_user_cash(intId, get_user_cash(intId) + intJackpot);
  108.  
  109.         }
  110.         else
  111.         {
  112.             new strData[ 16 ];
  113.  
  114.             new intCash = ( data[ JACKPOT_CASH ] + intJackpot );
  115.             formatex( strData, charsmax( strData ), "%i", intCash);
  116.  
  117.             fvault_set_data( g_szCashVault, data[ JACKPOT_STEAM ], strData );
  118.         }
  119.        
  120.         CmdResetJackpot();
  121.  
  122.     }
  123.  
  124. }
  125.  
  126. public CmdResetJackpot()
  127. {
  128.     for( new i = 0; i < get_maxplayers(); i++ )    
  129.         g_arrayPlayer[ i ][ JACKPOT_CASHJACKPOT ] = 0;
  130.  
  131.     g_intTotal = 0;
  132.     fvault_clear( g_szJackpot );
  133.     ArrayClear( g_aJackpot );
  134.     TrieClear( g_trieJackpot );
  135. }
  136.  
  137. public LoadCash( iClient )
  138. {
  139.     new strData[ 16 ], iNum[ 10 ];
  140.     if( !fvault_get_data( g_szCashVault, GetUserAuthid( iClient ), strData, sizeof( strData ) - 1) )
  141.     {
  142.         g_arrayPlayer[ iClient ][ JACKPOT_CASH ] = 0;
  143.         SaveUser( iClient );
  144.     }
  145.     else
  146.     {  
  147.         parse( strData, iNum, charsmax( iNum ) );
  148.         g_arrayPlayer[ iClient ][ JACKPOT_CASH ] = str_to_num( iNum );
  149.     }
  150. }
  151.  
  152.  
  153. public SaveCash( iClient )
  154. {
  155.     new strData[ 16 ];
  156.  
  157.     formatex( strData, charsmax( strData ), "%i", g_arrayPlayer[ iClient ][ JACKPOT_CASH ] );
  158.     fvault_set_data( g_szCashVault, g_arrayPlayer[ iClient ][ JACKPOT_STEAM ], strData );
  159. }
  160. public LoadUser( iClient )
  161. {
  162.     new strData[ 256 ], iNum[ 10 ];
  163.     if( !fvault_get_data( g_szJackpot, GetUserAuthid( iClient ), strData, sizeof( strData ) - 1) )
  164.     {
  165.         copy( g_arrayPlayer[ iClient ][ JACKPOT_NAME ], charsmax(  g_arrayPlayer[][ JACKPOT_NAME ] ), GetUserName( iClient ));
  166.         copy( g_arrayPlayer[ iClient ][ JACKPOT_STEAM ], charsmax(  g_arrayPlayer[][ JACKPOT_STEAM ] ), GetUserAuthid( iClient ));
  167.  
  168.         g_arrayPlayer[ iClient ][ JACKPOT_CASHJACKPOT ] = 0;
  169.         g_arrayPlayer[ iClient ][ JACKPOT_CASH ] = 0;
  170.         SaveUser( iClient );
  171.     }
  172.     else
  173.     {  
  174.         copy( g_arrayPlayer[ iClient ][ JACKPOT_NAME ], charsmax(  g_arrayPlayer[][ JACKPOT_NAME ] ), GetUserName( iClient ));
  175.  
  176.         strbreak( strData, iNum, sizeof( iNum ), strData, sizeof( strData ) );
  177.         g_arrayPlayer[ iClient ][ JACKPOT_CASHJACKPOT ]  = str_to_num( iNum );
  178.     }
  179. }
  180.  
  181. public SaveUser( iClient )
  182. {
  183.     new intLen, strTemp[ 256 ];
  184.  
  185.     intLen = format( strTemp[ intLen ], sizeof (strTemp ) - 1 - intLen , "%i", g_arrayPlayer[ iClient ][ JACKPOT_CASHJACKPOT ]);
  186.     intLen += format( strTemp[ intLen ], sizeof (strTemp ) - 1, " ^"%s^"", g_arrayPlayer[ iClient ][ JACKPOT_NAME ]);
  187.  
  188.     fvault_set_data( g_szJackpot, g_arrayPlayer[ iClient ][ JACKPOT_STEAM ], strTemp );
  189. }
  190.  
  191. public CmdSetupJackpot()
  192. {
  193.     static data[ enumJackpot ];
  194.  
  195.     new intTotal = fvault_size( g_szJackpot )
  196.     new strData[ 256 ], intCashJackpot[ 16 ];
  197.  
  198.     for( new i = 0; i < intTotal; i++ )
  199.     {
  200.         fvault_get_keyname( g_szJackpot , i, data[ JACKPOT_STEAM ], sizeof( data[ JACKPOT_STEAM ] ) - 1);
  201.         fvault_get_data( g_szJackpot , data[ JACKPOT_STEAM ], strData, sizeof( strData ) - 1);
  202.  
  203.         parse( strData, intCashJackpot, charsmax( intCashJackpot ), data[ JACKPOT_NAME ], charsmax( data[ JACKPOT_NAME ] ));
  204.  
  205.         data[ JACKPOT_CASHJACKPOT ] += str_to_num( intCashJackpot );
  206.  
  207.         if( data[ JACKPOT_CASHJACKPOT ] < 1000 )
  208.             continue;
  209.  
  210.         ArrayPushArray( g_aJackpot, data );
  211.         TrieSetCell( g_trieJackpot, data[ JACKPOT_STEAM ], g_intTotal );
  212.  
  213.         g_intTotal++;
  214.  
  215.     }  
  216. }
  217.  
  218.  
  219. public CmdDeposit( id )
  220. {
  221.     static data[ enumJackpot ];
  222.  
  223.     new strArgs[ 16 ];
  224.     read_argv( id, strArgs, charsmax( strArgs ) );
  225.  
  226.     if( !strlen( strArgs ) || !is_str_num( strArgs ) )
  227.     {
  228.         client_print( id, print_chat, "[ %s ] you have to enter a vaild number", PREFIX);
  229.         CmdMainJackpot( id )
  230.         return PLUGIN_HANDLED;
  231.     }
  232.     new intDeposit = str_to_num( strArgs );
  233.     new intMin = get_pcvar_num( g_aCvar[ CVAR_DEPOSIT ] );
  234.     new intMax = get_pcvar_num( g_aCvar[ CVAR_CASHMAX ] );
  235.     new intSniper = get_pcvar_num( g_aCvar[ CVAR_SNIPER ] )
  236.  
  237.     if( intDeposit < intMin )
  238.     {
  239.         client_print( id, print_chat, "[ %s ] you have to enter atleast more %i cash", PREFIX, intMin - intDeposit);
  240.         CmdMainJackpot( id );
  241.         return PLUGIN_HANDLED;
  242.     }
  243.  
  244.     if( g_arrayPlayer[ id ][ JACKPOT_CASH ] < intDeposit )
  245.     {
  246.         client_print( id, print_chat, "[ %s ] you dont own this kind of cash.", PREFIX);
  247.         CmdMainJackpot( id );
  248.         return PLUGIN_HANDLED;
  249.     }
  250.  
  251.     if( intSniper == 1  &&
  252.      intDeposit > ( CmdGetJackpotCash() * get_pcvar_float( g_aCvar[ CVAR_SNIPERNUMBER ] ) ) &&
  253.     CmdGetJackpotCash() >= get_pcvar_num( g_aCvar[ CVAR_CASHMIN ] )  )
  254.     {
  255.         client_print( id, print_chat, "[ %s ] Sorry snipers not allowed, lower the bet or wait for next round.", PREFIX);
  256.         CmdMainJackpot( id );
  257.         return PLUGIN_HANDLED;
  258.     }
  259.  
  260.     g_arrayPlayer[ id ][ JACKPOT_CASH ] -= intDeposit;
  261.     g_arrayPlayer[ id ][ JACKPOT_CASHJACKPOT ] += intDeposit;
  262.     SaveUser( id );
  263.  
  264.     if( TrieKeyExists( g_trieJackpot, g_arrayPlayer[ id ][ JACKPOT_STEAM ] ) )
  265.     {
  266.         new intKey
  267.         TrieGetCell( g_trieJackpot, g_arrayPlayer[ id ][ JACKPOT_STEAM ], intKey );
  268.  
  269.         ArrayGetArray( g_aJackpot, intKey, data );
  270.  
  271.         data[ JACKPOT_CASHJACKPOT ] += intDeposit;
  272.  
  273.         ArraySetArray( g_aJackpot, intKey, data );
  274.  
  275.     }
  276.     else
  277.     {
  278.         copy( data[ JACKPOT_STEAM ], charsmax( data[ JACKPOT_STEAM ] ), GetUserAuthid( id ) );
  279.         copy( data[ JACKPOT_NAME ], charsmax( data[ JACKPOT_NAME ] ), GetUserName( id ) );
  280.  
  281.         data[ JACKPOT_CASHJACKPOT ] = intDeposit;
  282.  
  283.         ArrayPushArray( g_aJackpot, data );
  284.         TrieSetCell( g_trieJackpot, data[ JACKPOT_STEAM ], g_intTotal );
  285.         g_intTotal++
  286.     }
  287.     if( CmdGetJackpotCash() > intMax )
  288.     {
  289.         CmdActiveJackpot();
  290.     }
  291.     CmdMainJackpot( id );
  292.     return PLUGIN_CONTINUE;
  293. }
  294.  
  295. public CmdMainJackpot( id )
  296. {
  297.     new strTemp[ 256 ], intLen;
  298.     new intJackpot = CmdGetJackpotCash();
  299.  
  300.     intLen = format( strTemp[ intLen ], sizeof( strTemp ) - 1, "\r[\w %s \r]\y Jackpot\w Main Menu^n", PREFIX);
  301.     intLen += format( strTemp[ intLen ], sizeof( strTemp ) - 1 - intLen, "\d*Note: jackpot starts every perfect hour, or when the pool is reach over %i^n^n", get_pcvar_num( g_aCvar[ CVAR_CASHMAX ] ));
  302.     intLen += format( strTemp[ intLen ], sizeof( strTemp ) - 1 - intLen, "\yJackpot\w Starts in: \y%s^n", CmdGetJackpotTime());
  303.     intLen += format( strTemp[ intLen ], sizeof( strTemp ) - 1 - intLen, "\yJackpot\w Cash: \d%i\r$^n^n", intJackpot);
  304.     intLen += format( strTemp[ intLen ], sizeof( strTemp ) - 1 - intLen, "\wYour deposited \d%i\r$\w, and your \ychances\w to win are\r %.2f%%", g_arrayPlayer[ id ][ JACKPOT_CASHJACKPOT ], 100 * ( float( g_arrayPlayer[ id ][ JACKPOT_CASHJACKPOT ] ) /  float( intJackpot )  ));
  305.     new iMenu = menu_create(strTemp , "CmdHandlerMain");
  306.  
  307.     menu_additem( iMenu, "Deposit Cash", "1");
  308.     menu_additem( iMenu, "View Jackpot Players", "2");
  309.  
  310.     menu_display( id, iMenu );
  311. }
  312.  
  313. public CmdHandlerMain( id, iMenu, iKey )
  314. {
  315.     if( iKey == MENU_EXIT )
  316.     {
  317.         menu_destroy( iMenu );
  318.     }
  319.     else
  320.     {
  321.         new intKey = MenuKey( iMenu, iKey );
  322.         switch( intKey )
  323.         {
  324.             case 1: client_cmd(id, "messagemode jackpot_amuont")
  325.             case 2: CmdMenuPlayers( id );
  326.         }
  327.     }
  328. }
  329.  
  330. public CmdMenuPlayers( id )
  331. {
  332.     static data[ enumJackpot ];
  333.  
  334.     new strTemp[ 128 ], intFound;
  335.     new intJackpot = CmdGetJackpotCash();
  336.  
  337.     formatex( strTemp, charsmax( strTemp ), "\r[\w %s \r]\w Jackpot Menu^nViewing all players in the \yjackpot\w poll:", PREFIX);
  338.     new iMenu = menu_create( strTemp, "CmdHandlerPlayers");
  339.  
  340.     for( new i = 0; i < g_intTotal; i++ )
  341.     {
  342.         ArrayGetArray( g_aJackpot, i, data )
  343.         formatex( strTemp, charsmax( strTemp ), "%s \d%i\r$ \y(%.2f%%)", data[ JACKPOT_NAME ], data[ JACKPOT_CASHJACKPOT ], 100 * (  float( data[ JACKPOT_CASHJACKPOT ] ) / float( intJackpot )  ));
  344.         menu_additem( iMenu, strTemp );
  345.  
  346.         intFound++;
  347.     }
  348.  
  349.     if( !intFound )
  350.     {
  351.         menu_additem( iMenu, "\rNo Players");
  352.     }
  353.  
  354.     menu_display( id, iMenu );
  355.  
  356. }
  357.  
  358. public CmdHandlerPlayers( id, iMenu, iKey )
  359. {
  360.     if( iKey == MENU_EXIT )
  361.     {
  362.         menu_destroy( iMenu );
  363.         CmdMainJackpot( id );
  364.     }
  365.     else
  366.     {
  367.         CmdMenuPlayers( id );
  368.     }
  369. }
  370.  
  371.  
  372. stock bool:CmdJacpotReady()
  373. {
  374.     if( CmdGetJackpotCash() < get_pcvar_num( g_aCvar[ CVAR_CASHMIN ] ) )
  375.     {
  376.         client_print( 0, print_chat, "[ %s ] Jackpot will be dealyed. since the pot didnt reach the minumum deposit( %i$ ).", PREFIX, get_pcvar_num( g_aCvar[ CVAR_CASHMIN ] ));
  377.         return false;
  378.     }
  379.     if( g_intTotal < get_pcvar_num( g_aCvar[ CVAR_PLAYERSMIN ] ) )
  380.     {
  381.         client_print( 0, print_chat, "[ %s ] Jackpot will be dealyed. since no players deposited.", PREFIX);
  382.         return false;
  383.     }
  384.  
  385.     return true;
  386. }
  387.  
  388. stock CmdGetWinner()
  389. {
  390.     static data[ enumJackpot ];
  391.  
  392.     new intCash , intRandom;
  393.     intCash = CmdGetJackpotCash();
  394.     intRandom = random_num( 1, intCash );
  395.  
  396.     new intCurrect , intPrevious, intWinner;
  397.  
  398.     for( new i = 0; i < g_intTotal; i++ )
  399.     {
  400.         ArrayGetArray( g_aJackpot, i, data );
  401.  
  402.         intCurrect = intPrevious + data[ JACKPOT_CASHJACKPOT ];
  403.  
  404.         if( intPrevious < intRandom && intRandom <=  intCurrect )
  405.         {
  406.             intWinner = i;
  407.             break;
  408.         }
  409.  
  410.         intPrevious += data[ JACKPOT_CASHJACKPOT ];
  411.     }
  412.  
  413.     return intWinner;
  414.  
  415. }
  416.  
  417. stock CmdisUserOnline( strSteam[] )
  418. {
  419.     for( new i = 0; i < get_maxplayers(); i++ )
  420.     {
  421.         if( equali( strSteam, GetUserAuthid( i ) ) )
  422.         {
  423.             return i;
  424.         }
  425.     }
  426.     return -1;
  427. }
  428. stock CmdGetJackpotTime()
  429. {
  430.     new strDate[ 64 ];
  431.  
  432.     new iHour, iMinute, iSecond;
  433.     time( iHour, iMinute, iSecond )
  434.  
  435.     new intCheckT = iMinute;
  436.  
  437.     intCheckT = 60 - ( ( intCheckT > 0 ) ? ( iMinute + 1) : iMinute );
  438.  
  439.     formatex( strDate, charsmax( strDate ), "%i:%i", intCheckT, ( 60 - iSecond ));
  440.  
  441.     return strDate;
  442. }
  443.  
  444. stock GetTime()
  445. {
  446.     new iHour, iMinute, iSecond;
  447.     time( iHour, iMinute, iSecond )
  448.  
  449.     new intCheckT = iMinute;
  450.  
  451.     intCheckT = 60 - ( ( intCheckT > 0 ) ? ( iMinute + 1) : iMinute );
  452.  
  453.     return ( ( intCheckT ) * 60 ) + ( 60 - iSecond );
  454. }
  455.  
  456. stock CmdGetJackpotCash()
  457. {
  458.     static data[ enumJackpot ];
  459.     new intCash = 0;
  460.  
  461.     for( new i = 0; i < g_intTotal; i++ )
  462.     {
  463.         ArrayGetArray( g_aJackpot, i, data );
  464.  
  465.         intCash += data[ JACKPOT_CASHJACKPOT ];
  466.     }
  467.  
  468.     return intCash;
  469. }
  470.  
  471.  
  472. stock GetUserName( const index )
  473. {
  474.     static strName[ 33 ];
  475.  
  476.     get_user_name( index, strName, charsmax( strName ) );
  477.  
  478.     return strName;
  479. }
  480.  
  481. stock MenuKey(menu, item)
  482. {
  483.     new szData[6], szName[64];
  484.     new access, callback;
  485.     menu_item_getinfo(menu, item, access, szData, charsmax(szData), szName, charsmax(szName), callback);
  486.  
  487.     menu_destroy(menu)
  488.  
  489.     return str_to_num(szData);
  490. }
  491.  
  492. stock GetUserAuthid( const index )
  493. {
  494.     static strAuthid[ 35 ];
  495.  
  496.     get_user_authid( index, strAuthid, charsmax( strAuthid ) );
  497.  
  498.     return strAuthid;
  499. }
RAW Paste Data