diff --git a/addons/sourcemod/scripting/include/shop.inc b/addons/sourcemod/scripting/include/shop.inc index d51042e..564732d 100644 --- a/addons/sourcemod/scripting/include/shop.inc +++ b/addons/sourcemod/scripting/include/shop.inc @@ -127,6 +127,7 @@ public void __pl_shop_SetNTVOptional() { MarkNativeAsOptional("Shop_IsStarted"); MarkNativeAsOptional("Shop_UnregisterMe"); + MarkNativeAsOptional("Shop_UnregisterItem"); MarkNativeAsOptional("Shop_ShowItemPanel"); MarkNativeAsOptional("Shop_OpenMainMenu"); MarkNativeAsOptional("Shop_ShowCategory"); diff --git a/addons/sourcemod/scripting/include/shop/items.inc b/addons/sourcemod/scripting/include/shop/items.inc index 652830a..f662295 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 + * + * @noreturn +*/ +native void Shop_UnregisterItem(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..4c40964 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_UnregisterItem", 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];