Advertisement
Tibers

Admin Models Menu

Nov 25th, 2023
1,163
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.91 KB | Gaming | 1 0
  1. /* Sublime AMXX Editor v2.2 */
  2.  
  3. #include <amxmodx>
  4. #include <amxmisc>
  5. #include <cstrike>
  6. #include <hamsandwich>
  7. #include <fvault>
  8.  
  9. #define PLUGIN  "Admin Models Menu"
  10. #define VERSION "1.0"
  11. #define AUTHOR  "FanTa. & Cosmin" // Tibers edit
  12. #define ADMIN_FLAG ADMIN_LEVEL_H // Flag "t" in users.ini
  13. new isFreeForAll
  14.  
  15. // Definition of keys for the menu
  16. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0;
  17. const MENU_KEY_EXIT = 9 // will be 0
  18.  
  19. // Vault name for storing player models data
  20. new const save_models[] = "save-models"
  21. new SaveType
  22.  
  23. // Arrays to store player model choices
  24. new bool:PlayerTero1[33], PlayerTero2[33], PlayerTero3[33];
  25. new bool:PlayerCounter1[33], PlayerCounter2[33], PlayerCounter3[33];
  26. // Arrays to store available models for each team
  27. new const ModelsTero[][] =
  28. {
  29.     "Asasin",
  30.     "Anonymous",
  31.     "Agent"
  32. };
  33.  
  34. new const ModelsCounter[][] =
  35. {
  36.     "Ghost",
  37.     "Vendetta",
  38.     "Neo"
  39. };
  40. // Plugin initialization function
  41. public plugin_init()
  42. {
  43.     register_plugin(PLUGIN, VERSION, AUTHOR);
  44.  
  45.     register_menu("Test Menu", KEYSMENU, "test_menu"); // Register the main menu
  46.     register_clcmd("say /admodels", "admin"); // Register the command to open the menu
  47.     RegisterHam(Ham_Spawn, "player", "Player_Spawn", 1); // Register Ham to detect player spawns
  48.     // Register cvars
  49.     SaveType = register_cvar("SaveType", "2"); // 1 - IP || 2 - Nick || 3 - SteamID
  50.     isFreeForAll = register_cvar("FreeForAll", "0"); // Enable FreeForAll mode by default (1 enable, 0 disable)
  51.  
  52.     // Add your code here...
  53. }
  54. // Function to open the menu for admins
  55. public admin(id)
  56. {
  57.     // Check if the player is an admin or FreeForAll is enabled
  58.     if ((get_user_flags(id) & ADMIN_FLAG) || get_pcvar_num(isFreeForAll))
  59.     {
  60.         TestMenu(id);
  61.     }
  62.     else
  63.     {
  64.         client_print(id, print_chat, "The models are only for Admins Members!");
  65.     }
  66. }
  67. // Player spawn function
  68. public Player_Spawn(id)
  69. {
  70.     if (get_user_team(id) == 1)
  71.     {
  72.         if (!get_pcvar_num(isFreeForAll))
  73.         {
  74.             // Reset models for Terrorists if isFreeForAll is 0 and the player is not an admin
  75.             if (!(get_user_flags(id) & ADMIN_FLAG))
  76.             {
  77.                 PlayerTero1[id] = false;
  78.                 PlayerTero2[id] = false;
  79.                 PlayerTero3[id] = false;
  80.                 cs_reset_user_model(id);
  81.             }
  82.             else
  83.             {
  84.                 // If admin and isFreeForAll is 0, set the default Terrorist model
  85.                 cs_reset_user_model(id);
  86.                 if (PlayerTero1[id]) cs_set_user_model(id, ModelsTero[0]);
  87.                 if (PlayerTero2[id]) cs_set_user_model(id, ModelsTero[1]);
  88.                 if (PlayerTero3[id]) cs_set_user_model(id, ModelsTero[2]);
  89.             }
  90.         }
  91.         else
  92.         {
  93.             // Reset models for Terrorists if isFreeForAll is 1 or the player is an admin
  94.             cs_reset_user_model(id);
  95.             if (PlayerTero1[id]) cs_set_user_model(id, ModelsTero[0]);
  96.             if (PlayerTero2[id]) cs_set_user_model(id, ModelsTero[1]);
  97.             if (PlayerTero3[id]) cs_set_user_model(id, ModelsTero[2]);
  98.         }
  99.     }
  100.     else if (get_user_team(id) == 2)
  101.     {
  102.         if (!get_pcvar_num(isFreeForAll))
  103.         {
  104.             // If admin and isFreeForAll is 0, set the default Counter-Terrorist model
  105.             if (!(get_user_flags(id) & ADMIN_FLAG))
  106.             {
  107.                 PlayerCounter1[id] = false;
  108.                 PlayerCounter2[id] = false;
  109.                 PlayerCounter3[id] = false;
  110.                 cs_reset_user_model(id);
  111.             }
  112.             else
  113.             {
  114.                 // If admin and isFreeForAll is 0, set the default Counter-Terrorist model
  115.                 cs_reset_user_model(id);
  116.                 if (PlayerCounter1[id]) cs_set_user_model(id, ModelsCounter[0]);
  117.                 if (PlayerCounter2[id]) cs_set_user_model(id, ModelsCounter[1]);
  118.                 if (PlayerCounter3[id]) cs_set_user_model(id, ModelsCounter[2]);
  119.             }
  120.         }
  121.         else
  122.         {
  123.             // Reset models for Counter-Terrorists if isFreeForAll is 1 or the player is an admin
  124.             cs_reset_user_model(id);
  125.             if (PlayerCounter1[id]) cs_set_user_model(id, ModelsCounter[0]);
  126.             if (PlayerCounter2[id]) cs_set_user_model(id, ModelsCounter[1]);
  127.             if (PlayerCounter3[id]) cs_set_user_model(id, ModelsCounter[2]);
  128.         }
  129.     }
  130. }
  131.  
  132. // Precache models function
  133. public plugin_precache()
  134. {
  135.     for (new i = 0; i < sizeof(ModelsTero); i++)
  136.     {
  137.         new Text[64];
  138.         formatex(Text, sizeof(Text) - 1, "models/player/%s/%s.mdl", ModelsTero[i], ModelsTero[i]);
  139.         precache_model(Text);
  140.     }
  141.  
  142.     for (new i = 0; i < sizeof(ModelsCounter); i++)
  143.     {
  144.         new Text[64];
  145.         formatex(Text, sizeof(Text) - 1, "models/player/%s/%s.mdl", ModelsCounter[i], ModelsCounter[i]);
  146.         precache_model(Text);
  147.     }
  148. }
  149. // Display menu function
  150. public TestMenu(id)
  151. {
  152.     new szMenu[512], iLen;
  153.  
  154.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\wAdmin Models Menu:^n^n");
  155.  
  156.     if (cs_get_user_team(id) == CS_TEAM_T)
  157.     {
  158.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y1\d]\w Assassin's Creed %s", PlayerTero1[id] ? "\y[ON]^n" : "\r[OFF]^n");
  159.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y2\d]\w 1337 Anonymous L33T %s", PlayerTero2[id] ? "\y[ON]^n" : "\r[OFF]^n");
  160.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y3\d]\w Agent Smith Matrix %s^n^n", PlayerTero3[id] ? "\y[ON]^n" : "\r[OFF]^n");
  161.     }
  162.     else if (cs_get_user_team(id) == CS_TEAM_CT)
  163.     {
  164.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y1\d]\w Ghostface Death %s", PlayerCounter1[id] ? "\y[ON]^n" : "\r[OFF]^n");
  165.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y2\d]\w V for Vendetta %s", PlayerCounter2[id] ? "\y[ON]^n" : "\r[OFF]^n");
  166.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y3\d]\w Neo from The Matrix %s^n^n", PlayerCounter3[id] ? "\y[ON]^n" : "\r[OFF]^n");
  167.     }
  168.  
  169.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d[\y0\d]\w Exit^n");
  170.     show_menu(id, KEYSMENU, szMenu, -1, "Test Menu");
  171. }
  172. // Function to handle menu selection
  173. public test_menu(id, key)
  174. {
  175.     if (cs_get_user_team(id) == CS_TEAM_T)
  176.     {
  177.         switch (key)
  178.         {
  179.             case 0:
  180.             {
  181.                 if (!PlayerTero1[id])
  182.                 {
  183.                     PlayerTero1[id] = true;
  184.                     PlayerTero2[id] = false;
  185.                     PlayerTero3[id] = false;
  186.                     cs_set_user_model(id, ModelsTero[0]);
  187.                     client_print(id, print_chat, "You have enabled your Assassin's Creed model.");
  188.                 }
  189.                 else
  190.                 {
  191.                     PlayerTero1[id] = false;
  192.                     cs_reset_user_model(id);
  193.                     client_print(id, print_chat, "You have disabled your Assassin's Creed model.");
  194.                 }
  195.             }
  196.  
  197.             case 1:
  198.             {
  199.                 if (!PlayerTero2[id])
  200.                 {
  201.                     PlayerTero1[id] = false;
  202.                     PlayerTero2[id] = true;
  203.                     PlayerTero3[id] = false;
  204.                     cs_set_user_model(id, ModelsTero[1]);
  205.                     client_print(id, print_chat, "You have enabled your 1337 Anonymous L33T model.");
  206.                 }
  207.                 else
  208.                 {
  209.                     PlayerTero2[id] = false;
  210.                     cs_reset_user_model(id);
  211.                     client_print(id, print_chat, "You have disabled your 1337 Anonymous L33T model.");
  212.                 }
  213.             }
  214.  
  215.             case 2:
  216.             {
  217.                 if (!PlayerTero3[id])
  218.                 {
  219.                     PlayerTero1[id] = false;
  220.                     PlayerTero2[id] = false;
  221.                     PlayerTero3[id] = true;
  222.                     cs_set_user_model(id, ModelsTero[2]);
  223.                     client_print(id, print_chat, "You have enabled your Agent Smith Matrix model.");
  224.                 }
  225.                 else
  226.                 {
  227.                     PlayerTero3[id] = false;
  228.                     cs_reset_user_model(id);
  229.                     client_print(id, print_chat, "You have disabled your Agent Smith Matrix model.");
  230.                 }
  231.             }
  232.  
  233.             case MENU_KEY_EXIT: // exit
  234.             {
  235.                 return PLUGIN_HANDLED;
  236.             }
  237.         }
  238.     }
  239.     else if (cs_get_user_team(id) == CS_TEAM_CT)
  240.     {
  241.         switch (key)
  242.         {
  243.             case 0:
  244.             {
  245.                 if (!PlayerCounter1[id])
  246.                 {
  247.                     PlayerCounter1[id] = true;
  248.                     PlayerCounter2[id] = false;
  249.                     PlayerCounter3[id] = false;
  250.                     cs_set_user_model(id, ModelsCounter[0]);
  251.                     client_print(id, print_chat, "You have enabled your Ghostface Death model.");
  252.                 }
  253.                 else
  254.                 {
  255.                     PlayerCounter1[id] = false;
  256.                     cs_reset_user_model(id);
  257.                     client_print(id, print_chat, "You have disabled your Ghostface Death model.");
  258.                 }
  259.             }
  260.  
  261.             case 1:
  262.             {
  263.                 if (!PlayerCounter2[id])
  264.                 {
  265.                     PlayerCounter1[id] = false;
  266.                     PlayerCounter2[id] = true;
  267.                     PlayerCounter3[id] = false;
  268.                     cs_set_user_model(id, ModelsCounter[1]);
  269.                     client_print(id, print_chat, "You have enabled your V for Vendetta model.");
  270.                 }
  271.                 else
  272.                 {
  273.                     PlayerCounter2[id] = false;
  274.                     cs_reset_user_model(id);
  275.                     client_print(id, print_chat, "You have disabled your V for Vendetta model.");
  276.                 }
  277.             }
  278.  
  279.             case 2:
  280.             {
  281.                 if (!PlayerCounter3[id])
  282.                 {
  283.                     PlayerCounter1[id] = false;
  284.                     PlayerCounter2[id] = false;
  285.                     PlayerCounter3[id] = true;
  286.                     cs_set_user_model(id, ModelsCounter[2]);
  287.                     client_print(id, print_chat, "You have enabled your Neo from The Matrix model.");
  288.                 }
  289.                 else
  290.                 {
  291.                     PlayerCounter3[id] = false;
  292.                     cs_reset_user_model(id);
  293.                     client_print(id, print_chat, "You have disabled your Neo from The Matrix model.");
  294.                 }
  295.             }
  296.  
  297.             case MENU_KEY_EXIT: // exit
  298.             {
  299.                 return PLUGIN_HANDLED;
  300.             }
  301.         }
  302.     }
  303.     // Save player data and redisplay the menu
  304.     SaveData(id);
  305.     TestMenu(id);
  306.     return PLUGIN_HANDLED;
  307. }
  308. // Function called when a client disconnects
  309. public client_disconnected(id)
  310. {
  311.     // Save player data when disconnected
  312.     SaveData(id);
  313. }
  314. // Function called when a client is authorized
  315. public client_authorized(id)
  316. {
  317.     // Load player data when authorized
  318.     LoadData(id);
  319. }
  320. // Function to save player data
  321. public SaveData(id)
  322. {
  323.     new TypeSave[64], Data[256]
  324.     // Determine the type of save based on a cvar
  325.     switch(get_pcvar_num(SaveType))
  326.     {
  327.         case 1: get_user_ip(id, TypeSave, charsmax(TypeSave), 1)
  328.         case 2: get_user_name(id, TypeSave, charsmax(TypeSave))
  329.         case 3: get_user_authid(id, TypeSave, charsmax(TypeSave))
  330.     }
  331.     // Format player data for saving
  332.     formatex(Data, charsmax(Data), "%d %d %d %d %d %d", PlayerTero1[id], PlayerTero2[id], PlayerTero3[id], PlayerCounter1[id], PlayerCounter2[id], PlayerCounter3[id])
  333.     // Save the data using a vault
  334.     fvault_set_data(save_models, TypeSave, Data)
  335. }
  336. // Function to load player data
  337. public LoadData(id)
  338. {
  339.     new TypeSave[64], Data[256], PlayerData[6][2];
  340.  
  341.     // Determine the type of load based on a cvar
  342.     switch(get_pcvar_num(SaveType))
  343.     {
  344.         case 1: get_user_ip(id, TypeSave, charsmax(TypeSave), 1)
  345.         case 2: get_user_name(id, TypeSave, charsmax(TypeSave))
  346.         case 3: get_user_authid(id, TypeSave, charsmax(TypeSave))
  347.     }
  348.  
  349.     if (fvault_get_data(save_models, TypeSave, Data, charsmax(Data)))
  350.     {
  351.         // Data found, so parse and load values
  352.         parse(Data, PlayerData[0], 1, PlayerData[1], 1, PlayerData[2], 1, PlayerData[3], 1, PlayerData[4], 1, PlayerData[5], 1);
  353.         PlayerTero1[id] = str_to_num(PlayerData[0]) == 1;
  354.         PlayerTero2[id] = str_to_num(PlayerData[1]) == 1;
  355.         PlayerTero3[id] = str_to_num(PlayerData[2]) == 1;
  356.         PlayerCounter1[id] = str_to_num(PlayerData[3]) == 1;
  357.         PlayerCounter2[id] = str_to_num(PlayerData[4]) == 1;
  358.         PlayerCounter3[id] = str_to_num(PlayerData[5]) == 1;
  359.     }
  360. }
  361.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement