-
-
Notifications
You must be signed in to change notification settings - Fork 139
NPC Component #916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPC Component #916
Conversation
|
Good job! |
error in native? |
Edited. |
The first tests look interesting)) |
|
I don't think NPCs are supposed to connect with ipv6 as your logs show |
I removed the spawn, the server is working, the npcs have connected, but are physically absent) logs looks like good.
later )
ipv6 turns into a localhost after the first player connects, hm..) |
I tried to spawn NPCs 10 seconds after connecting - the server also crashed |
|
One more bug, in OnNPCConnect(npcid) |
|
As we talked in discord, regarding the crash issue, it should be fixed now. @eakwarp was kicking them and kicking an NPC wasn't implemented since it was on network level. Also removing/destroying NPCs on connect callbacks would result into crashes as well, which is now fixed too. Also callback names are updated |
|
what about new builds?) |
7d97857 to
5ad4db9
Compare
EDITEvery thing from below are done and testedSome natives from FCNPC for Mysy
|
|
If you start making an NPC shoot with NPC_AimAtPlayer() and then call NPC_StopAim() inside OnNPCWeaponShot(), the NPC will still appear to shoot, but it won’t deal any damage. In this case, NPC_StopAim() has no effect for that NPC. |
@douq Fixed in latest commit |
This reverts commit eb13392.
open.mp/Server/Components/NPCs/NPC/npc.cpp Line 1439 in b876feb
open.mp/Server/Components/NPCs/NPC/npc.cpp Line 267 in b876feb
#include <open.mp>
#include <omp_npcs>
main(){}
new vehicleid;
new npcid;
public OnGameModeInit()
{
npcid = NPC_Create("Driver");
NPC_Spawn(npcid);
vehicleid = CreateVehicle(411, 1958.33, 1343.12, 15.36, 0.0, -1, -1, -1);
NPC_PutInVehicle(npcid, vehicleid, 0); // ok
return 1;
}
public OnGameModeExit()
{
NPC_Destroy(npcid);
return 1;
}
public OnNPCSpawn(npcid)
{
printf("NPC %d spawned", npcid); // infinite loop
// NPC_PutInVehicle(npcid, vehicleid, 0);
return 1;
}
public OnNPCDestroy(npcid)
{
printf("NPC %d destroy", npcid);
return 1;
}
public OnPlayerDisconnect(playerid)
{
printf("player %d disconnect", playerid);
return 1;
}
public OnPlayerStateChange(playerid, PLAYER_STATE:newstate, PLAYER_STATE:oldstate)
{
// gmx -> disconnect -> still trigger this callback, maybe others same
printf("player %d %d %d", playerid, newstate, oldstate);
return 1;
} |
|
@dockfries thanks for your reports. They're all should be fixed now |
|
trigger twice OnPlayerDisconnect, maybe should be destroy -> disconnect? #include <open.mp>
#include <omp_npcs>
main(){}
new npcid_;
public OnGameModeInit()
{
npcid_ = NPC_Create("Driver");
NPC_Spawn(npcid_);
return 1;
}
public OnGameModeExit()
{
NPC_Destroy(npcid_);
return 1;
}
public OnNPCDestroy(npcid)
{
printf("NPC %d destroy", npcid);
return 1;
}
public OnPlayerDisconnect(playerid)
{
printf("player %d disconnect", playerid);
return 1;
}
samp.on("OnGameModeInit", () => {
/**
* [2025-10-12T13:56:34+0800] [Info] [connection] incoming connection: 127.0.0.1:61258 id: 59
[2025-10-12T13:56:34+0800] [Info] [npc:join] test has joined the server (59:127.0.0.1)
[2025-10-12T13:56:34+0800] [Info] [sampgdk:w] Index mismatch for OnScriptLoadPlayer (-10049 != -10050)
[2025-10-12T13:56:34+0800] [Info] Legacy Network started on port 7777
[2025-10-12T13:56:34+0800] [Info] [sampgdk:w] Index mismatch for OnNPCWeaponStateChange (-10010 != -10011)
*/
samp.callNative("NPC_Create", "s", 'test'); // not ok...
// setTimeout(() => { // it's ok... but why?
// samp.callNative("NPC_Create", "s", 'test');
// });
}) |
|
The issue above was fixed in last commit |
|
I'm not sure whether it's a bug or not. NPCs don't trigger the OnPlayerEnterDynamicArea() or OnPlayerEnterGangZone() callbacks. I'm using UseGangZoneCheck() and have shown the zone to the NPC. |
I think you need to manually enable
I tested it in my environment, but anyway it would be better if any guys could show code to recurrence it. It seems that we cannot directly use NPC_Create during OnGameModeInit, Streamer_ToggleItemUpdate for npcid returns 0, failed. #include <open.mp>
#include <omp_npcs>
#include <streamer>
main(){}
new npcid_;
new gangzone_;
new gangzone2_;
new area_;
public OnGameModeInit()
{
// DelayInit(); // Streamer_ToggleItemUpdate for npcid failed
SetTimerEx("DelayInit", 0, false, ""); // ok
SetTimerEx("SetNpcPosOne", 1000, false, "");
SetTimerEx("SetNpcPosTwo", 1500, false, "");
return 1;
}
forward DelayInit();
public DelayInit()
{
npcid_ = NPC_Create("Driver");
NPC_Spawn(npcid_);
// return 0, then the npc Enter/LeaveDynamicArea will not be received
printf("Streamer_ToggleItemUpdate %d", Streamer_ToggleItemUpdate(npcid_, STREAMER_TYPE_AREA, 1));
printf("Streamer_IsToggleItemUpdate %d", Streamer_IsToggleItemUpdate(npcid_, STREAMER_TYPE_AREA));
gangzone_ = CreatePlayerGangZone(npcid_, 0, 0, 100, 100);
gangzone2_ = GangZoneCreate(0, 0, 100, 100);
area_ = CreateDynamicCircle(0, 3, 1000);
UsePlayerGangZoneCheck(npcid_, gangzone_, true);
UseGangZoneCheck(gangzone2_, true);
PlayerGangZoneShow(npcid_, gangzone_, 0xFFFFFFFF);
GangZoneShowForAll(gangzone2_, 0xFFFFFFFF);
return 1;
}
forward SetNpcPosOne();
public SetNpcPosOne()
{
NPC_SetPos(npcid_, 1000, 100, 100);
new Float:x, Float:y, Float:z;
NPC_GetPos(npcid_, x, y, z);
printf("pos one %f %f %f", x, y, z);
printf("is in area? %d", IsPlayerInAnyDynamicArea(npcid_));
printf("is in gangzone? %d %d", IsPlayerInGangZone(npcid_, gangzone2_), IsPlayerInGangZone(npcid_, gangzone2_));
return 1;
}
forward SetNpcPosTwo();
public SetNpcPosTwo()
{
NPC_SetPos(npcid_, 0, 3, 3);
new Float:x, Float:y, Float:z;
NPC_GetPos(npcid_, x, y, z);
printf("pos two %f %f %f", x, y, z);
printf("is in area? %d", IsPlayerInAnyDynamicArea(npcid_));
printf("is in gangzone? %d %d", IsPlayerInGangZone(npcid_, gangzone2_), IsPlayerInGangZone(npcid_, gangzone2_));
return 1;
}
public OnPlayerEnterDynamicArea(playerid, STREAMER_TAG_AREA:areaid)
{
printf("npc is entering area %i", area_);
return 1;
}
public OnPlayerLeaveDynamicArea(playerid, STREAMER_TAG_AREA:areaid)
{
printf("npc is leaving area %i", area_);
return 1;
}
public OnPlayerEnterPlayerGangZone(playerid, zoneid)
{
printf("npc is entering player gangzone %i", zoneid);
return 1;
}
public OnPlayerLeavePlayerGangZone(playerid, zoneid)
{
printf("npc is leaving player gangzone %i", zoneid);
return 1;
}
public OnPlayerEnterGangZone(playerid, zoneid)
{
printf("npc is entering gangzone %i", zoneid);
return 1;
}
public OnPlayerLeaveGangZone(playerid, zoneid)
{
printf("npc is leaving gangzone %i", zoneid);
return 1;
} |
It doesn't work |
|
If we create NPCs after the OnGameModeInit event, it seems to work properly, particularly for the streamer dynamic area. This bug currently exists in the legacy_plugin of any version of the streamer. If you prefer not to delay the creation of NPCs after OnGameModeInit, you can use the open.mp component version branch. |
|
@douq @dockfries this is my code and it's running fine and I get the print log: native UseGangZoneCheck(gangzoneid, bool:check);
public OnGameModeInit()
{
new npcid = NPC_Create("AmitBot1");
NPC_Spawn(npcid);
NPC_SetPos(npcid, 32.7, 77.3, 0.0);
new gzid = GangZoneCreate(-18.0, 58.5, 80.0, 119.5);
GangZoneShowForPlayer(npcid, gzid, 0xFF0000FF);
UseGangZoneCheck(gzid, true);
return 1;
}
forward OnPlayerEnterGangZone(playerid, gangzoneid);
public OnPlayerEnterGangZone(playerid, gangzoneid)
{
printf("Player %d has entered GangZone %d", playerid, gangzoneid);
return 1;
} |
|
Merged to master, it's finally done bros. |


Info
This PR is made to follow progress of NPC component development
Also creating this PR allows our build CIs to run so people can grab server builds from this PR to test NPCs
(Note: Some stuff are taken from this branch https://github.com/openmultiplayer/open.mp/tree/Alasnkz/npc like NPC network class and some move calculations)
Current Pawn scripting API
All content has been moved to HERE
Videos:
Short video of basic usage:
https://cdn.discordapp.com/attachments/966398440051445790/1229681168878669895/ompnpc.mp4