Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- שחקן מקליד בצ'אט "/skins".
- נפתח תפריט ראשי עם האפשרויות "Weapon Skins" ו-"Player Model Skins".
- בתחתית התפריט מוצג סכום הכסף של השחקן.
- תפריט Weapon Skins:
- השחקן רואה רשימה של סקינים לנשק, למשל:
- Default [Owned]
- Gold [$1000]
- סקינים שכבר נרכשו מסומנים כ-"Owned".
- סקינים שעדיין לא נרכשו מציגים את מחירם.
- רכישת סקין לנשק:
- השחקן בוחר סקין שעדיין לא רכש.
- אם יש לו מספיק כסף, הסקין נרכש והודעה מופיעה בצ'אט:
- "You purchased the Gold weapon skin for $1000!"
- הסקין מוחל מיד על הנשק של השחקן.
- תפריט Player Model Skins:
- דומה לתפריט הנשקים, אבל עבור מודלים של שחקנים.
- למשל: Default [Owned], VIP [$2000]
- רכישת סקין למודל שחקן:
- בחירת סקין תגרום לרכישה אם יש מספיק כסף.
- הודעה תופיע בצ'אט: "You purchased the VIP player skin for $2000!"
- המודל החדש יוחל מיד על השחקן.
- שימוש בסקינים:
- בכל פעם שהשחקן מתחיל סיבוב חדש, הסקינים שנבחרו (לנשק ולמודל) יוחלו אוטומטית.
- שחקנים אחרים יראו את המודל החדש של השחקן.
- השחקן יראה את הסקין החדש של הנשק שלו.
- */
- #include <amxmodx>
- #include <amxmisc>
- #include <cstrike>
- #include <fakemeta>
- #include <fvault>
- #include <hamsandwich>
- #define PLUGIN "Skin Menu"
- #define VERSION "1.9"
- #define AUTHOR "CheezPuff"
- #define MAX_PLAYERS 32
- #define MAX_WEAPON_TYPES 5
- #define MAX_WEAPON_SKINS 10
- #define MAX_PLAYER_SKINS 5
- enum _:SkinInfo {
- SKIN_NAME[32],
- SKIN_COST,
- SKIN_MODEL[128],
- SKIN_PURCHASES
- }
- new const g_WeaponSkinsData[MAX_WEAPON_SKINS][SkinInfo] = {
- {"Golden AK47", 1000, "models/custom_weapons/v_ak47_gold.mdl", 0},
- {"Neon AK47", 2000, "models/custom_weapons/v_ak47_neon.mdl", 0},
- {"Flames M4A1", 1500, "models/custom_weapons/v_m4a1_flames.mdl", 0},
- {"Diamond AWP", 3000, "models/custom_weapons/v_awp_diamond.mdl", 0},
- {"Lava Deagle", 1200, "models/custom_weapons/v_deagle_lava.mdl", 0},
- {"", 0, "", 0},
- {"", 0, "", 0},
- {"", 0, "", 0},
- {"", 0, "", 0},
- {"", 0, "", 0}
- }
- new const g_PlayerSkinsData[MAX_PLAYER_SKINS][SkinInfo] = {
- {"VIP", 2000, "models/player/vip/vip.mdl", 0},
- {"Zombie", 3000, "models/player/zombie/zombie.mdl", 0},
- {"Ninja", 2500, "models/player/ninja/ninja.mdl", 0},
- {"Robot", 3500, "models/player/robot/robot.mdl", 0},
- {"Alien", 4000, "models/player/alien/alien.mdl", 0}
- }
- new Array:g_WeaponSkins
- new Array:g_PlayerSkins
- new g_PlayerWeaponSkin[MAX_PLAYERS + 1][MAX_WEAPON_TYPES]
- new g_PlayerModelSkin[MAX_PLAYERS + 1]
- new Array:g_PlayerOwnedSkins
- native get_user_cash(id);
- native set_user_cash(id, amount);
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- register_clcmd("say /skins", "Cmd_ShowSkinMenu")
- register_clcmd("say /knifes", "Cmd_ShowSkinMenu")
- RegisterHam(Ham_Spawn, "player", "PlayerSpawn_Post", 1)
- RegisterHam(Ham_Item_Deploy, "weapon_*", "Ham_Item_Deploy_Post", 1)
- g_WeaponSkins = ArrayCreate(SkinInfo)
- g_PlayerSkins = ArrayCreate(SkinInfo)
- g_PlayerOwnedSkins = ArrayCreate(1, MAX_PLAYERS + 1)
- LoadSkinsFromConstants()
- }
- LoadSkinsFromConstants() {
- for (new i = 0; i < MAX_WEAPON_SKINS; i++) {
- if (g_WeaponSkinsData[i][SKIN_NAME][0]) {
- ArrayPushArray(g_WeaponSkins, g_WeaponSkinsData[i])
- }
- }
- for (new i = 0; i < MAX_PLAYER_SKINS; i++) {
- if (g_PlayerSkinsData[i][SKIN_NAME][0]) {
- ArrayPushArray(g_PlayerSkins, g_PlayerSkinsData[i])
- }
- }
- }
- public plugin_precache() {
- for (new i = 0; i < MAX_WEAPON_SKINS; i++) {
- if (g_WeaponSkinsData[i][SKIN_MODEL][0]) {
- precache_model(g_WeaponSkinsData[i][SKIN_MODEL])
- }
- }
- for (new i = 0; i < MAX_PLAYER_SKINS; i++) {
- if (g_PlayerSkinsData[i][SKIN_MODEL][0]) {
- precache_model(g_PlayerSkinsData[i][SKIN_MODEL])
- }
- }
- }
- public Cmd_ShowSkinMenu(id) {
- ShowMainMenu(id)
- return PLUGIN_HANDLED
- }
- ShowMainMenu(id) {
- new menu = menu_create("\rSkin Menu", "MainMenuHandler")
- menu_additem(menu, "\wWeapon Skins")
- menu_additem(menu, "\wPlayer Model Skins")
- new info[64]
- formatex(info, charsmax(info), "\yCash: $%d", get_user_cash(id))
- menu_addtext(menu, info, 0)
- menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
- menu_display(id, menu, 0)
- }
- public MainMenuHandler(id, menu, item) {
- if (item == MENU_EXIT) {
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- switch(item) {
- case 0: ShowWeaponSkinMenu(id)
- case 1: ShowPlayerSkinMenu(id)
- }
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- ShowWeaponSkinMenu(id) {
- new menu = menu_create("\rWeapon Skins", "WeaponSkinMenuHandler")
- new skin[SkinInfo]
- for (new i = 0; i < ArraySize(g_WeaponSkins); i++) {
- ArrayGetArray(g_WeaponSkins, i, skin)
- new item[64], status[16]
- new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, i)) {
- copy(status, charsmax(status), "\yOwned")
- } else {
- formatex(status, charsmax(status), "\r$%d", cost)
- }
- formatex(item, charsmax(item), "%s \y[%s]", skin[SKIN_NAME], status)
- menu_additem(menu, item)
- }
- menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
- menu_display(id, menu, 0)
- }
- public WeaponSkinMenuHandler(id, menu, item) {
- if (item == MENU_EXIT) {
- ShowMainMenu(id)
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- new skin[SkinInfo]
- ArrayGetArray(g_WeaponSkins, item, skin)
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, item)) {
- g_PlayerWeaponSkin[id][0] = item
- client_print_color(id, print_team_default, "^4[Skins] ^1You equipped the ^3%s^1!", skin[SKIN_NAME])
- } else {
- new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
- new cash = get_user_cash(id)
- if (cash >= cost) {
- set_user_cash(id, cash - cost)
- g_PlayerWeaponSkin[id][0] = item
- if (!playerOwnedSkins) {
- playerOwnedSkins = ArrayCreate(1)
- ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
- }
- ArraySetCell(playerOwnedSkins, item, 1)
- skin[SKIN_PURCHASES]++
- ArraySetArray(g_WeaponSkins, item, skin)
- client_print_color(id, print_team_default, "^4[Skins] ^1You purchased the ^3%s ^1for ^4$%d^1!", skin[SKIN_NAME], cost)
- SavePlayerData(id)
- } else {
- client_print_color(id, print_team_default, "^4[Skins] ^1You don't have enough cash to purchase this skin!")
- }
- }
- ShowWeaponSkinMenu(id)
- return PLUGIN_HANDLED
- }
- ShowPlayerSkinMenu(id) {
- new menu = menu_create("\rPlayer Model Skins", "PlayerSkinMenuHandler")
- new skin[SkinInfo]
- for (new i = 0; i < ArraySize(g_PlayerSkins); i++) {
- ArrayGetArray(g_PlayerSkins, i, skin)
- new item[64], status[16]
- new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + i)) {
- copy(status, charsmax(status), "\yOwned")
- } else {
- formatex(status, charsmax(status), "\r$%d", cost)
- }
- formatex(item, charsmax(item), "%s \y[%s]", skin[SKIN_NAME], status)
- menu_additem(menu, item)
- }
- menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
- menu_display(id, menu, 0)
- }
- public PlayerSkinMenuHandler(id, menu, item) {
- if (item == MENU_EXIT) {
- ShowMainMenu(id)
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- new skin[SkinInfo]
- ArrayGetArray(g_PlayerSkins, item, skin)
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- if (playerOwnedSkins && ArrayGetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + item)) {
- g_PlayerModelSkin[id] = item
- client_print_color(id, print_team_default, "^4[Skins] ^1You equipped the ^3%s ^1player skin!", skin[SKIN_NAME])
- } else {
- new cost = CalculateSkinCost(skin[SKIN_COST], skin[SKIN_PURCHASES])
- new cash = get_user_cash(id)
- if (cash >= cost) {
- set_user_cash(id, cash - cost)
- g_PlayerModelSkin[id] = item
- if (!playerOwnedSkins) {
- playerOwnedSkins = ArrayCreate(1)
- ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
- }
- ArraySetCell(playerOwnedSkins, ArraySize(g_WeaponSkins) + item, 1)
- skin[SKIN_PURCHASES]++
- ArraySetArray(g_PlayerSkins, item, skin)
- client_print_color(id, print_team_default, "^4[Skins] ^1You purchased the ^3%s ^1player skin for ^4$%d^1!", skin[SKIN_NAME], cost)
- SavePlayerData(id)
- } else {
- client_print_color(id, print_team_default, "^4[Skins] ^1You don't have enough cash to purchase this skin!")
- }
- }
- ShowPlayerSkinMenu(id)
- return PLUGIN_HANDLED
- }
- CalculateSkinCost(baseCost, purchases) {
- return baseCost + (baseCost * purchases * 10 / 100)
- }
- SavePlayerData(id) {
- new authid[32], data[1024]
- get_user_authid(id, authid, charsmax(authid))
- new len = formatex(data, charsmax(data), "%d %d ", g_PlayerWeaponSkin[id][0], g_PlayerModelSkin[id])
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- new totalSkins = ArraySize(g_WeaponSkins) + ArraySize(g_PlayerSkins)
- for (new i = 0; i < totalSkins; i++) {
- len += formatex(data[len], charsmax(data) - len, "%d ", playerOwnedSkins && ArrayGetCell(playerOwnedSkins, i) ? 1 : 0)
- }
- fvault_set_data("PlayerSkins", authid, data)
- }
- LoadPlayerData(id) {
- new authid[32], data[1024]
- get_user_authid(id, authid, charsmax(authid))
- if (fvault_get_data("PlayerSkins", authid, data, charsmax(data))) {
- new weaponSkin[16], playerSkin[16], ownedSkin[8]
- new pos = 0
- pos += argparse(data[pos], charsmax(data) - pos, weaponSkin, charsmax(weaponSkin))
- pos += argparse(data[pos], charsmax(data) - pos, playerSkin, charsmax(playerSkin))
- g_PlayerWeaponSkin[id][0] = str_to_num(weaponSkin)
- g_PlayerModelSkin[id] = str_to_num(playerSkin)
- new Array:playerOwnedSkins = ArrayCreate(1)
- ArraySetCell(g_PlayerOwnedSkins, id, playerOwnedSkins)
- new totalSkins = ArraySize(g_WeaponSkins) + ArraySize(g_PlayerSkins)
- for (new i = 0; i < totalSkins; i++) {
- pos += argparse(data[pos], charsmax(data) - pos, ownedSkin, charsmax(ownedSkin))
- ArrayPushCell(playerOwnedSkins, str_to_num(ownedSkin))
- }
- }
- }
- public client_putinserver(id) {
- LoadPlayerData(id)
- }
- public client_disconnected(id) {
- SavePlayerData(id)
- new Array:playerOwnedSkins = ArrayGetCell(g_PlayerOwnedSkins, id)
- if (playerOwnedSkins) {
- ArrayDestroy(playerOwnedSkins)
- ArraySetCell(g_PlayerOwnedSkins, id, 0)
- }
- }
- public PlayerSpawn_Post(id) {
- if (is_user_alive(id)) {
- ApplyPlayerSkin(id)
- ApplyWeaponSkin(id)
- }
- }
- ApplyPlayerSkin(id) {
- if (!is_user_alive(id)) return
- new skinIndex = g_PlayerModelSkin[id]
- if (skinIndex >= 0 && skinIndex < ArraySize(g_PlayerSkins)) {
- new skin[SkinInfo]
- ArrayGetArray(g_PlayerSkins, skinIndex, skin)
- cs_set_user_model(id, skin[SKIN_MODEL])
- }
- }
- ApplyWeaponSkin(id) {
- if (!is_user_alive(id)) return
- new skinIndex = g_PlayerWeaponSkin[id][0]
- if (skinIndex >= 0 && skinIndex < ArraySize(g_WeaponSkins)) {
- new skin[SkinInfo]
- ArrayGetArray(g_WeaponSkins, skinIndex, skin)
- // Apply skin to all weapons the player has
- new weapons[32], num
- get_user_weapons(id, weapons, num)
- for (new i = 0; i < num; i++) {
- new weaponEnt = weapons[i]
- if (pev_valid(weaponEnt)) {
- set_pev(weaponEnt, pev_viewmodel2, skin[SKIN_MODEL])
- // If you want to change the world model as well, uncomment the following line:
- // set_pev(weaponEnt, pev_weaponmodel2, skin[SKIN_MODEL])
- }
- }
- }
- }
- stock get_weapon_name(weaponid, name[], len) {
- switch (weaponid) {
- case CSW_AK47: copy(name, len, "AK47")
- case CSW_M4A1: copy(name, len, "M4A1")
- case CSW_AWP: copy(name, len, "AWP")
- case CSW_DEAGLE: copy(name, len, "Desert Eagle")
- // Add more weapons as needed
- default: copy(name, len, "Unknown")
- }
- }
- public Ham_Item_Deploy_Post(weapon_ent) {
- new id = get_pdata_cbase(weapon_ent, 41, 4)
- if (!is_user_alive(id)) return
- new weaponid = cs_get_weapon_id(weapon_ent)
- new skinIndex = g_PlayerWeaponSkin[id][0]
- if (skinIndex >= 0 && skinIndex < ArraySize(g_WeaponSkins)) {
- new skin[SkinInfo]
- ArrayGetArray(g_WeaponSkins, skinIndex, skin)
- set_pev(weapon_ent, pev_viewmodel2, skin[SKIN_MODEL])
- new weaponName[32]
- get_weapon_name(weaponid, weaponName, charsmax(weaponName))
- client_print_color(id, print_team_default, "^4[Skins] ^1Applied ^3%s ^1skin to your ^3%s^1.", skin[SKIN_NAME], weaponName)
- }
- }
- // I would appreciate feedback and opinions
- // Steam: CheezPuff
- // Discord: CheezPuff#7720
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement