广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 954 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x31 鲜花 x69
分享: 转寄此文章 Facebook Plurk Twitter 版主评分版主评分版主评分 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x4
[插件] 使用 OOP 写成的背包系统 API
原创文章

【插件资讯】
插件来源:原创

使用指令:
[CVAR]
inv_default_size 14 // 预设背包的空间

[管理员/伺服器指令]
// 给予玩家道具
inv_give 玩家名 道具的类别名称 给予的数量
inv_give holla shit 5
inv_give holla medkit 1

// 显示伺服器的道具列表
gameitem_list

[玩家指令]
// 打开背包选单
inv_open

安装路径:addons\amxmodx\scripting


【插件介绍】


[安装需求]



主楼 - 基本介绍
1楼 - INC 介绍
2楼 - 使用实例


请注意: 本插件适用于对AMXX编写有一定程度了解的中阶级玩家使用




[影片展示]
按这里检视影片,登入论坛可以直接观看

[图片展示]
背包选单 (不同道具类型可设定不同的堆叠数量)


整理背包的功能 (把道具全部堆到最前面)


选择栏位之后的子选单


使用后





[建议 plugins.ini 排序方法]
复制程式
; 核心
oo_game_item.amxx ; 道具管理器
oo_inventory.amxx ; 背包系统

; 道具
oo_item_medkit.amxx
oo_item_armor.amxx
oo_item_gravity.amxx
oo_item_footstep.amxx
oo_item_godmode.amxx
oo_item_shit.amxx
oo_item_respawn.amxx

; 其他
kill_random_item.amxx ; 杀人获得随机道具 及显示 获得 和 丢弃操作 的讯息
inventory_save.amxx ; 以 steamid 储存背包的道具 (nvault)
;test_game_item_and_inventory.sma ; 用以测试功能有没有运作正常

只有INC及SMA (5 威望)

[此文章售价 10 雅币已有 5 人购买]
若发现会员采用欺骗的方法获取财富,请立刻举报,我们会对会员处以2-N倍的罚金,严重者封掉ID!

威望要 5 以上才可以下载附件,您目前威望不足,请勿购买


[ 此文章被11922911在2024-03-23 19:21重新编辑 ]

此文章被评分,最近评分记录
财富:500 (by amore12) | 理由: 辛苦了!!



YouTube: @holla16
献花 x4 回到顶端 [楼 主] From:香港没有资料 | Posted:2024-03-20 23:25 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x31 鲜花 x69
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

【INC 介绍】
(文章可能未能及时更新内容, 详情看INC为准)
oo_game_item.inc
复制程式
// 使用道具事件
forward oo_on_gameitem_use(id, GameItem:item_o);

// 道具可不可以使用
// return PLUGIN_CONTINUE 为可以, PLUGIN_HANDLED 为不可以
forward oo_on_gameitem_can_use(id, GameItem:item_o);

复制程式
// 初始化道具容器 (可自定义 GameItemManager 类别或物件, 用于如果你已经继承了 GameItemManager 类别并覆写原有类别的东西)
// @param class 容器的类别名称
// @param manager_o 容器的hash
//   若 manager_o 不是 @null, 将使用 manger_o 作为容器
//   否则使用 class 的 GetInstance() 方法来获取容器的hash
// @return 该物件的hash
stock GameItemManager:oo_gameitem_init(const class[]="GameItemManager", GameItemManager:manager_o=@null)

复制程式
// 加入新道具到容器
// @param item_o 道具的hash
// @return 加入的索引位置
stock oo_gameitem_add(GameItem:item_o)

// 从容器中移除道具
// @param index 索引位置
// @param delete 是否也删除物件
//   若 delete=true 则同时删除物件
// @noreturn
stock oo_gameitem_remove(index, bool:delete=false)

复制程式
// 从容器中获取道具的阵列
// @return 阵列的 array id
stock Array:oo_gameitem_get_items()

// 从容器中获取道具的数量
// @return 道具的数量
stock oo_gameitem_get_count()

