#include "amxmodx"\n#include "amxmisc"\n#include "amxmisc"\n\nnew const PLUGIN_NAME[] = "商店插件";\nnew const PLUGIN_VERSION[] = "1.0";\n\n// 商店物品结构体\nenum ShopItem\n{\n SHOP_ITEM_NAME_MAX = 32,\n SHOP_ITEM_DESCRIPTION_MAX = 128,\n SHOP_ITEM_PRICE_MAX = 10\n};\n\nnew ShopItem g_shopItems[MAX_SHOP_ITEMS];\n\n// 注册商店物品\nvoid RegisterShopItems()\n{\n // 注册商店物品代码\n // 例如:g_shopItems[0] = { "物品1", "物品1的描述", 100 };\n // g_shopItems[1] = { "物品2", "物品2的描述", 200 };\n}\n\n// 显示商店菜单\npublic ShowShopMenu(id)\n{\n new String[128];\n new shopItemIndex;\n\n // 显示商店物品列表\n for(shopItemIndex = 0; shopItemIndex < MAX_SHOP_ITEMS; shopItemIndex++)\n {\n format(String, sizeof(String), "%d. %s - %s ($%d)", shopItemIndex + 1, g_shopItems[shopItemIndex].name, g_shopItems[shopItemIndex].description, g_shopItems[shopItemIndex].price);\n client_print(id, print_chat, String);\n }\n}\n\n// 购买物品\npublic BuyItem(id, shopItemIndex)\n{\n new price = g_shopItems[shopItemIndex].price;\n\n // 检查玩家余额是否足够购买物品\n if(get_user_money(id) < price)\n {\n client_print(id, print_chat, "你的余额不足,无法购买该物品!");\n return PLUGIN_HANDLED;\n }\n\n // 扣除玩家余额\n set_user_money(id, get_user_money(id) - price);\n\n // 给予玩家物品\n // 例如:give_item(id, "物品1");\n\n client_print(id, print_chat, "物品购买成功!");\n return PLUGIN_HANDLED;\n}\n\n// 插件初始化\npublic plugin_init()\n{\n register_plugin(PLUGIN_NAME, PLUGIN_VERSION, "作者");\n RegisterShopItems();\n}\n\n// 玩家连接\npublic client_connect(id)\n{\n // 注册商店菜单命令\n register_clcmd("shop", "ShowShopMenu", 0);\n}\n\n// 玩家断开连接\npublic client_disconnect(id)\n{\n // 释放玩家内存数据\n // 例如:free_user_data(id);\n}\n\n// 玩家死亡\npublic player_death(id, killer, weapon)\n{\n // 处理玩家死亡逻辑\n return PLUGIN_CONTINUE;\n}\n\n// 玩家伤害\npublic player_damage(victim, attacker, Float:health, armor, weapon, Float:damage)\n{\n // 处理玩家伤害逻辑\n return PLUGIN_CONTINUE;\n}\n\n请注意,以上代码只是一个基本框架,您需要根据自己的需求进行修改和扩展。


原文地址: https://www.cveoy.top/t/topic/poGM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录