openmultiplayer / open.mp

Open Multiplayer, a multiplayer mod fully backwards compatible with SA-MP
https://open.mp
Mozilla Public License 2.0
453 stars 92 forks source link

NPC Component (WIP) #916

Open AmyrAhmady opened 5 months ago

AmyrAhmady commented 5 months ago

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

Natives:

native NPC_Create(const name[]);
native NPC_Destroy(npcid);
native NPC_IsValid(npcid);
native NPC_Spawn(npcid);
native NPC_SetPos(npcid, Float:x, Float:y, Float:z);
native NPC_GetPos(npcid, &Float:x, &Float:y, &Float:z);
native NPC_SetRot(npcid, Float:x, Float:y, Float:z);
native NPC_GetRot(npcid, &Float:x, &Float:y, &Float:z);
native NPC_SetVirtualWorld(npcid, vw);
native NPC_GetVirtualWorld(npcid, &vw);
native NPC_Move(npcid, Float:x, Float:y, Float:z, moveType);
native NPC_StopMove(npcid);

Callbacks:

forward OnNPCFinishMove(npcid);
forward OnNPCCreate(npcid);
forward OnNPCDestroy(npcid);

Videos:

Short video of basic usage: https://cdn.discordapp.com/attachments/966398440051445790/1229681168878669895/ompnpc.mp4

eakwarp commented 5 months ago

Good job! I'll try this on my walking npcs)

eakwarp commented 5 months ago

native NPC_StopMove(npcid, Float:x, Float:y, Float:z, moveType);


SCRIPT_API(NPC_StopMove, bool(INPC& npc))
{
    npc.stopMove();
    return true;
}

error in native?

ksenonadv commented 5 months ago

native NPC_StopMove(npcid, Float:x, Float:y, Float:z, moveType);


SCRIPT_API(NPC_StopMove, bool(INPC& npc))
{
  npc.stopMove();
  return true;
}

error in native?

Edited.

eakwarp commented 5 months ago
[2024-04-17T13:02:50+0300] [Info] [connection] incoming connection: 7f00:1:a4ff:ffff:a4ff:ffff:b94b:d7f7:63392 id: 0
[2024-04-17T13:02:50+0300] [Info] WalkNPC 0 Load, skin 31 node 2245
[2024-04-17T13:02:50+0300] [Info] [npc:part] FortCarson has left the server (0:2)
[2024-04-17T13:02:50+0300] [Info] [debug] Server crashed due to an unknown error

The first tests look interesting))

eakwarp commented 5 months ago

image not bad not bad.)) 500 npc slots, 50 player slots)) Server crashed when i try to spawn npc in OnNPCConnect.

AmyrAhmady commented 5 months ago

I don't think NPCs are supposed to connect with ipv6 as your logs show Also can you try using a cmd instead of spawning on connect? just to see if they work?

AmyrAhmady commented 5 months ago

image not bad not bad.)) 500 npc slots, 50 player slots)) Server crashed when i try to spawn npc in OnNPCConnect.

Also, update your launcher!

eakwarp commented 5 months ago

I don't think NPCs are supposed to connect with ipv6 as your logs show Also can you try using a cmd instead of spawning on connect? just to see if they work?

I removed the spawn, the server is working, the npcs have connected, but are physically absent)

logs looks like good.