复制程式
// 从容器中以类别名称搜寻道具所在的索引位置
// @param class 类别的名称
// @return 索引位置
stock oo_gameitem_find_index(const class[])

// 从容器中以类别名称搜寻道具的hash
// @param class 类别的名称
// @return 道具的hash
stock GameItem:oo_gameitem_find_obj(const class[])

复制程式
// 从容器中以指定索引位置存取道具的hash
// @param class 索引位置
// @return 道具的hash
stock GameItem:oo_gameitem_at(index)

// 从容器中移除所有道具
// @param delete 是否也删除物件
//   若 delete=true 则同时删除所有物件
// @noreturn
stock oo_gameitem_clear(bool:delete=false)

复制程式
// 获取道具的名称
// @param item_o 道具的hash
// @param name 输出的字串
// @param maxlen 字串长度
// @noreturn
stock oo_gameitem_get_name(GameItem:item_o, name[], maxlen)

复制程式
// 获取道具的注解
// @param item_o 道具的hash
// @param name 输出的字串
// @param maxlen 字串长度
// @noreturn
stock oo_gameitem_get_desc(GameItem:item_o, name[], maxlen)

复制程式
// 获取道具的类别名称
// @param item_o 道具的hash
// @param name 输出的字串
// @param maxlen 字串长度
// @noreturn
stock oo_gameitem_get_class(GameItem:item_o, name[], maxlen)

复制程式
// 获取道具的堆叠数量
// @param item_o 道具的hash
// @return 堆叠数量
stock oo_gameitem_get_stacks(GameItem:item_o)




oo_inventory.inc
复制程式
// 建立背包实例的事件
// 在 forward 中 return PLUGIN_HANDLE 可以阻止原有的事件, 
// 然后可使用 oo_inventory_set_instance() 取代原有的实例
// 以上方法用于如果你继承了新的 PlayerInventory 类别, 想使用新的类别作为实例
forward oo_on_inventory_new(id);

复制程式
// 背包的建构事件
forward oo_on_inventory_ctor(id);

// 背包的解构事件
forward oo_on_inventory_dtor(id);

// 背包给予道具事件
forward oo_on_inventory_give(id, GameItem:item_o, amount);

// 背包选项进行事件
// return PLUGIN_HANDLE 可阻止事件进行
forward oo_on_inventory_perform_option(id, option, slot);

复制程式
// 给道具进背包
// @param id 玩家
// @param item_o 道具的hash
// @param amount 给予的数量
// @param check_space 是否先检查有没有足够空间, 若空间不足则不给予
// @return 给了多少个
stock oo_inventory_give_item(id, GameItem:item_o, amount=1, bool:check_space=false)

复制程式
// 移除指定背包栏位的道具
// @param id 玩家
// @param slot 栏位的索引位置
// @param amount 移除的数量, 若为 0 则移除该栏位的全部
// @noreturn 
stock oo_inventory_remove_slot(id, slot, amount=0)

// 移除背包中的指定一种道具
// @param id 玩家
// @param item_o 道具的hash
// @param amount 移除的数量
// @return 移除了多少个 
stock oo_inventory_remove_item(id, GameItem:item_o, amount=1)

复制程式
// 计算背包中指定一种道具的数量
// @param id 玩家
// @param item_o 道具的hash
// @return 计算后的数量
stock oo_inventory_count_item(id, GameItem:item_o)

// 整理背包
// @param id 玩家
// @noreturn 
stock oo_inventory_organize(id)

复制程式
// 复制背包内容
// @param id 玩家
// @param inventory_o 要被复制的背包的hash
// @param resize 是否改变背包大小 (若玩家背包大小跟要被复制的背包大小不一样)
// @noreturn
stock oo_inventory_copy(id, PlayerInventory:inventory_o, bool:resize=false)

复制程式
// 获取背包的大小
// @param id 玩家
// @noreturn
stock oo_inventory_get_size(id)

// 清空背包
// @param id 玩家
// @noreturn
stock oo_inventory_clear(id)

