Fix issues with NPCs
This PR refers to #1158.
Status:
- [x] NPC_SetPos may remove bot from vehicle (solved in 6cac7da)
- [x] NPC doesn't call vehicle events like death or respawn (it deserves another PR)
- [x] NPC_EnableInfiniteAmmo has no effect if NPC_SetAmmo wasn't used (done)
After some debugging of the vehicle death event I observed that:
If a vehicle's health were set at value <= 250 and it has never been occupied by a player in his lifetime (common if you use it with a NPC), the Vehicle::setDead() will never be called, and consequently OnVehicleDeath() will also be missed! This happens because the clients won't send the VehicleDeath's packet (id 136) at the vehicle explosion, because they never entered the vehicle in the first place!
There is another way that the client can inform the vehicle's death to the player: vehicle.cpp:304 where the client can sync vehicles while onfoot. However, after multiple testing, it seems that the condition if (health <= 0.f) is never encoutered because after the explosion (health = 0), the client doesn't send anymore PlayerUnoccupiedSync's packet (id 209).
Side note: unoccupiedSync.SeatID != 0 could be removed because it seems like SeatID is always 0 when the player is on foot. (maybe it is used in some particular cases?)
Can anyone confirm/reject these observations?
@AmyrAhmady, I think it's better that I transform this PR for the infinite ammo improvement for NPC only. The vehicle death it's a separate question (from the observation that I had), and for the "NPC_SetPos issue" I saw that you already commit a fix.
What do you think?
Thanks for your work and attention to my issue. I think the first item in the list can also be completely solved by adding NPC_SetVehiclePos (instead of any changes into NPC_SetPos), so there will be no differences with player manipulation natives.
I edited the PR, now it addresses the infinite ammo behaviour issue.
I think the first item in the list can also be completely solved by adding NPC_SetVehiclePos
I think it's better to separate it with another PR.
Merging this, I'll handle the other two in the rest