....
[2024-04-17T13:43:01+0300] [Info] [connection] incoming connection: 127.0.0.1:60194 id: 354
[2024-04-17T13:43:01+0300] [Info] [npc:join] FortCarson15 has joined the server (354:127.0.0.1)
[2024-04-17T13:43:01+0300] [Info] WalkNPC 355 Load, skin 191 node 4180
[2024-04-17T13:43:02+0300] [Info] [connection] incoming connection: 127.0.0.1:55540 id: 355
[2024-04-17T13:43:02+0300] [Info] [npc:join] FortCarson16 has joined the server (355:127.0.0.1)
[2024-04-17T13:43:02+0300] [Info] WalkNPC 356 Load, skin 226 node 4178
[2024-04-17T13:43:02+0300] [Info] [connection] incoming connection: 127.0.0.1:54902 id: 356
[2024-04-17T13:43:02+0300] [Info] [npc:join] FortCarson17 has joined the server (356:127.0.0.1)
[2024-04-17T13:43:02+0300] [Info] WalkNPC 357 Load, skin 248 node 4192
[2024-04-17T13:43:02+0300] [Info] [connection] incoming connection: 127.0.0.1:53290 id: 357
[2024-04-17T13:43:02+0300] [Info] [npc:join] FortCarson18 has joined the server (357:127.0.0.1)
[2024-04-17T13:43:02+0300] [Info] WalkNPC 358 Load, skin 261 node 4190
[2024-04-17T13:43:03+0300] [Info] [connection] incoming connection: 127.0.0.1:62594 id: 358
[2024-04-17T13:43:03+0300] [Info] [npc:join] FortCarson19 has joined the server (358:127.0.0.1)
[2024-04-17T13:43:03+0300] [Info] WalkNPC 359 Load, skin 151 node 4166
[2024-04-17T13:43:03+0300] [Info] [connection] incoming connection: 127.0.0.1:49694 id: 359
[2024-04-17T13:43:03+0300] [Info] [npc:join] Civilian has joined the server (359:127.0.0.1)
[2024-04-17T13:43:03+0300] [Info] WalkNPC 362 Load, skin 35 node 4218
....

Also, update your launcher!

later )

ipv6

ipv6 turns into a localhost after the first player connects, hm..)

[2024-04-17T13:41:29+0300] [Info] [connection] incoming connection: 7f00:1:fcdb:afff:7ce0:afff:9db:afff:58068 id: 55
[2024-04-17T13:41:29+0300] [Info] [npc:join] WillowField4 has joined the server (55:7f00:1:fcdb:afff:7ce0:afff:9db:afff)
[2024-04-17T13:41:29+0300] [Info] WalkNPC 55 Load, skin 48 node 510
[2024-04-17T13:41:29+0300] [Info] [connection] incoming connection: **7f00:1:fcdb:afff:7ce0:afff:9db:afff:56960 id: 56**
[2024-04-17T13:41:29+0300] [Info] [npc:join] SanPedro5 has joined the server (56:7f00:1:fcdb:afff:7ce0:afff:9db:afff)
[2024-04-17T13:41:29+0300] [Info] WalkNPC 56 Load, skin 236 node 520
[2024-04-17T13:41:29+0300] [Info] [connection] incoming connection: [censored]:14169 id: 57
**[2024-04-17T13:41:29+0300] [Info] [join] Richard_Castle has joined the server (57:[censored])**
[2024-04-17T13:41:29+0300] [Info] [connection] incoming connection: **127.0.0.1:61243 id: 58**
[2024-04-17T13:41:29+0300] [Info] [npc:join] SanPedro6 has joined the server (58:127.0.0.1)
[2024-04-17T13:41:29+0300] [Info] WalkNPC 57 Load, skin 192 node 530
[2024-04-17T13:41:30+0300] [Info] [connection] incoming connection: 127.0.0.1:62777 id: 59
[2024-04-17T13:41:30+0300] [Info] [npc:join] SanPedro7 has joined the server (59:127.0.0.1)
[2024-04-17T13:41:30+0300] [Info] WalkNPC 58 Load, skin 190 node 540
[2024-04-17T13:41:30+0300] [Info] [connection] incoming connection: 127.0.0.1:54810 id: 60
[2024-04-17T13:41:30+0300] [Info] [npc:join] SanPedro8 has joined the server (60:127.0.0.1)
eakwarp commented 5 months ago
[2024-04-17T14:04:29+0300] [Info] npc 0 spawned via timer
[2024-04-17T14:04:29+0300] [Info] npc 0 walk start timer
[2024-04-17T14:04:29+0300] [Info] [npc:part] FortCarson has left the server (0:2)
[2024-04-17T14:04:29+0300] [Info] [debug] Server crashed due to an unknown error

I tried to spawn NPCs 10 seconds after connecting - the server also crashed

eakwarp commented 5 months ago

One more bug, in OnNPCConnect(npcid) npcid always 0

AmyrAhmady commented 5 months ago

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

eakwarp commented 1 month ago

what about new builds?)