SHARE
TWEET

[ZP] Banka za mrkija

milutinke Nov 30th, 2014 230 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <fvault>
  3. #include <zombieplague>
  4.  
  5. #define AUTOSAVE_INTERVAL 20.0
  6.  
  7. #define flag_get(%1,%2) (%1 & (1 << (%2 & 31)))
  8. #define flag_get_boolean(%1,%2) (flag_get(%1,%2) ? true : false)
  9. #define flag_set(%1,%2) %1 |= (1 << (%2 & 31))
  10. #define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31))
  11.  
  12. new const g_vault_name[] = "zp_autobank"
  13. new g_LoadSuccess, g_IsConnected, g_MaxPlayers
  14. new g_authid[33][35]
  15. new g_ammo[33]
  16.  
  17. #define is_user_valid(%1) (1 <= %1 <= g_MaxPlayers)
  18.  
  19. public plugin_init()
  20. {
  21.         register_plugin("ZP AmmoSaving(fvault)", "1.0.5", "wbyokomo")
  22.        
  23.         register_logevent("logevent_round_end", 2, "1=Round_End")
  24.        
  25.         g_MaxPlayers = get_maxplayers()
  26. }
  27.  
  28. public plugin_cfg()
  29. {
  30.         set_task(AUTOSAVE_INTERVAL, "TaskAutoSave",_,_,_,"b")
  31. }
  32.  
  33. public client_putinserver(id)
  34. {
  35.         if(is_user_hltv(id) || is_user_bot(id)) return;
  36.        
  37.         flag_set(g_IsConnected,id)
  38.         get_user_authid(id, g_authid[id], 34)
  39.         LoadAmmo(id)
  40. }
  41.  
  42. public client_disconnect(id)
  43. {
  44.         if(flag_get(g_LoadSuccess,id))
  45.         {
  46.                 SaveAmmo(id)
  47.                 flag_unset(g_LoadSuccess,id)
  48.         }
  49.        
  50.         flag_unset(g_IsConnected,id)
  51. }
  52.  
  53. public logevent_round_end() TaskAutoSave();
  54.  
  55. public TaskAutoSave()
  56. {
  57.         for(new id = 1; id <= g_MaxPlayers; id++)
  58.         {
  59.                 if(is_user_valid(id) && flag_get(g_IsConnected,id) && flag_get(g_LoadSuccess,id)) SaveAmmo(id);
  60.         }
  61. }
  62.  
  63. LoadAmmo(id)
  64. {
  65.         new data[16]
  66.         if(fvault_get_data(g_vault_name, g_authid[id], data, 15))
  67.         {
  68.                 g_ammo[id] = str_to_num(data)
  69.                 zp_set_user_ammo_packs(id, g_ammo[id])
  70.         }
  71.        
  72.         flag_set(g_LoadSuccess,id)
  73. }
  74.  
  75. SaveAmmo(id)
  76. {
  77.         if(!flag_get(g_LoadSuccess,id))
  78.         {
  79.                 server_print("[BANK] User [%i] failed to save AP because its not loaded yet!", id)
  80.                 return
  81.         }
  82.        
  83.         g_ammo[id] = zp_get_user_ammo_packs(id)
  84.        
  85.         new data[16]
  86.         num_to_str(g_ammo[id], data, 15)
  87.         fvault_set_data(g_vault_name, g_authid[id], data)
  88. }
RAW Paste Data
Pastebin PRO Autumn Special!
Get 40% OFF on Pastebin PRO accounts!
Top