复制程式
// 获取背包中指定栏位中的资料 (包括道具hash 和 堆叠数量)
// @param id 玩家
// @param slot_id 栏位的索引位置
// @param slot_data 栏位的资料 (详见 oo_inventory_const.inc 的 PlayerInventorySlot)
// @noreturn
stock oo_inventory_get(id, slot_id, slot_data[PlayerInventorySlot])

复制程式
// 改变背包中指定栏位中的资料 (包括道具hash 和 堆叠数量)
// @param id 玩家
// @param slot_id 栏位的索引位置
// @param slot_data 栏位的资料 (详见 oo_inventory_const.inc 的 PlayerInventorySlot)
// @noreturn
stock oo_inventory_set(id, slot_id, slot_data[PlayerInventorySlot])

复制程式
// 显示背包选单
// @param id 玩家
// @param page 显示页数
// @param time 显示时间 (若为 -1 则永久显示)
// @return 选单的id
stock oo_inventory_show_menu(id, page=0, time=-1)

复制程式
// 获取背包的操作选项
// @param id 玩家
// @param options 输出到的阵列
// @noreturn
stock oo_inventory_get_options(id, options[MAX_INVENTORY_OPTIONS])

复制程式
// 进行背包的选项
// @param id 玩家
// @param option_id 选项的id
// @param slot_id 背包栏位的id
// @return false 为进行失败, true 则为成功
stock bool:oo_inventory_perform_option(id, option_id, slot_id)

复制程式
// 获取背包的实例
// @param id 玩家
// @return 实例的hash
stock PlayerInventory:oo_inventory_get_instance(id)

// 改变背包的实例
// @param id 玩家
// @param instance_o 实例的hash
// @noreturn
stock oo_inventory_set_instance(id, PlayerInventory:instance_o)


[ 此文章被11922911在2024-03-23 12:57重新编辑 ]


YouTube: @holla16
献花 x0 回到顶端 [1 楼] From:香港没有资料 | Posted:2024-03-20 23:25 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x31 鲜花 x69
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

【使用实例】
让我们来试试加入一个新道具 oo_item_shit.sma
复制程式
#include <amxmodx>
#include <fun>
#include <oo_game_item>

new GameItem:g_oItem; // 用以记录道具的 hash

public plugin_init()
{
       register_plugin("GameItem: Shit", "0.1", "holla");

       oo_gameitem_init(); // 初始化容器

       // oo_new("GameItem", 类别名称, 道具显示名称, 注解, 堆叠数量)
       g_oItem = oo_new("GameItem", "shit", "屎", "使用就知道效果", 3);
       oo_gameitem_add(g_oItem); // 加入道具到容器
}

// 判定道具能不能使用
public oo_on_gameitem_can_use(id, GameItem:item_o)
{
       if (item_o == g_oItem) // 检查道具 hash
       {
              if (!is_user_alive(id)) // 玩家已死亡
              {
                     client_print(id, print_chat, "只有生存时才能使用");
                     return PLUGIN_HANDLED; // 不能使用
              }
       }

       return PLUGIN_CONTINUE; // 可以使用
}

// 使用道具的动作
public oo_on_gameitem_use(id, GameItem:item_o)
{
       if (item_o == g_oItem) // 检查道具 hash
       {
              user_kill(id); // 处死玩家
              client_print(0, print_chat, "%n 吃了屎臭得自己也昏了", id);
       }
}

给予玩家5个屎的方法:

复制程式
new GameItem:shit_o = oo_gameitem_find_obj("shit");
oo_inventory_give_item(id, shit_o, 5);

试写杀人获得随机物品 kill_random_item.sma
复制程式
#include <amxmodx>
#include <hamsandwich>
#include <oo_inventory>

public plugin_init()
{
       register_plugin("Kill Random Item", "0.1", "holla");

       oo_gameitem_init() // 容器初始化

       RegisterHam(Ham_Killed, "player", "OnPlayerKilled_Post", 1); // 注册事件
}

// 玩家被杀
public OnPlayerKilled_Post(id, killer)
{
       if (id != killer)
       {
              // 给予杀手道具随机的道具
              oo_inventory_give_item(killer, oo_gameitem_at(random(oo_gameitem_get_count())));
       }
}

