1. Xianith

    Xianith Scavenger Plugin Developer

    Is there a way to get the default item drop position and item drop velocity? I'm not seeing it in the assembly.

    I see the Vector3 input I'm just trying to get the default vectors for the .Drop call.

    End goal is to shoot flaming rocks out from the player.
     
  2. MalkoR

    MalkoR Wood Hoarder Plugin Developer

    use it:

    Code (Text):
    item.Drop(player.eyes.position, player.eyes.BodyForward() * 2f);
     
  3. Xianith

    Xianith Scavenger Plugin Developer

    Getting:

    Code (Text):
    | Failed to call hook 'OnItemDropped' on plugin 'Fireball 0.0.1' (NullReferenceException: Object reference not set to an instance of an object)
     
  4. MalkoR

    MalkoR Wood Hoarder Plugin Developer

    It's not about vectors or positions, it's about objects.
    Item or player is null
     
  5. Xianith

    Xianith Scavenger Plugin Developer

    I'm doing the following

    Code (Text):
     void OnItemDropped(Item item, BaseEntity entity)
            {
                if (item.info.shortname == "rock")
                {
                    BasePlayer player = item.GetOwnerPlayer();
                    Item newitem = ItemManager.Create(ItemManager.FindItemDefinition("rock"), 1, 0uL);
                    item.Remove(0f);
                    item.RemoveFromContainer();
                    Vector3 velocity = new Vector3(0, 0, 0);
                    newitem.Drop(player.transform.position, player.GetDropVelocity());
                    return;
                }
                else
                {
                    return;
                }

            }
     
     
    Last edited: Apr 21, 2017
  6. MalkoR

    MalkoR Wood Hoarder Plugin Developer

    1. Why do you create a new object, is not it easier to throw off the existing?

    Code (Text):
    void OnItemDropped(Item item, BaseEntity entity)
            {
                if (item.info.shortname == "rock")
                {
                    BasePlayer player = item.GetOwnerPlayer();
                    item.Drop(player.eyes.position, player.eyes.BodyForward() * 2f);
                }
            }
     
    2. Item create is not meaning it's will be an object in worl. So you need to wait before drop it:

    Code (Text):
    void OnItemDropped(Item item, BaseEntity entity)
            {
                if (item.info.shortname == "rock")
                {
                    BasePlayer player = item.GetOwnerPlayer();
                    Item newitem = ItemManager.Create(ItemManager.FindItemDefinition("rock"), 1, 0uL);
                    item.Remove(0f);
                    item.RemoveFromContainer();
                    NextTick(() =>
                    {
                        newitem.Drop(player.eyes.position, player.eyes.BodyForward() * 2f);
                    });
                }
            }
     
  7. Xianith

    Xianith Scavenger Plugin Developer

    Still getting null reference exception :(

    Even with just the long version of what you posted. Is it because the hook is called after the item is dropped and thus it has no owner?
     
  8. Xianith

    Xianith Scavenger Plugin Developer

    I've done some testing and am just hitting a rode block here. It seems that the player will always be null as the item has dropped and does not have an owner anymore...

    I could be wrong but is this something intended with the hook?
     
  9. Xianith

    Xianith Scavenger Plugin Developer

    Finally figured this one out.

    I was calling the BasePlayer incorrectly. Now I can't mark this as solved 0.o