Skip to content

A couple of issues found with new NPCs #1158

Closed

Description

@NexiusTailer

1. NPC_SetPos may remove bot from vehicle
The first issue with NPC_SetPos native: when you teleported an NPC which was in car by FCNPC plugin, this bot always teleported right with his vehicle and continued to be in it on the new position set: https://github.com/ziggi/FCNPC/blob/master/src/CPlayerData.cpp#L997-L1004

But in omp implementation, an NPC may be either teleported without the vehicle or the vehicle may stay at the old position until re-stream, and it cannot be solved by using SetVehiclePos because this function doesn't work when NPC is a driver of the vehicle. So NPC_SetPos must always teleport an NPC who's a driver of this vehicle together with this vehicle, just like in FCNPC.

Test script where you can compare the behavior in-game: FCNPC / omp NPCs variant

2. NPC doesn't call vehicle events like death or respawn
If you apply NPC_SetVehicleHealth for a driver NPC and set any low health value for his vehicle like 150.0 or 0.0 when it starts firing and finally explode, still no OnVehicleDeath will be called, nor OnVehicleSpawn after a while too. Looks like this vehicle will explode and disappear only clientside, but not serverside. NPC will just stay at the same place without a car, moreover without his own death and respawn.

Test script where you can compare the behavior in-game: FCNPC / omp NPCs variant

3. NPC_EnableInfiniteAmmo has no effect if NPC_SetAmmo wasn't used
If an NPC has weapon with 0 ammo and you try to use NPC_EnableInfiniteAmmo, he still won't shoot any bullets:

NPC_SetWeapon(npcid, random(3) + 22);
NPC_EnableInfiniteAmmo(npcid, true);
NPC_AimAtPlayer(npcid, playerid, .shoot = true);

but when you set this NPC at least 1 or more bullets with NPC_SetAmmo, he immediately start shooting:

NPC_SetWeapon(npcid, random(3) + 22);
NPC_SetAmmo(npcid, 1); // or 5, or 999
NPC_EnableInfiniteAmmo(npcid, true);
NPC_AimAtPlayer(npcid, playerid, .shoot = true);

while FCNPC correctly handle even the first case

Activity

  1. changed the title [-]NPC_SetPos removed bot from vehicle[/-] [+]NPC_SetPos removes bot from vehicle[/+] on Dec 19, 2025
  2. changed the title [-]NPC_SetPos removes bot from vehicle[/-] [+]A couple of issues found with new NPCs[/+] on Dec 19, 2025
  3. ziggi commented on Dec 28, 2025

    @ziggi
    1. NPC_SetPos may remove bot from vehicle

    Isn't that how SetPlayerPos works? I think the implementation in FCNPC is incorrect.

  4. NexiusTailer commented on Dec 28, 2025

    @NexiusTailer
    ContributorAuthor
    1. NPC_SetPos may remove bot from vehicle

    Isn't that how SetPlayerPos works? I think the implementation in FCNPC is incorrect.

    Sure, but we have a different case with players comparing to NPCs:

    • to teleport just the player who sits in any vehicle without the vehicle, we oughta use SetPlayerPos, that's how it works
    • to teleport the player with his vehicle, we oughta use SetVehiclePos, just teleporting the vehicle in which the player sits

    As I already mentioned above, we cannot use SetVehiclePos on a vehicle with NPC as driver. So the easiest fix is to let teleporting NPCs with their vehicle by existing NPC_SetPos (and thus we will actually have to eject NPC from car to teleport just him without this car, like it is in FCNPC now), or make the logic identical as when working with players and add new NPC_SetVehiclePos function.

    Anyway thanks for notice as now there's some choice of how to solve this better.

  5. ziggi commented on Dec 28, 2025

    @ziggi

    If it is not possible to change the behavior of the SetVehiclePos function to support NPC as driver (for compatibility reasons or something else), then yes, it is better to add something like NPC_SetVehiclePos.

  6. AmyrAhmady commented on Jan 7, 2026

    @AmyrAhmady
    Member

    can you please test this for NPC_SetVehiclePos? (and NPC_SetVehicleRot)
    https://github.com/openmultiplayer/open.mp/actions/runs/20794996896

    native bool:NPC_SetVehiclePos(npcid, Float:x, Float:y, Float:z);
    native bool:NPC_SetVehicleRot(npcid, Float:x, Float:y, Float:z);
  7. NexiusTailer commented on Jan 8, 2026

    @NexiusTailer
    ContributorAuthor

    Tested the build #1182 and now can say that NPC_SetVehiclePos and NPC_SetVehicleRot works good.

    But NPC_SetPos seems broken now: it doesn't teleport an NPC which is in vehicle, now at all. Visually this NPC keep staying in his vehicle on the previous vehicle position. Also if I look at sobeit custom nametags which show NPCs, he starts eing "AFK" in this vehicle after NPC_SetPos was used on him.

    My current test script: https://pastebin.com/NPTN1iFz

  8. NexiusTailer commented on Jan 28, 2026

    @NexiusTailer
    ContributorAuthor

    Issue with NPC_SetPos applied to NPC vehicle driver now solved after #1182, but since there were NPC_SetVehiclePos and NPC_SetVehicleRot added, would be great to also have their counterparts (getter functions)

  9. AmyrAhmady commented on Jan 28, 2026

    @AmyrAhmady
    Member

    Create a new issue for getter functions, I'm going to close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions