Skip to content
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 (WIP) #916

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open

NPC Component (WIP) #916

wants to merge 32 commits into from

Conversation

AmyrAhmady
Copy link
Member

@AmyrAhmady AmyrAhmady commented Apr 17, 2024

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_SetFacingAngle(npcid, Float:angle);
native NPC_GetFacingAngle(npcid, &Float:angle);
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);
native NPC_SetSkin(npcid, model);
native NPC_IsStreamedIn(npcid, playerid);
native NPC_IsAnyStreamedIn(npcid);
native NPC_GetAll(npcs[], sizeof npcs);
native NPC_SetInterior(npcid, interiorid);
native NPC_GetInterior(npcid);
native NPC_SetHealth(npcid, Float:health);
native Float:NPC_GetHealth(npcid);
native NPC_SetArmour(npcid, Float:armour);
native Float:NPC_GetArmour(npcid);
native NPC_ApplyAnimation(npcid, const animLib[], const animName[], Float:delta, bool:loop, bool:lockX, bool:lockY, bool:freeze, time, sync);

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

@AmyrAhmady AmyrAhmady self-assigned this Apr 17, 2024
@AmyrAhmady AmyrAhmady changed the title NPC Component NPC Component (WIP) Apr 17, 2024
@eakwarp
Copy link

eakwarp commented Apr 17, 2024

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

@eakwarp
Copy link

eakwarp commented Apr 17, 2024

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
Copy link
Member

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
Copy link

eakwarp commented Apr 17, 2024

[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
Copy link

eakwarp commented Apr 17, 2024

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

@AmyrAhmady
Copy link
Member Author

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
Copy link
Member Author

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
Copy link

eakwarp commented Apr 17, 2024

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
Copy link

eakwarp commented Apr 17, 2024

[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
Copy link

eakwarp commented Apr 17, 2024

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

@AmyrAhmady
Copy link
Member Author

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
Copy link

eakwarp commented Aug 8, 2024

what about new builds?)

@AmyrAhmady
Copy link
Member Author

AmyrAhmady commented Oct 20, 2024

Some natives from FCNPC for Mysy

  • FCNPC_Create
  • FCNPC_Spawn
  • FCNPC_Respawn
  • FCNPC_IsDead
  • FCNPC_IsStreamedInForAnyone
  • FCNPC_GetPosition
  • FCNPC_SetPosition
  • FCNPC_GetHealth
  • FCNPC_SetHealth
  • FCNPC_SetVirtualWorld
  • FCNPC_SetWeapon
  • FCNPC_SetAmmo
  • FCNPC_GiveAmmo
  • FCNPC_SetWeaponAccuracy
  • FCNPC_UseReloading
  • FCNPC_UseInfiniteAmmo
  • FCNPC_AimAtPlayer
  • FCNPC_Stop
  • FCNPC_StopAim
  • FCNPC_GoTo
  • FCNPC_GoToPlayer
  • FCNPC_TriggerWeaponShot
  • FCNPC_SetAngleToPlayer
  • FCNPC_MeleeAttack
  • FCNPC_ApplyAnimation
  • FCNPC_SetSkin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants