廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 808 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為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.027371 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言