How to change block active item

How do I prevent changing weapons?

example:

I want to disable 23456 while holding weapon 1.

 

object OnActiveItemChange(BasePlayer player, Item oldItem, uint newItemId)
{
Puts("OnActiveItemChange works!");
return null;
}

return true 
Returning true or false will also change.

void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem)
{
Puts("OnActiveItemChanged works!");
}

This hook "OnActiveItemChange" is called only after the item has already changed so will not block it i beleve.. you could try and set there heldentity back to the old item in the call maybe.

OnActiveItemChange is called when the item is ATTEMPTING to be changed per Umod API docs. OnActiveItemChanged is called once its done. Unless the docs are outdated. 

According to the docs, i think OPs answer lies here:

  • Returning a non-null value cancels default behavior

The issue with active items is that client has some level of independent authority, so you cannot simply manipulate it with a hook. Some plugins use the approach of removing the item for a fraction of a second and then adding it back, in order to deactivate the item. You cannot dictate that the client select an active weapon though.

If you want to prevent the client from selecting another belt item, one trick you could resort to, if you have the patience, is to remove those items from the player's belt, and then draw a UI representing the items. The full solution will be a bit more involved, but this gives you an idea.

phudgee

OnActiveItemChange is called when the item is ATTEMPTING to be changed per Umod API docs. OnActiveItemChanged is called once its done. Unless the docs are outdated. 

According to the docs, i think OPs answer lies here:

  • Returning a non-null value cancels default behavior

But, the action is not canceled.

01rhAs2k2QocURf.jpg WhiteThunder

The issue with active items is that client has some level of independent authority, so you cannot simply manipulate it with a hook. Some plugins use the approach of removing the item for a fraction of a second and then adding it back, in order to deactivate the item. You cannot dictate that the client select an active weapon though.

If you want to prevent the client from selecting another belt item, one trick you could resort to, if you have the patience, is to remove those items from the player's belt, and then draw a UI representing the items. The full solution will be a bit more involved, but this gives you an idea.


I want to lock the belt except for the 0 slot.
I don't know how to refresh.
r8KBNS3t3ZDB7oR.png ambition0419

I want to lock the belt except for the 0 slot.
I don't know how to refresh
You haven't supplied enough information about your use care for any reasonable person to help you.

Can you explain more about why you want to block accessing other belt items? The whole point of the belt items is for quick access. How do you intend for players to be able to use the other belt items when they are blocked? If you don't want to allow using other belt items at all, then you could use the approach of simply disallowing items being placed in those slots. If that doesn't work for your use case, then there are clearly other details about the user experience that you have left out.
cXSGDN4GOqNbYP7.jpg WhiteThunder
You haven't supplied enough information about your use care for any reasonable person to help you.

Can you explain more about why you want to block accessing other belt items? The whole point of the belt items is for quick access. How do you intend for players to be able to use the other belt items when they are blocked? If you don't want to allow using other belt items at all, then you could use the approach of simply disallowing items being placed in those slots. If that doesn't work for your use case, then there are clearly other details about the user experience that you have left out.

I succeeded in locking it, but

Slot 1 is unlocked, but the item disappears.

If you turn it back, the item is still there.

player.inventory.containerBelt.capacity = 1;
player.inventory.SendUpdatedInventory(PlayerInventory.Type.Belt, player.inventory.containerBelt, true);​

I'm making a weapon damage upgrade.