Implemented OnItemDrop hook (Hurtworld)

Discussion in 'Feature Suggestions' started by 5311, Jan 25, 2017.

  1. 5311

    5311 Scavenger

    Hi guys.
    I need a hook when player drop a item, any solutions?
     
  2. JimLess

    JimLess Scavenger

    I made and test new hook for my creative server.

    Hook inject in Inventory.DropSlot
    Code (Text):
    public void DropSlot(int slotNumber, Vector3 fromPosition, Vector3 direction)

    {
        if (uLink.Network.isClient)
        {
            base.RPC("RPCDropSlot", uLink.RPCMode.Server, new object[]
            {
                (ushort)slotNumber,
                fromPosition,
                direction
            });
        }
        else
        {
            if (!this.CanTakeItem(slotNumber))
            {
                return;
            }
            if (Interface.CallHook("CanDropSlot", new object[]
            {
                this,
                slotNumber,
                fromPosition,
                direction
            }) != null)
            {
                return;
            }
            ITrackedObject componentByInterface = base.gameObject.GetComponentByInterface<ITrackedObject>();
            GlobalItemManager.SpawnWorldItem(this.Items[slotNumber], fromPosition + new Vector3(0f, 1f, 0f) + direction / 2f, (direction + new Vector3(0f, 0.2f, 0f)) * 8f, componentByInterface);
            this.Items[slotNumber] = null;
        }
        this.Invalidate(false);
    }
     
    Config:
    Code (Text):
            {
              "Type": "Simple",
              "Hook": {
                "InjectionIndex": 30,
                "ReturnBehavior": 1,
                "ArgumentBehavior": 3,
                "ArgumentString": null,
                "HookTypeName": "Simple",
                "Name": "CanDropSlot",
                "HookName": "CanDropSlot",
                "AssemblyName": "Assembly-CSharp.dll",
                "TypeName": "Inventory",
                "Flagged": false,
                "Signature": {
                  "Exposure": 2,
                  "Name": "DropSlot",
                  "ReturnType": "System.Void",
                  "Parameters": [
                    "System.Int32",
                    "UnityEngine.Vector3",
                    "UnityEngine.Vector3"
                  ]
                },
                "MSILHash": "XRQ/swP98t731YcY6ujJtlz0Bn/h837h97S7f2GrpOM=",
                "BaseHookName": null,
                "HookCategory": "Inventory"
              }
            }
    Code example:
    Code (Text):
            object CanDropSlot(Inventory inventory, int slotNumber, Vector3 fromPosition, Vector3 direction)
            {
                Puts($"{slotNumber} {inventory.Items[slotNumber]} {fromPosition} {direction}");

                return true;
            }
    Shall we discuss?
     
  3. alex.priadko2014

    alex.priadko2014 Naked Wanderer

  4. Wulf

    Wulf Community Admin Community Admin Oxide Developer

  5. Mughisi

    Mughisi Community Mod Oxide Developer

    Implemented OnItemDrop(Inventory inventory, int slot) and will be included in the next build.
     
  6. JimLess

    JimLess Scavenger

    There are serious differences in the hooks for itemv2(hurtworld). Please correct it.
    oxide.PNG
    Code (Text):
      {
              "Type": "Simple",
              "Hook": {
                "InjectionIndex": 27,
                "ReturnBehavior": 1,
                "ArgumentBehavior": 4,
                "ArgumentString": "this, a0",
                "HookTypeName": "Simple",
                "Name": "OnItemDrop",
                "HookName": "OnItemDrop",
                "AssemblyName": "Assembly-CSharp.dll",
                "TypeName": "Inventory",
                "Flagged": false,
                "Signature": {
                  "Exposure": 2,
                  "Name": "DropSlot",
                  "ReturnType": "System.Void",
                  "Parameters": [
                    "System.Int32",
                    "UnityEngine.Vector3"
                  ]
                },
                "MSILHash": "76TgVbm4vQdbNV74TBgdReFXnSOHV3D8lAiqrCkOPP0=",
                "BaseHookName": null,
                "HookCategory": "Item"
              }
            },
     
  7. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Those are entirely different hooks. It was changed to be a post hook and an CanDropItem or something like that was added as a pre instead. If a Can hook is available, we do not have a pre and post hook, only a post.
     
  8. JimLess

    JimLess Scavenger

    Sorry i can't find something like CanDropItem. there no such hooks or i missed it?
     
  9. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Hmmm, might have gotten lost when the unstashing and merging, but there is supposed to be one. :p

    I'll get CanDropItem added soon.