SampSharp icon indicating copy to clipboard operation
SampSharp copied to clipboard

player.Vehicle returns EntityID instead of Vehicle

Open EvilShadeZ opened this issue 2 years ago • 3 comments

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.

EvilShadeZ avatar May 04 '22 17:05 EvilShadeZ

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())

ikkentim avatar May 08 '22 18:05 ikkentim

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.

EvilShadeZ avatar May 09 '22 13:05 EvilShadeZ

#415

y0ung3r avatar Jul 02 '22 17:07 y0ung3r

Closing since a PR has added this extension method.

ikkentim avatar Sep 19 '22 18:09 ikkentim