Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 11/07/2024 v1.1 By CheezPuff (Fuck For Fun ;])
- Updated save_player_data and load_player_data functions to include cash and XP.
- Helper functions for managing cash and XP.
- The update_hud function to display player's cash, XP, and USP level.
- A modified event_death function that uses the new cash and XP system.
- Updated purchase_usp and upgrade_usp functions to use the new cash system.
- */
- #include <amxmodx>
- #include <cstrike>
- #include <fakemeta>
- #include <hamsandwich>
- #include <nvault>
- #include <engine>
- #define PLUGIN "Custom USP Shop"
- #define VERSION "1.1"
- #define AUTHOR "Ariel - CheezPuff"
- #define m_pPlayer 41
- #define m_flAccuracy 108
- #define MAX_PLAYERS 32
- #define TASK_SHOWHUD 1000
- // USP Models
- enum {
- USP_DEFAULT,
- USP_SILENCER,
- USP_MATCH,
- USP_EXPERT,
- USP_GUARDIAN,
- MAX_USP_MODELS
- }
- new const g_usp_names[MAX_USP_MODELS][] = {
- "Default USP",
- "USP Silencer",
- "USP Match",
- "USP Expert",
- "USP Guardian"
- }
- new const g_usp_models[MAX_USP_MODELS][] = {
- "models/v_usp.mdl",
- "models/v_usp_silencer.mdl",
- "models/v_usp_match.mdl",
- "models/v_usp_expert.mdl",
- "models/v_usp_guardian.mdl"
- }
- new const g_usp_prices[MAX_USP_MODELS] = {
- 0, // Default USP is free
- 1000, // USP Silencer
- 2000, // USP Match
- 3000, // USP Expert
- 4000 // USP Guardian
- }
- // USP Stats
- new const g_usp_damage[MAX_USP_MODELS] = {34, 35, 35, 36, 37}
- new const g_usp_accuracy[MAX_USP_MODELS] = {65, 68, 70, 72, 75}
- new const g_usp_recoil[MAX_USP_MODELS][] = {"High", "Medium", "Medium", "Low", "Very Low"}
- new const g_usp_firerate[MAX_USP_MODELS] = {380, 390, 400, 410, 420}
- new g_player_usp_model[MAX_PLAYERS + 1]
- new g_player_usp_level[MAX_PLAYERS + 1]
- new g_player_cash[MAX_PLAYERS + 1]
- new g_player_xp[MAX_PLAYERS + 1]
- // Upgrade costs
- new const g_upgrade_costs[] = {500, 1000, 1500, 2000, 2500}
- new g_vault
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- register_clcmd("say /uspshop", "cmd_usp_shop")
- RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
- RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_usp", "fw_WeaponPrimaryAttack_Post", 1)
- register_event("DeathMsg", "event_death", "a")
- g_vault = nvault_open("usp_shop_data")
- set_task(1.0, "update_hud", TASK_SHOWHUD, .flags = "b")
- }
- public plugin_precache() {
- for (new i = 0; i < MAX_USP_MODELS; i++) {
- precache_model(g_usp_models[i])
- }
- }
- public client_putinserver(id) {
- load_player_data(id)
- set_task(1.0, "update_hud", id + TASK_SHOWHUD, .flags = "b")
- }
- public client_disconnected(id) {
- save_player_data(id)
- remove_task(id + TASK_SHOWHUD)
- }
- public cmd_usp_shop(id) {
- if (!is_user_alive(id)) {
- client_print_color(id, print_team_default, "^4[USP Shop] ^1You must be alive to use the USP shop.")
- return PLUGIN_HANDLED
- }
- show_usp_models_menu(id)
- return PLUGIN_HANDLED
- }
- public show_usp_models_menu(id) {
- new menu = menu_create("\wUSP Shop^n\wYour Cash: \r$%d", "menu_handler_models", g_player_cash[id])
- new item[100]
- for (new i = 0; i < MAX_USP_MODELS; i++) {
- formatex(item, charsmax(item), "%s \y[$%d]", g_usp_names[i], g_usp_prices[i])
- menu_additem(menu, item, fmt("%d", i))
- }
- menu_display(id, menu, 0)
- }
- public menu_handler_models(id, menu, item) {
- if (item == MENU_EXIT) {
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- new data[6], name[64], access, callback
- menu_item_getinfo(menu, item, access, data, 5, name, 63, callback)
- new model = str_to_num(data)
- show_usp_details(id, model)
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- public show_usp_details(id, model) {
- new menu_title[64]
- formatex(menu_title, charsmax(menu_title), "\yYou are viewing %s", g_usp_names[model])
- new menu = menu_create(menu_title, "menu_handler_usp_details")
- new item[100]
- formatex(item, charsmax(item), "\wRequest Level: \y%d", g_player_usp_level[id])
- menu_additem(menu, item)
- formatex(item, charsmax(item), "\wYour Cash: \y$%d", g_player_cash[id])
- menu_additem(menu, item)
- formatex(item, charsmax(item), "\wUSP Price: \y$%d", g_usp_prices[model])
- menu_additem(menu, item)
- menu_additem(menu, "\wView USP Stats")
- if (g_player_usp_model[id] == model) {
- if (g_player_usp_level[id] < 5) {
- formatex(item, charsmax(item), "\wUpgrade [\y$%d\w]", g_upgrade_costs[g_player_usp_level[id]])
- menu_additem(menu, item)
- }
- } else {
- menu_additem(menu, "\wPurchase")
- }
- menu_display(id, menu, 0)
- }
- public menu_handler_usp_details(id, menu, item) {
- if (item == MENU_EXIT) {
- menu_destroy(menu)
- show_usp_models_menu(id)
- return PLUGIN_HANDLED
- }
- new data[6], name[64], access, callback
- menu_item_getinfo(menu, item, access, data, 5, name, 63, callback)
- new model = g_player_usp_model[id]
- if (equali(name, "View USP Stats")) {
- show_usp_abilities(id, model, g_player_usp_level[id])
- } else if (equali(name, "Upgrade")) {
- upgrade_usp(id)
- } else if (equali(name, "Purchase")) {
- purchase_usp(id, model)
- }
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- public show_usp_abilities(id, model, level) {
- new menu_title[64]
- formatex(menu_title, charsmax(menu_title), "\y%s - Level %d Stats", g_usp_names[model], level)
- new menu = menu_create(menu_title, "menu_handler_abilities")
- new item[100]
- formatex(item, charsmax(item), "\wDamage: \y%d", g_usp_damage[model] + level * 2)
- menu_additem(menu, item)
- formatex(item, charsmax(item), "\wAccuracy: \y%d%%", g_usp_accuracy[model] + level * 2)
- menu_additem(menu, item)
- formatex(item, charsmax(item), "\wRecoil: \y%s", g_usp_recoil[model])
- menu_additem(menu, item)
- formatex(item, charsmax(item), "\wFire Rate: \y%d RPM", g_usp_firerate[model] + level * 10)
- menu_additem(menu, item)
- // Deathrun specific abilities
- formatex(item, charsmax(item), "\wWall Bang: \y%s", level >= 3 ? "Enabled" : "Disabled")
- menu_additem(menu, item)
- menu_additem(menu, "Back")
- menu_display(id, menu, 0)
- }
- public menu_handler_abilities(id, menu, item) {
- menu_destroy(menu)
- show_usp_details(id, g_player_usp_model[id])
- return PLUGIN_HANDLED
- }
- public purchase_usp(id, model) {
- new price = g_usp_prices[model]
- if (g_player_cash[id] >= price) {
- g_player_cash[id] -= price
- g_player_usp_model[id] = model
- g_player_usp_level[id] = 0
- // Set the USP model
- new weapon = find_ent_by_owner(-1, "weapon_usp", id)
- if (weapon > 0) {
- entity_set_string(weapon, EV_SZ_viewmodel, g_usp_models[model])
- entity_set_string(weapon, EV_SZ_weaponmodel, g_usp_models[model])
- }
- client_print_color(id, print_team_default, "^4[USP Shop] ^1You've purchased the %s for $%d", g_usp_names[model], price)
- save_player_data(id)
- show_usp_details(id, model)
- } else {
- client_print_color(id, print_team_default, "^4[USP Shop] ^1You don't have enough cash to purchase this USP model.")
- show_usp_models_menu(id)
- }
- }
- public upgrade_usp(id) {
- new cost = g_upgrade_costs[g_player_usp_level[id]]
- if (g_player_usp_level[id] >= 5) {
- client_print_color(id, print_team_default, "^4[USP Shop] ^1Your USP is already at maximum level.")
- show_usp_details(id, g_player_usp_model[id])
- return
- }
- if (g_player_cash[id] >= cost) {
- g_player_cash[id] -= cost
- g_player_usp_level[id]++
- client_print_color(id, print_team_default, "^4[USP Shop] ^1USP upgraded to Level %d/5", g_player_usp_level[id])
- save_player_data(id)
- } else {
- client_print_color(id, print_team_default, "^4[USP Shop] ^1You don't have enough cash for this upgrade.")
- }
- show_usp_details(id, g_player_usp_model[id])
- }
- public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_bits) {
- if (!is_user_connected(attacker) || get_user_weapon(attacker) != CSW_USP)
- return HAM_IGNORED
- new model = g_player_usp_model[attacker]
- new level = g_player_usp_level[attacker]
- new Float:new_damage = float(g_usp_damage[model] + level * 2)
- SetHamParamFloat(4, new_damage)
- return HAM_HANDLED
- }
- public fw_WeaponPrimaryAttack_Post(entity) {
- new id = pev(entity, pev_owner)
- // Apply recoil reduction based on level
- new Float:recoil = 1.0 - (float(g_player_usp_level[id]) * 0.1)
- set_pdata_float(entity, m_flAccuracy, recoil, 4)
- }
- public event_death() {
- new killer = read_data(1)
- new victim = read_data(2)
- if (!is_user_connected(killer) || killer == victim)
- return
- new CsTeams:killer_team = cs_get_user_team(killer)
- new CsTeams:victim_team = cs_get_user_team(victim)
- if (killer_team == CS_TEAM_T && victim_team == CS_TEAM_CT) {
- // Terrorist killed Counter-Terrorist
- new cash_reward = random_num(100, 500)
- new xp_reward = random_num(10, 50)
- add_user_cash(killer, cash_reward)
- add_user_xp(killer, xp_reward * 2) // Double XP
- 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)
- } else if (killer_team == CS_TEAM_CT && victim_team == CS_TEAM_T) {
- // Counter-Terrorist killed Terrorist
- new cash_reward = random_num(50, 250)
- add_user_cash(killer, cash_reward)
- add_user_xp(killer, 1)
- client_print_color(killer, print_team_blue, "^4[Reward] ^1You received ^3$%d ^1and ^31 XP ^1for killing a T!", cash_reward)
- }
- save_player_data(killer)
- }
- public update_hud(taskid) {
- new id = taskid - TASK_SHOWHUD
- if (!is_user_connected(id) || !is_user_alive(id))
- return
- set_hudmessage(0, 255, 0, 0.02, 0.1, 0, 6.0, 1.0)
- show_hudmessage(id, "Cash: $%d | XP: %d | USP Level: %d", g_player_cash[id], g_player_xp[id], g_player_usp_level[id])
- }
- save_player_data(id) {
- new authid[32], data[64]
- get_user_authid(id, authid, charsmax(authid))
- formatex(data, charsmax(data), "%d %d", g_player_usp_model[id], g_player_usp_level[id])
- nvault_set(g_vault, authid, data)
- }
- load_player_data(id) {
- new authid[32], data[64]
- get_user_authid(id, authid, charsmax(authid))
- if (nvault_get(g_vault, authid, data, charsmax(data))) {
- new model[16], level[16]
- parse(data, model, charsmax(model), level, charsmax(level))
- g_player_usp_model[id] = str_to_num(model)
- g_player_usp_level[id] = str_to_num(level)
- // Set the USP model
- new weapon = find_ent_by_owner(-1, "weapon_usp", id)
- if (weapon > 0) {
- entity_set_string(weapon, EV_SZ_viewmodel, g_usp_models[g_player_usp_model[id]])
- entity_set_string(weapon, EV_SZ_weaponmodel, g_usp_models[g_player_usp_model[id]])
- }
- }
- }
- public plugin_end() {
- nvault_close(g_vault)
- }
- // Helper functions for cash and XP management
- stock get_user_cash(id) {
- return g_player_cash[id]
- }
- stock set_user_cash(id, amount) {
- g_player_cash[id] = amount
- save_player_data(id)
- }
- stock add_user_cash(id, amount) {
- g_player_cash[id] += amount
- save_player_data(id)
- }
- stock get_user_xp(id) {
- return g_player_xp[id]
- }
- stock add_user_xp(id, amount) {
- g_player_xp[id] += amount
- save_player_data(id)
- }
Add Comment
Please, Sign In to add comment