// 背包给予道具的事件
public oo_on_inventory_give(id, GameItem:item_o, amount)
{
       static name[32];
       oo_gameitem_get_name(item_o, name, charsmax(name)); // 获取道具的名称
       client_print(0, print_chat, "%n 获得了 %s x %d", id, name, amount);
}

// 背包选项进行事件
public oo_on_inventory_perform_option(id, option, slot)
{
       // 预设是 (0 = 使用, 1 = 丢弃一个, 2 = 丢弃栏位全部)
       if (option == 1 || option == 2)
       {
              new slot_data[PlayerInventorySlot];
              oo_inventory_get(id, slot, slot_data);

              new amount = (option == 1) ? 1 : slot_data[PIS_Count];

              static name[32];
              oo_gameitem_get_name(slot_data[PIS_Item], name, charsmax(name)); // 获取道具的名称
              client_print(id, print_chat, "你丢弃了 %s x %d", name, amount);
       }
}

试写要用nvault保存玩家的道具 inventory_save.sma
复制程式
#include <amxmodx>
#include <nvault>
#include <oo_inventory>

new g_Vault;

public plugin_init()
{
       register_plugin("Inventory Save", "0.1", "holla");
       oo_gameitem_init();
       g_Vault = nvault_open("inventory");
}

public plugin_end()
{
       nvault_close(g_Vault);
}

public client_putinserver(id)
{
       static data[512], arg[2][32], authid[50];
       get_user_authid(id, authid, charsmax(authid));

       if (nvault_get(g_Vault, authid, data, charsmax(data)))
       {
              new size = oo_inventory_get_size(id);
              new slot[PlayerInventorySlot], GameItem:item_o;
              for (new i = 0; i < size; i++)
              {
                     if (argbreak(data, arg[0], charsmax(arg[]), data, charsmax(data)) == -1) break;
                     if (argbreak(data, arg[1], charsmax(arg[]), data, charsmax(data)) == -1) break;

                     item_o = oo_gameitem_find_obj(arg[0]);
                     if (item_o != @null)
                     {
                            slot[PIS_Item] = item_o;
                            slot[PIS_Count] = str_to_num(arg[1]);
                            oo_inventory_set(id, i, slot);
                     }
              }
       }
}

public oo_on_inventory_dtor(id)
{
       static data[512], class[32], authid[50];

       new len = 0;
       new slot[PlayerInventorySlot]
       new size = oo_inventory_get_size(id);
       for (new i = 0; i < size; i++)
       {
              oo_inventory_get(id, i, slot);
              if (slot[PIS_Item] == @null)
                     copy(class, charsmax(class), "^"^"");
              else
                     oo_gameitem_get_class(slot[PIS_Item], class, charsmax(class));

              len += formatex(data[len], charsmax(data)-len, "%s %d ", class, slot[PIS_Count]);
       }

       get_user_authid(id, authid, charsmax(authid));
       nvault_set(g_Vault, authid, data);
}


[ 此文章被11922911在2024-03-21 18:03重新编辑 ]

此文章被评分,最近评分记录
威望:5 (by amore12) | 理由: 辛苦了!!


YouTube: @holla16
献花 x3 回到顶端 [2 楼] From:香港没有资料 | Posted:2024-03-20 23:26 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x31 鲜花 x69
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

其实还有更进阶的用法, 但我懒得打, 等有一天我想打再打出来 表情


YouTube: @holla16
献花 x0 回到顶端 [3 楼] From:香港没有资料 | Posted:2024-03-20 23:40 |
11922911
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖 社区建设奖
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x31 鲜花 x69
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

预留 5


YouTube: @holla16
献花 x0 回到顶端 [4 楼] From:香港没有资料 | Posted:2024-03-21 00:09 |
cyxnzb 会员卡
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x0 鲜花 x6
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

表情 东西不错哦,虽然好像在哪见过类似的,但是这个API挺新颖的说


献花 x0 回到顶端 [5 楼] From:安徽 | Posted:2024-03-23 10:42 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.018132 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言