From b641dda4af0c0e133f36215026c92e62258b316d Mon Sep 17 00:00:00 2001 From: IL0co Date: Wed, 17 Mar 2021 20:22:40 +0200 Subject: [PATCH 1/6] added Shop_UnregisterItemId --- .../scripting/include/shop/items.inc | 9 ++++++++ .../sourcemod/scripting/shop/item_manager.sp | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/addons/sourcemod/scripting/include/shop/items.inc b/addons/sourcemod/scripting/include/shop/items.inc index 652830a..18f5cba 100644 --- a/addons/sourcemod/scripting/include/shop/items.inc +++ b/addons/sourcemod/scripting/include/shop/items.inc @@ -203,6 +203,15 @@ native bool Shop_SetItemCustomInfoString(ItemId item_id, const char[] info, cons */ native bool Shop_KvCopySubKeysItemCustomInfo(ItemId item_id, KeyValues kv); +/** + * Unregisters item, categories and removes them from the shop and players' inventory by ItemId + * + * @param item_id Item id + * + * @return true on success, false otherwise +*/ +native void Shop_UnregisterItemId(ItemId item_id); + /** * Gets an item credits price * diff --git a/addons/sourcemod/scripting/shop/item_manager.sp b/addons/sourcemod/scripting/shop/item_manager.sp index 595ee2a..6765cff 100644 --- a/addons/sourcemod/scripting/shop/item_manager.sp +++ b/addons/sourcemod/scripting/shop/item_manager.sp @@ -45,6 +45,8 @@ void ItemManager_CreateNatives() CreateNative("Shop_SetCallbacks", ItemManager_SetCallbacks); CreateNative("Shop_SetHide", ItemManager_SetHide); CreateNative("Shop_EndItem", ItemManager_EndItem); + + CreateNative("Shop_UnregisterItemId", ItemManager_UnregisterItem); CreateNative("Shop_GetItemCustomInfo", ItemManager_GetItemCustomInfo); CreateNative("Shop_SetItemCustomInfo", ItemManager_SetItemCustomInfo); @@ -576,6 +578,27 @@ public int ItemManager_EndItem(Handle plugin, int numParams) plugin_item[0] = '\0'; } +public int ItemManager_UnregisterItem(Handle plugin, int numParams) +{ + char item[SHOP_MAX_STRING_LENGTH]; + int item_id = GetNativeCell(1); + + Format(item, sizeof(item), "%i", item_id); + + h_KvItems.Rewind(); + if(!h_KvItems.JumpToKey(item)) + ThrowNativeError(SP_ERROR_NATIVE, "Item id %s is invalid", item); + + DataPack dpCallback = view_as(h_KvItems.GetNum("callbacks", 0)); + if(dpCallback != null) + delete dpCallback; + + OnItemUnregistered(item_id); + + h_KvItems.DeleteThis(); + h_KvItems.Rewind(); +} + public int ItemManager_OnItemRegistered(Handle owner, Handle hndl, const char[] error, DataPack dp) { char category[SHOP_MAX_STRING_LENGTH], item[SHOP_MAX_STRING_LENGTH]; From 03830bcc17ad1fc6aebeda177ba8a35bb8d00a4b Mon Sep 17 00:00:00 2001 From: IL0co Date: Wed, 17 Mar 2021 20:29:19 +0200 Subject: [PATCH 2/6] fix native description --- addons/sourcemod/scripting/include/shop/items.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/include/shop/items.inc b/addons/sourcemod/scripting/include/shop/items.inc index 18f5cba..a588b93 100644 --- a/addons/sourcemod/scripting/include/shop/items.inc +++ b/addons/sourcemod/scripting/include/shop/items.inc @@ -208,7 +208,7 @@ native bool Shop_KvCopySubKeysItemCustomInfo(ItemId item_id, KeyValues kv); * * @param item_id Item id * - * @return true on success, false otherwise + * @noreturn */ native void Shop_UnregisterItemId(ItemId item_id); From 541d122664533c729a527446d945e01a18759ef0 Mon Sep 17 00:00:00 2001 From: IL0co Date: Thu, 18 Mar 2021 14:53:49 +0200 Subject: [PATCH 3/6] rename native Shop_UnregisterItemId --- addons/sourcemod/scripting/shop/item_manager.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/shop/item_manager.sp b/addons/sourcemod/scripting/shop/item_manager.sp index 6765cff..4c40964 100644 --- a/addons/sourcemod/scripting/shop/item_manager.sp +++ b/addons/sourcemod/scripting/shop/item_manager.sp @@ -46,7 +46,7 @@ void ItemManager_CreateNatives() CreateNative("Shop_SetHide", ItemManager_SetHide); CreateNative("Shop_EndItem", ItemManager_EndItem); - CreateNative("Shop_UnregisterItemId", ItemManager_UnregisterItem); + CreateNative("Shop_UnregisterItem", ItemManager_UnregisterItem); CreateNative("Shop_GetItemCustomInfo", ItemManager_GetItemCustomInfo); CreateNative("Shop_SetItemCustomInfo", ItemManager_SetItemCustomInfo); From cc8ba324cb716384c43d709d7666abe09480aa61 Mon Sep 17 00:00:00 2001 From: IL0co Date: Thu, 18 Mar 2021 14:54:09 +0200 Subject: [PATCH 4/6] adding to Optional native --- addons/sourcemod/scripting/include/shop.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/include/shop.inc b/addons/sourcemod/scripting/include/shop.inc index d51042e..940bc7c 100644 --- a/addons/sourcemod/scripting/include/shop.inc +++ b/addons/sourcemod/scripting/include/shop.inc @@ -127,7 +127,7 @@ public void __pl_shop_SetNTVOptional() { MarkNativeAsOptional("Shop_IsStarted"); MarkNativeAsOptional("Shop_UnregisterMe"); - MarkNativeAsOptional("Shop_ShowItemPanel"); + MarkNativeAsOptional("Shop_UnregisterItem"); MarkNativeAsOptional("Shop_OpenMainMenu"); MarkNativeAsOptional("Shop_ShowCategory"); MarkNativeAsOptional("Shop_ShowInventory"); From ea1fffe4ad3b138c4dae0ff6ac482f66ec6303fe Mon Sep 17 00:00:00 2001 From: IL0co Date: Thu, 18 Mar 2021 15:02:47 +0200 Subject: [PATCH 5/6] try rename --- addons/sourcemod/scripting/include/shop/items.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/include/shop/items.inc b/addons/sourcemod/scripting/include/shop/items.inc index a588b93..f662295 100644 --- a/addons/sourcemod/scripting/include/shop/items.inc +++ b/addons/sourcemod/scripting/include/shop/items.inc @@ -210,7 +210,7 @@ native bool Shop_KvCopySubKeysItemCustomInfo(ItemId item_id, KeyValues kv); * * @noreturn */ -native void Shop_UnregisterItemId(ItemId item_id); +native void Shop_UnregisterItem(ItemId item_id); /** * Gets an item credits price From 03c12db98c905c23cced139785210b5a1c427165 Mon Sep 17 00:00:00 2001 From: IL0co Date: Thu, 18 Mar 2021 23:16:05 +0200 Subject: [PATCH 6/6] will return Shop_ShowItemPanel --- addons/sourcemod/scripting/include/shop.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sourcemod/scripting/include/shop.inc b/addons/sourcemod/scripting/include/shop.inc index 940bc7c..564732d 100644 --- a/addons/sourcemod/scripting/include/shop.inc +++ b/addons/sourcemod/scripting/include/shop.inc @@ -128,6 +128,7 @@ public void __pl_shop_SetNTVOptional() MarkNativeAsOptional("Shop_IsStarted"); MarkNativeAsOptional("Shop_UnregisterMe"); MarkNativeAsOptional("Shop_UnregisterItem"); + MarkNativeAsOptional("Shop_ShowItemPanel"); MarkNativeAsOptional("Shop_OpenMainMenu"); MarkNativeAsOptional("Shop_ShowCategory"); MarkNativeAsOptional("Shop_ShowInventory");