JuSTaR

FXP HELP 6

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