Implemented OnItemDrop hook (Hurtworld)

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

  1. 5311

    5311 Naked Wanderer

    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 Grenade Master Community Mod Oxide Developer

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