Skip to content

Commit

Permalink
Merge pull request #99 from IL0co/unreg_item
Browse files Browse the repository at this point in the history
add Shop_UnregisterItemId native
  • Loading branch information
R1KO authored Mar 23, 2021
2 parents 86bf917 + 03c12db commit 39b0820
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/include/shop.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions addons/sourcemod/scripting/include/shop/items.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
23 changes: 23 additions & 0 deletions addons/sourcemod/scripting/shop/item_manager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<DataPack>(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];
Expand Down

0 comments on commit 39b0820

Please sign in to comment.