SampSharp
SampSharp copied to clipboard
player.Vehicle returns EntityID instead of Vehicle
Hi,
Using SampSharp 0.10.1 ECS, player.Vehicle returns SampSharp.Entities.EntityID instead of Vehicle. Is this the intended behaviour? If so how do I retrieve the Vehicle instance from EntityID?
Thanks.
You can get the Vehicle component through the EntityManager.
[PlayerCommand]
public void SampleCommand(Player player, IEntityManager entityManager)
{
var vehicle = entityManager.GetComponent<Vehicle>(player.Vehicle);
}
I think I'll add some helper methods to make this easier in the future (e.g. player.GetVehicle()
)
Thanks! That would be useful addition. In the meantime, I'm using a dictionary with the ID and Vehicle in order to keep track of them. For cleanup purposes mostly.
#415
Closing since a PR has added this extension method.