open.mp
open.mp copied to clipboard
NPC Component bugs
Opened this issue to compile problems found while working on documentation.
Anyone is free to add new issues here. Please include screenshots or videos and a short explanation when reporting.
This issue includes a helper gamemode for testing: https://github.com/itsneufox/NPC-bare-test-omp-gamemode
The documentation PR is here: https://github.com/openmultiplayer/web/pull/1137
Issue 1:
If the NPC is shooting, and we set the shoot flag to false in NPC_AimAtPlayer, it keeps "shooting" (sound and animation only, no bullets).
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/hostile", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC."), 1;
NPC_AimAtPlayer(npcid, playerid, true, 800, true, 0.0, 0.0, 0.8, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER); // true: NPC fires
SendClientMessage(playerid, 0xFF0000FF, "NPC %d is now hostile towards you!", npcid);
return 1;
}
if (!strcmp(cmdtext, "/guard", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC."), 1;
NPC_AimAtPlayer(npcid, playerid, false, 0, true, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER); // false: should stop firing
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now guarding you.", npcid);
return 1;
}
return 0;
}
Fix:
Adding NPC_StopAim(npcid); before NPC_AimAtPlayer(...) stops the firing animation correctly.
if (!strcmp(cmdtext, "/guard", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC."), 1;
NPC_StopAim(npcid);
NPC_AimAtPlayer(npcid, playerid, false, 0, true, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now guarding you.", npcid);
return 1;
}
Issue 2:
If the NPC is shooting, and we set the shoot flag to false in NPC_AimAt, it keeps "shooting" (sound and animation only, no bullets).
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/aim", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC."), 1;
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
NPC_AimAt(npcid, x, y, z, false, 0, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_NONE); // false: should not fire
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now aiming at your position.", npcid);
return 1;
}
if (!strcmp(cmdtext, "/aimfire", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC."), 1;
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
NPC_AimAt(npcid, x, y, z, true, 800, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_NONE); // true: fires
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now firing at your position.", npcid);
return 1;
}
return 0;
}
Fix:
Adding NPC_StopAim(npcid); before NPC_AimAt(...) resolves the problem.
Same fix as Issue 1
Issue 3:
If an NPC is set to shoot at Player A, and that player disconnects (freeing their player slot), any new player who joins and takes the same slot will automatically become the NPC’s new target and get shot at.
The NPC’s target isn’t reset when the original player disconnects.
Video on discord since it had sensitive info: https://discord.com/channels/231799104731217931/1429460137776775208/1431102945247887380
if (!strcmp(cmdtext, "/hostile", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You have no NPC.");
NPC_AimAtPlayer(npcid, playerid, true, 800, true, 0.0, 0.0, 0.8, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER);
SendClientMessage(playerid, 0xFF0000FF, "NPC %d is now hostile towards you!", npcid);
return 1;
}
Expected Behaviour: When the targeted player disconnects or becomes invalid, the NPC should stop aiming or shooting automatically.