CheezPuff

[Free] iGaming DR Custom Shop [By CheezPuff)

Jul 11th, 2024 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.71 KB | None | 0 0
  1. /*
  2. 11/07/2024 v1.1 By CheezPuff (Fuck For Fun ;])
  3. Updated save_player_data and load_player_data functions to include cash and XP.
  4. Helper functions for managing cash and XP.
  5. The update_hud function to display player's cash, XP, and USP level.
  6. A modified event_death function that uses the new cash and XP system.
  7. Updated purchase_usp and upgrade_usp functions to use the new cash system.
  8. */
  9.  
  10. #include <amxmodx>
  11. #include <cstrike>
  12. #include <fakemeta>
  13. #include <hamsandwich>
  14. #include <nvault>
  15. #include <engine>
  16.  
  17. #define PLUGIN "Custom USP Shop"
  18. #define VERSION "1.1"
  19. #define AUTHOR "Ariel - CheezPuff"
  20.  
  21. #define m_pPlayer 41
  22. #define m_flAccuracy 108
  23. #define MAX_PLAYERS 32
  24. #define TASK_SHOWHUD 1000
  25.  
  26. // USP Models
  27. enum {
  28.     USP_DEFAULT,
  29.     USP_SILENCER,
  30.     USP_MATCH,
  31.     USP_EXPERT,
  32.     USP_GUARDIAN,
  33.     MAX_USP_MODELS
  34. }
  35.  
  36. new const g_usp_names[MAX_USP_MODELS][] = {
  37.     "Default USP",
  38.     "USP Silencer",
  39.     "USP Match",
  40.     "USP Expert",
  41.     "USP Guardian"
  42. }
  43.  
  44. new const g_usp_models[MAX_USP_MODELS][] = {
  45.     "models/v_usp.mdl",
  46.     "models/v_usp_silencer.mdl",
  47.     "models/v_usp_match.mdl",
  48.     "models/v_usp_expert.mdl",
  49.     "models/v_usp_guardian.mdl"
  50. }
  51.  
  52. new const g_usp_prices[MAX_USP_MODELS] = {
  53.     0,    // Default USP is free
  54.     1000, // USP Silencer
  55.     2000, // USP Match
  56.     3000, // USP Expert
  57.     4000  // USP Guardian
  58. }
  59.  
  60. // USP Stats
  61. new const g_usp_damage[MAX_USP_MODELS] = {34, 35, 35, 36, 37}
  62. new const g_usp_accuracy[MAX_USP_MODELS] = {65, 68, 70, 72, 75}
  63. new const g_usp_recoil[MAX_USP_MODELS][] = {"High", "Medium", "Medium", "Low", "Very Low"}
  64. new const g_usp_firerate[MAX_USP_MODELS] = {380, 390, 400, 410, 420}
  65.  
  66. new g_player_usp_model[MAX_PLAYERS + 1]
  67. new g_player_usp_level[MAX_PLAYERS + 1]
  68. new g_player_cash[MAX_PLAYERS + 1]
  69. new g_player_xp[MAX_PLAYERS + 1]
  70.  
  71. // Upgrade costs
  72. new const g_upgrade_costs[] = {500, 1000, 1500, 2000, 2500}
  73.  
  74. new g_vault
  75.  
  76. public plugin_init() {
  77.     register_plugin(PLUGIN, VERSION, AUTHOR)
  78.    
  79.     register_clcmd("say /uspshop", "cmd_usp_shop")
  80.    
  81.     RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  82.     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_usp", "fw_WeaponPrimaryAttack_Post", 1)
  83.    
  84.     register_event("DeathMsg", "event_death", "a")
  85.  
  86.     g_vault = nvault_open("usp_shop_data")
  87.     set_task(1.0, "update_hud", TASK_SHOWHUD, .flags = "b")
  88. }
  89.  
  90. public plugin_precache() {
  91.     for (new i = 0; i < MAX_USP_MODELS; i++) {
  92.         precache_model(g_usp_models[i])
  93.     }
  94. }
  95.  
  96. public client_putinserver(id) {
  97.     load_player_data(id)
  98.     set_task(1.0, "update_hud", id + TASK_SHOWHUD, .flags = "b")
  99. }
  100.  
  101. public client_disconnected(id) {
  102.     save_player_data(id)
  103.     remove_task(id + TASK_SHOWHUD)
  104. }
  105.  
  106. public cmd_usp_shop(id) {
  107.     if (!is_user_alive(id)) {
  108.         client_print_color(id, print_team_default, "^4[USP Shop] ^1You must be alive to use the USP shop.")
  109.         return PLUGIN_HANDLED
  110.     }
  111.    
  112.     show_usp_models_menu(id)
  113.     return PLUGIN_HANDLED
  114. }
  115.  
  116. public show_usp_models_menu(id) {
  117.     new menu = menu_create("\wUSP Shop^n\wYour Cash: \r$%d", "menu_handler_models", g_player_cash[id])
  118.    
  119.     new item[100]
  120.     for (new i = 0; i < MAX_USP_MODELS; i++) {
  121.         formatex(item, charsmax(item), "%s \y[$%d]", g_usp_names[i], g_usp_prices[i])
  122.         menu_additem(menu, item, fmt("%d", i))
  123.     }
  124.    
  125.     menu_display(id, menu, 0)
  126. }
  127.  
  128. public menu_handler_models(id, menu, item) {
  129.     if (item == MENU_EXIT) {
  130.         menu_destroy(menu)
  131.         return PLUGIN_HANDLED
  132.     }
  133.    
  134.     new data[6], name[64], access, callback
  135.     menu_item_getinfo(menu, item, access, data, 5, name, 63, callback)
  136.    
  137.     new model = str_to_num(data)
  138.     show_usp_details(id, model)
  139.    
  140.     menu_destroy(menu)
  141.     return PLUGIN_HANDLED
  142. }
  143.  
  144. public show_usp_details(id, model) {
  145.     new menu_title[64]
  146.     formatex(menu_title, charsmax(menu_title), "\yYou are viewing %s", g_usp_names[model])
  147.     new menu = menu_create(menu_title, "menu_handler_usp_details")
  148.    
  149.     new item[100]
  150.     formatex(item, charsmax(item), "\wRequest Level: \y%d", g_player_usp_level[id])
  151.     menu_additem(menu, item)
  152.    
  153.     formatex(item, charsmax(item), "\wYour Cash: \y$%d", g_player_cash[id])
  154.     menu_additem(menu, item)
  155.    
  156.     formatex(item, charsmax(item), "\wUSP Price: \y$%d", g_usp_prices[model])
  157.     menu_additem(menu, item)
  158.    
  159.     menu_additem(menu, "\wView USP Stats")
  160.    
  161.     if (g_player_usp_model[id] == model) {
  162.         if (g_player_usp_level[id] < 5) {
  163.             formatex(item, charsmax(item), "\wUpgrade [\y$%d\w]", g_upgrade_costs[g_player_usp_level[id]])
  164.             menu_additem(menu, item)
  165.         }
  166.     } else {
  167.         menu_additem(menu, "\wPurchase")
  168.     }
  169.    
  170.     menu_display(id, menu, 0)
  171. }
  172.  
  173. public menu_handler_usp_details(id, menu, item) {
  174.     if (item == MENU_EXIT) {
  175.         menu_destroy(menu)
  176.         show_usp_models_menu(id)
  177.         return PLUGIN_HANDLED
  178.     }
  179.    
  180.     new data[6], name[64], access, callback
  181.     menu_item_getinfo(menu, item, access, data, 5, name, 63, callback)
  182.    
  183.     new model = g_player_usp_model[id]
  184.    
  185.     if (equali(name, "View USP Stats")) {
  186.         show_usp_abilities(id, model, g_player_usp_level[id])
  187.     } else if (equali(name, "Upgrade")) {
  188.         upgrade_usp(id)
  189.     } else if (equali(name, "Purchase")) {
  190.         purchase_usp(id, model)
  191.     }
  192.    
  193.     menu_destroy(menu)
  194.     return PLUGIN_HANDLED
  195. }
  196.  
  197. public show_usp_abilities(id, model, level) {
  198.     new menu_title[64]
  199.     formatex(menu_title, charsmax(menu_title), "\y%s - Level %d Stats", g_usp_names[model], level)
  200.     new menu = menu_create(menu_title, "menu_handler_abilities")
  201.    
  202.     new item[100]
  203.     formatex(item, charsmax(item), "\wDamage: \y%d", g_usp_damage[model] + level * 2)
  204.     menu_additem(menu, item)
  205.    
  206.     formatex(item, charsmax(item), "\wAccuracy: \y%d%%", g_usp_accuracy[model] + level * 2)
  207.     menu_additem(menu, item)
  208.    
  209.     formatex(item, charsmax(item), "\wRecoil: \y%s", g_usp_recoil[model])
  210.     menu_additem(menu, item)
  211.    
  212.     formatex(item, charsmax(item), "\wFire Rate: \y%d RPM", g_usp_firerate[model] + level * 10)
  213.     menu_additem(menu, item)
  214.    
  215.     // Deathrun specific abilities
  216.     formatex(item, charsmax(item), "\wWall Bang: \y%s", level >= 3 ? "Enabled" : "Disabled")
  217.     menu_additem(menu, item)
  218.    
  219.     menu_additem(menu, "Back")
  220.    
  221.     menu_display(id, menu, 0)
  222. }
  223.  
  224. public menu_handler_abilities(id, menu, item) {
  225.     menu_destroy(menu)
  226.     show_usp_details(id, g_player_usp_model[id])
  227.     return PLUGIN_HANDLED
  228. }
  229.  
  230. public purchase_usp(id, model) {
  231.     new price = g_usp_prices[model]
  232.    
  233.     if (g_player_cash[id] >= price) {
  234.         g_player_cash[id] -= price
  235.         g_player_usp_model[id] = model
  236.         g_player_usp_level[id] = 0
  237.        
  238.         // Set the USP model
  239.         new weapon = find_ent_by_owner(-1, "weapon_usp", id)
  240.         if (weapon > 0) {
  241.             entity_set_string(weapon, EV_SZ_viewmodel, g_usp_models[model])
  242.             entity_set_string(weapon, EV_SZ_weaponmodel, g_usp_models[model])
  243.         }
  244.        
  245.         client_print_color(id, print_team_default, "^4[USP Shop] ^1You've purchased the %s for $%d", g_usp_names[model], price)
  246.         save_player_data(id)
  247.         show_usp_details(id, model)
  248.     } else {
  249.         client_print_color(id, print_team_default, "^4[USP Shop] ^1You don't have enough cash to purchase this USP model.")
  250.         show_usp_models_menu(id)
  251.     }
  252. }
  253.  
  254. public upgrade_usp(id) {
  255.     new cost = g_upgrade_costs[g_player_usp_level[id]]
  256.    
  257.     if (g_player_usp_level[id] >= 5) {
  258.         client_print_color(id, print_team_default, "^4[USP Shop] ^1Your USP is already at maximum level.")
  259.         show_usp_details(id, g_player_usp_model[id])
  260.         return
  261.     }
  262.    
  263.     if (g_player_cash[id] >= cost) {
  264.         g_player_cash[id] -= cost
  265.         g_player_usp_level[id]++
  266.         client_print_color(id, print_team_default, "^4[USP Shop] ^1USP upgraded to Level %d/5", g_player_usp_level[id])
  267.         save_player_data(id)
  268.     } else {
  269.         client_print_color(id, print_team_default, "^4[USP Shop] ^1You don't have enough cash for this upgrade.")
  270.     }
  271.    
  272.     show_usp_details(id, g_player_usp_model[id])
  273. }
  274.  
  275. public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_bits) {
  276.     if (!is_user_connected(attacker) || get_user_weapon(attacker) != CSW_USP)
  277.         return HAM_IGNORED
  278.    
  279.     new model = g_player_usp_model[attacker]
  280.     new level = g_player_usp_level[attacker]
  281.     new Float:new_damage = float(g_usp_damage[model] + level * 2)
  282.     SetHamParamFloat(4, new_damage)
  283.    
  284.     return HAM_HANDLED
  285. }
  286.  
  287. public fw_WeaponPrimaryAttack_Post(entity) {
  288.     new id = pev(entity, pev_owner)
  289.    
  290.     // Apply recoil reduction based on level
  291.     new Float:recoil = 1.0 - (float(g_player_usp_level[id]) * 0.1)
  292.     set_pdata_float(entity, m_flAccuracy, recoil, 4)
  293. }
  294.  
  295. public event_death() {
  296.     new killer = read_data(1)
  297.     new victim = read_data(2)
  298.    
  299.     if (!is_user_connected(killer) || killer == victim)
  300.         return
  301.    
  302.     new CsTeams:killer_team = cs_get_user_team(killer)
  303.     new CsTeams:victim_team = cs_get_user_team(victim)
  304.    
  305.     if (killer_team == CS_TEAM_T && victim_team == CS_TEAM_CT) {
  306.         // Terrorist killed Counter-Terrorist
  307.         new cash_reward = random_num(100, 500)
  308.         new xp_reward = random_num(10, 50)
  309.         add_user_cash(killer, cash_reward)
  310.         add_user_xp(killer, xp_reward * 2) // Double XP
  311.         client_print_color(killer, print_team_red, "^4[Reward] ^1You received ^3$%d ^1and ^3%d XP ^1for killing a CT!", cash_reward, xp_reward * 2)
  312.     } else if (killer_team == CS_TEAM_CT && victim_team == CS_TEAM_T) {
  313.         // Counter-Terrorist killed Terrorist
  314.         new cash_reward = random_num(50, 250)
  315.         add_user_cash(killer, cash_reward)
  316.         add_user_xp(killer, 1)
  317.         client_print_color(killer, print_team_blue, "^4[Reward] ^1You received ^3$%d ^1and ^31 XP ^1for killing a T!", cash_reward)
  318.     }
  319.    
  320.     save_player_data(killer)
  321. }
  322.  
  323. public update_hud(taskid) {
  324.     new id = taskid - TASK_SHOWHUD
  325.     if (!is_user_connected(id) || !is_user_alive(id))
  326.         return
  327.  
  328.     set_hudmessage(0, 255, 0, 0.02, 0.1, 0, 6.0, 1.0)
  329.     show_hudmessage(id, "Cash: $%d | XP: %d | USP Level: %d", g_player_cash[id], g_player_xp[id], g_player_usp_level[id])
  330. }
  331.  
  332. save_player_data(id) {
  333.     new authid[32], data[64]
  334.     get_user_authid(id, authid, charsmax(authid))
  335.     formatex(data, charsmax(data), "%d %d", g_player_usp_model[id], g_player_usp_level[id])
  336.     nvault_set(g_vault, authid, data)
  337. }
  338.  
  339. load_player_data(id) {
  340.     new authid[32], data[64]
  341.     get_user_authid(id, authid, charsmax(authid))
  342.     if (nvault_get(g_vault, authid, data, charsmax(data))) {
  343.         new model[16], level[16]
  344.         parse(data, model, charsmax(model), level, charsmax(level))
  345.         g_player_usp_model[id] = str_to_num(model)
  346.         g_player_usp_level[id] = str_to_num(level)
  347.         // Set the USP model
  348.         new weapon = find_ent_by_owner(-1, "weapon_usp", id)
  349.         if (weapon > 0) {
  350.             entity_set_string(weapon, EV_SZ_viewmodel, g_usp_models[g_player_usp_model[id]])
  351.             entity_set_string(weapon, EV_SZ_weaponmodel, g_usp_models[g_player_usp_model[id]])
  352.         }
  353.     }
  354. }
  355.  
  356. public plugin_end() {
  357.     nvault_close(g_vault)
  358. }
  359.  
  360. // Helper functions for cash and XP management
  361. stock get_user_cash(id) {
  362.     return g_player_cash[id]
  363. }
  364.  
  365. stock set_user_cash(id, amount) {
  366.     g_player_cash[id] = amount
  367.     save_player_data(id)
  368. }
  369.  
  370. stock add_user_cash(id, amount) {
  371.     g_player_cash[id] += amount
  372.     save_player_data(id)
  373. }
  374.  
  375. stock get_user_xp(id) {
  376.     return g_player_xp[id]
  377. }
  378.  
  379. stock add_user_xp(id, amount) {
  380.     g_player_xp[id] += amount
  381.     save_player_data(id)
  382. }
Add Comment
Please, Sign In to add comment