Advertisement
CheezPuff

[Free] ViewCD Skin SHOP - [By CheezPuff]

Jul 7th, 2024 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.16 KB | None | 0 0
  1. /*
  2. שחקן מקליד בצ'אט "/skins".
  3. נפתח תפריט ראשי עם האפשרויות "Weapon Skins" ו-"Player Model Skins".
  4. בתחתית התפריט מוצג סכום הכסף של השחקן.
  5.  
  6.  
  7. תפריט Weapon Skins:
  8. השחקן רואה רשימה של סקינים לנשק, למשל:
  9. Default [Owned]
  10. Gold [$1000]
  11.  
  12. סקינים שכבר נרכשו מסומנים כ-"Owned".
  13. סקינים שעדיין לא נרכשו מציגים את מחירם.
  14.  
  15.  
  16. רכישת סקין לנשק:
  17.  
  18. השחקן בוחר סקין שעדיין לא רכש.
  19. אם יש לו מספיק כסף, הסקין נרכש והודעה מופיעה בצ'אט:
  20. "You purchased the Gold weapon skin for $1000!"
  21. הסקין מוחל מיד על הנשק של השחקן.
  22.  
  23.  
  24. תפריט Player Model Skins:
  25.  
  26. דומה לתפריט הנשקים, אבל עבור מודלים של שחקנים.
  27. למשל: Default [Owned], VIP [$2000]
  28.  
  29. רכישת סקין למודל שחקן:
  30.  
  31. בחירת סקין תגרום לרכישה אם יש מספיק כסף.
  32. הודעה תופיע בצ'אט: "You purchased the VIP player skin for $2000!"
  33. המודל החדש יוחל מיד על השחקן.
  34.  
  35. שימוש בסקינים:
  36.  
  37. בכל פעם שהשחקן מתחיל סיבוב חדש, הסקינים שנבחרו (לנשק ולמודל) יוחלו אוטומטית.
  38. שחקנים אחרים יראו את המודל החדש של השחקן.
  39. השחקן יראה את הסקין החדש של הנשק שלו.
  40. */
  41.  
  42. #include <amxmodx>
  43. #include <amxmisc>
  44. #include <cstrike>
  45. #include <fakemeta>
  46. #include <fvault>
  47. #include <hamsandwich>
  48.  
  49. #define PLUGIN "Skin Menu"
  50. #define VERSION "1.9"
  51. #define AUTHOR "CheezPuff"
  52.  
  53. #define MAX_PLAYERS 32
  54. #define MAX_WEAPON_TYPES 5
  55. #define MAX_WEAPON_SKINS 10
  56. #define MAX_PLAYER_SKINS 5
  57.  
  58. enum _:SkinInfo {
  59.     SKIN_NAME[32],
  60.     SKIN_COST,
  61.     SKIN_MODEL[128],
  62.     SKIN_PURCHASES
  63. }
  64.  
  65. new const g_WeaponSkinsData[MAX_WEAPON_SKINS][SkinInfo] = {
  66.     {"Golden AK47", 1000, "models/custom_weapons/v_ak47_gold.mdl", 0},
  67.     {"Neon AK47", 2000, "models/custom_weapons/v_ak47_neon.mdl", 0},
  68.     {"Flames M4A1", 1500, "models/custom_weapons/v_m4a1_flames.mdl", 0},
  69.     {"Diamond AWP", 3000, "models/custom_weapons/v_awp_diamond.mdl", 0},
  70.     {"Lava Deagle", 1200, "models/custom_weapons/v_deagle_lava.mdl", 0},
  71.     {"", 0, "", 0},
  72.     {"", 0, "", 0},
  73.     {"", 0, "", 0},
  74.     {"", 0, "", 0},
  75.     {"", 0, "", 0}
  76. }
  77.  
  78. new const g_PlayerSkinsData[MAX_PLAYER_SKINS][SkinInfo] = {
  79.     {"VIP", 2000, "models/player/vip/vip.mdl", 0},
  80.     {"Zombie", 3000, "models/player/zombie/zombie.mdl", 0},
  81.     {"Ninja", 2500, "models/player/ninja/ninja.mdl", 0},
  82.     {"Robot", 3500, "models/player/robot/robot.mdl", 0},
  83.     {"Alien", 4000, "models/player/alien/alien.mdl", 0}
  84. }
  85.  
  86. new Array:g_WeaponSkins
  87. new Array:g_PlayerSkins
  88.  
  89. new g_PlayerWeaponSkin[MAX_PLAYERS + 1][MAX_WEAPON_TYPES]
  90. new g_PlayerModelSkin[MAX_PLAYERS + 1]
  91. new Array:g_PlayerOwnedSkins
  92.  
  93. native get_user_cash(id);
  94. native set_user_cash(id, amount);
  95.  
  96. public plugin_init() {
  97.     register_plugin(PLUGIN, VERSION, AUTHOR)
  98.     register_clcmd("say /skins", "Cmd_ShowSkinMenu")
  99.     register_clcmd("say /knifes", "Cmd_ShowSkinMenu")
  100.    
  101.     RegisterHam(Ham_Spawn, "player", "PlayerSpawn_Post", 1)
  102.     RegisterHam(Ham_Item_Deploy, "weapon_*", "Ham_Item_Deploy_Post", 1)
  103.    
  104.     g_WeaponSkins = ArrayCreate(SkinInfo)
  105.     g_PlayerSkins = ArrayCreate(SkinInfo)
  106.  
  107.     g_PlayerOwnedSkins = ArrayCreate(1, MAX_PLAYERS + 1)
  108.  
  109.     LoadSkinsFromConstants()
  110. }
  111.  
  112. LoadSkinsFromConstants() {
  113.     for (new i = 0; i < MAX_WEAPON_SKINS; i++) {
  114.         if (g_WeaponSkinsData[i][SKIN_NAME][0]) {
  115.             ArrayPushArray(g_WeaponSkins, g_WeaponSkinsData[i])
  116.         }
  117.     }
  118.    
  119.     for (new i = 0; i < MAX_PLAYER_SKINS; i++) {
  120.         if (g_PlayerSkinsData[i][SKIN_NAME][0]) {
  121.             ArrayPushArray(g_PlayerSkins, g_PlayerSkinsData[i])
  122.         }
  123.     }
  124. }
  125.  
  126. public plugin_precache() {
  127.     for (new i = 0; i < MAX_WEAPON_SKINS; i++) {
  128.         if (g_WeaponSkinsData[i][SKIN_MODEL][0]) {
  129.             precache_model(g_WeaponSkinsData[i][SKIN_MODEL])
  130.         }
  131.     }
  132.    
  133.     for (new i = 0; i < MAX_PLAYER_SKINS; i++) {
  134.         if (g_PlayerSkinsData[i][SKIN_MODEL][0]) {
  135.             precache_model(g_PlayerSkinsData[i][SKIN_MODEL])
  136.         }
  137.     }
  138. }
  139.  
  140. public Cmd_ShowSkinMenu(id) {
  141.     ShowMainMenu(id)
  142.     return PLUGIN_HANDLED
  143. }
  144.  
  145. ShowMainMenu(id) {
  146.     new menu = menu_create("\rSkin Menu", "MainMenuHandler")
  147.    
  148.     menu_additem(menu, "\wWeapon Skins")
  149.     menu_additem(menu, "\wPlayer Model Skins")
  150.    
  151.     new info[64]
  152.     formatex(info, charsmax(info), "\yCash: $%d", get_user_cash(id))
  153.     menu_addtext(menu, info, 0)
  154.    
  155.     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  156.     menu_display(id, menu, 0)
  157. }
  158.  
  159. public MainMenuHandler(id, menu, item) {
  160.     if (item == MENU_EXIT) {
  161.         menu_destroy(menu)
  162.         return PLUGIN_HANDLED
  163.     }
  164.    
  165.     switch(item) {
  166.         case 0: ShowWeaponSkinMenu(id)
  167.         case 1: ShowPlayerSkinMenu(id)
  168.     }
  169.    
  170.     menu_destroy(menu)
  171.     return PLUGIN_HANDLED
  172. }
  173.  
  174. ShowWeaponSkinMenu(id) {
  175.     new menu = menu_create("\rWeapon Skins", "WeaponSkinMenuHandler")
  176.    
  177.     new skin[SkinInfo]
  178.     for (new i = 0; i < ArraySize(g_WeaponSkins); i++) {
  179.         ArrayGetArray(g_WeaponSkins, i, skin)
  180.         new item[64], status[16]
  181.         new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
  182.        
  183.         new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  184.         if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, i)) {
  185.             copy(status, charsmax(status), "\yOwned")
  186.         } else {
  187.             formatex(status, charsmax(status), "\r$%d", cost)
  188.         }
  189.        
  190.         formatex(item, charsmax(item), "%s \y[%s]", skin[SKIN_NAME], status)
  191.         menu_additem(menu, item)
  192.     }
  193.    
  194.     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  195.     menu_display(id, menu, 0)
  196. }
  197.  
  198. public WeaponSkinMenuHandler(id, menu, item) {
  199.     if (item == MENU_EXIT) {
  200.         ShowMainMenu(id)
  201.         menu_destroy(menu)
  202.         return PLUGIN_HANDLED
  203.     }
  204.    
  205.     new skin[SkinInfo]
  206.     ArrayGetArray(g_WeaponSkins, item, skin)
  207.    
  208.     new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  209.     if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, item)) {
  210.         g_PlayerWeaponSkin[id][0] = item
  211.         client_print_color(id, print_team_default, "^4[Skins] ^1You equipped the ^3%s^1!", skin[SKIN_NAME])
  212.     } else {
  213.         new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
  214.         new cash = get_user_cash(id)
  215.        
  216.         if (cash >= cost) {
  217.             set_user_cash(id, cash - cost)
  218.             g_PlayerWeaponSkin[id][0] = item
  219.             if (!playerOwnedSkins) {
  220.                 playerOwnedSkins = ArrayCreate(1)
  221.                 ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
  222.             }
  223.             ArraySetCell(playerOwnedSkins, item, 1)
  224.             skin[SKIN_PURCHASES]++
  225.             ArraySetArray(g_WeaponSkins, item, skin)
  226.             client_print_color(id, print_team_default, "^4[Skins] ^1You purchased the ^3%s ^1for ^4$%d^1!", skin[SKIN_NAME], cost)
  227.             SavePlayerData(id)
  228.         } else {
  229.             client_print_color(id, print_team_default, "^4[Skins] ^1You don't have enough cash to purchase this skin!")
  230.         }
  231.     }
  232.    
  233.     ShowWeaponSkinMenu(id)
  234.     return PLUGIN_HANDLED
  235. }
  236.  
  237. ShowPlayerSkinMenu(id) {
  238.     new menu = menu_create("\rPlayer Model Skins", "PlayerSkinMenuHandler")
  239.    
  240.     new skin[SkinInfo]
  241.     for (new i = 0; i < ArraySize(g_PlayerSkins); i++) {
  242.         ArrayGetArray(g_PlayerSkins, i, skin)
  243.         new item[64], status[16]
  244.         new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
  245.        
  246.         new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  247.         if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + i)) {
  248.             copy(status, charsmax(status), "\yOwned")
  249.         } else {
  250.             formatex(status, charsmax(status), "\r$%d", cost)
  251.         }
  252.        
  253.         formatex(item, charsmax(item), "%s \y[%s]", skin[SKIN_NAME], status)
  254.         menu_additem(menu, item)
  255.     }
  256.    
  257.     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  258.     menu_display(id, menu, 0)
  259. }
  260.  
  261. public PlayerSkinMenuHandler(id, menu, item) {
  262.     if (item == MENU_EXIT) {
  263.         ShowMainMenu(id)
  264.         menu_destroy(menu)
  265.         return PLUGIN_HANDLED
  266.     }
  267.    
  268.     new skin[SkinInfo]
  269.     ArrayGetArray(g_PlayerSkins, item, skin)
  270.    
  271.     new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  272.     if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + item)) {
  273.         g_PlayerModelSkin[id] = item
  274.         client_print_color(id, print_team_default, "^4[Skins] ^1You equipped the ^3%s ^1player skin!", skin[SKIN_NAME])
  275.     } else {
  276.         new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
  277.         new cash = get_user_cash(id)
  278.        
  279.         if (cash >= cost) {
  280.             set_user_cash(id, cash - cost)
  281.             g_PlayerModelSkin[id] = item
  282.             if (!playerOwnedSkins) {
  283.                 playerOwnedSkins = ArrayCreate(1)
  284.                 ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
  285.             }
  286.             ArraySetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + item, 1)
  287.             skin[SKIN_PURCHASES]++
  288.             ArraySetArray(g_PlayerSkins, item, skin)
  289.             client_print_color(id, print_team_default, "^4[Skins] ^1You purchased the ^3%s ^1player skin for ^4$%d^1!", skin[SKIN_NAME], cost)
  290.             SavePlayerData(id)
  291.         } else {
  292.             client_print_color(id, print_team_default, "^4[Skins] ^1You don't have enough cash to purchase this skin!")
  293.         }
  294.     }
  295.    
  296.     ShowPlayerSkinMenu(id)
  297.     return PLUGIN_HANDLED
  298. }
  299.  
  300. CalculateSkinCost(baseCost, purchases) {
  301.     return baseCost + (baseCost * purchases * 10 / 100)
  302. }
  303.  
  304. SavePlayerData(id) {
  305.     new authid[32], data[1024]
  306.     get_user_authid(id, authid, charsmax(authid))
  307.    
  308.     new len = formatex(data, charsmax(data), "%d %d ", g_PlayerWeaponSkin[id][0], g_PlayerModelSkin[id])
  309.    
  310.     new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  311.     new totalSkins = ArraySize(g_WeaponSkins) + ArraySize(g_PlayerSkins)
  312.     for (new i = 0; i < totalSkins; i++) {
  313.         len += formatex(data[len], charsmax(data) - len, "%d ", playerOwnedSkins && ArrayGetCell(playerOwnedSkins, i) ? 1 : 0)
  314.     }
  315.    
  316.     fvault_set_data("PlayerSkins", authid, data)
  317. }
  318.  
  319. LoadPlayerData(id) {
  320.     new authid[32], data[1024]
  321.     get_user_authid(id, authid, charsmax(authid))
  322.     if (fvault_get_data("PlayerSkins", authid, data, charsmax(data))) {
  323.         new weaponSkin[16], playerSkin[16], ownedSkin[8]
  324.        
  325.         new pos = 0
  326.         pos += argparse(data[pos], charsmax(data) - pos, weaponSkin, charsmax(weaponSkin))
  327.         pos += argparse(data[pos], charsmax(data) - pos, playerSkin, charsmax(playerSkin))
  328.        
  329.         g_PlayerWeaponSkin[id][0] = str_to_num(weaponSkin)
  330.         g_PlayerModelSkin[id] = str_to_num(playerSkin)
  331.        
  332.         new Array:playerOwnedSkins = ArrayCreate(1)
  333.         ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
  334.        
  335.         new totalSkins = ArraySize(g_WeaponSkins) + ArraySize(g_PlayerSkins)
  336.         for (new i = 0; i < totalSkins; i++) {
  337.             pos += argparse(data[pos], charsmax(data) - pos, ownedSkin, charsmax(ownedSkin))
  338.             ArrayPushCell(playerOwnedSkins, str_to_num(ownedSkin))
  339.         }
  340.     }
  341. }
  342.  
  343. public client_putinserver(id) {
  344.     LoadPlayerData(id)
  345. }
  346.  
  347. public client_disconnected(id) {
  348.     SavePlayerData(id)
  349.     new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
  350.     if (playerOwnedSkins) {
  351.         ArrayDestroy(playerOwnedSkins)
  352.         ArraySetCell(g_PlayerOwnedSkins, id, 0)
  353.     }
  354. }
  355.  
  356. public PlayerSpawn_Post(id) {
  357.     if (is_user_alive(id)) {
  358.         ApplyPlayerSkin(id)
  359.         ApplyWeaponSkin(id)
  360.     }
  361. }
  362.  
  363. ApplyPlayerSkin(id) {
  364.     if (!is_user_alive(id)) return
  365.    
  366.     new skinIndex = g_PlayerModelSkin[id]
  367.     if (skinIndex >= 0 && skinIndex < ArraySize(g_PlayerSkins)) {
  368.         new skin[SkinInfo]
  369.         ArrayGetArray(g_PlayerSkins, skinIndex, skin)
  370.         cs_set_user_model(id, skin[SKIN_MODEL])
  371.     }
  372. }
  373.  
  374. ApplyWeaponSkin(id) {
  375.     if (!is_user_alive(id)) return
  376.    
  377.     new skinIndex = g_PlayerWeaponSkin[id][0]
  378.     if (skinIndex >= 0 && skinIndex < ArraySize(g_WeaponSkins)) {
  379.         new skin[SkinInfo]
  380.         ArrayGetArray(g_WeaponSkins, skinIndex, skin)
  381.        
  382.         // Apply skin to all weapons the player has
  383.         new weapons[32], num
  384.         get_user_weapons(id, weapons, num)
  385.        
  386.         for (new i = 0; i < num; i++) {
  387.             new weaponEnt = weapons[i]
  388.             if (pev_valid(weaponEnt)) {
  389.                 set_pev(weaponEnt, pev_viewmodel2, skin[SKIN_MODEL])
  390.                 // If you want to change the world model as well, uncomment the following line:
  391.                 // set_pev(weaponEnt, pev_weaponmodel2, skin[SKIN_MODEL])
  392.             }
  393.         }
  394.     }
  395. }
  396.  
  397. stock get_weapon_name(weaponid, name[], len) {
  398.     switch (weaponid) {
  399.         case CSW_AK47: copy(name, len, "AK47")
  400.         case CSW_M4A1: copy(name, len, "M4A1")
  401.         case CSW_AWP: copy(name, len, "AWP")
  402.         case CSW_DEAGLE: copy(name, len, "Desert Eagle")
  403.         // Add more weapons as needed
  404.         default: copy(name, len, "Unknown")
  405.     }
  406. }
  407.  
  408. public Ham_Item_Deploy_Post(weapon_ent) {
  409.     new id = get_pdata_cbase(weapon_ent, 41, 4)
  410.    
  411.     if (!is_user_alive(id)) return
  412.    
  413.     new weaponid = cs_get_weapon_id(weapon_ent)
  414.     new skinIndex = g_PlayerWeaponSkin[id][0]
  415.    
  416.     if (skinIndex >= 0 && skinIndex < ArraySize(g_WeaponSkins)) {
  417.         new skin[SkinInfo]
  418.         ArrayGetArray(g_WeaponSkins, skinIndex, skin)
  419.        
  420.         set_pev(weapon_ent, pev_viewmodel2, skin[SKIN_MODEL])
  421.  
  422.         new weaponName[32]
  423.         get_weapon_name(weaponid, weaponName, charsmax(weaponName))
  424.         client_print_color(id, print_team_default, "^4[Skins] ^1Applied ^3%s ^1skin to your ^3%s^1.", skin[SKIN_NAME], weaponName)
  425.     }
  426. }
  427. // I would appreciate feedback and opinions
  428. // Steam: CheezPuff
  429. // Discord: CheezPuff#7720
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement