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.
Getting default item drop position and velocity?
Discussion in 'Rust Development' started by Xianith, Apr 19, 2017.
-
use it:
Code:item.Drop(player.eyes.position, player.eyes.BodyForward() * 2f);
-
Getting:
Code:| Failed to call hook 'OnItemDropped' on plugin 'Fireball 0.0.1' (NullReferenceException: Object reference not set to an instance of an object)
-
It's not about vectors or positions, it's about objects.
Item or player is null -
I'm doing the following
Code: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 by a moderator: Apr 21, 2017 -
1. Why do you create a new object, is not it easier to throw off the existing?
Code:void OnItemDropped(Item item, BaseEntity entity) { if (item.info.shortname == "rock") { BasePlayer player = item.GetOwnerPlayer(); item.Drop(player.eyes.position, player.eyes.BodyForward() * 2f); } }
Code: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); }); } }
-
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? -
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? -
Finally figured this one out.
I was calling the BasePlayer incorrectly. Now I can't mark this as solved 0.o