server-beta
server-beta copied to clipboard
NPC Component (WIP)
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, Float:moveSpeed = -1.0);
native NPC_StopMove(npcid);
native bool:NPC_IsMoving(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);
native NPC_SetWeapon(npcid, weapon);
native NPC_GetWeapon(npcid);
native NPC_SetAmmo(npcid, ammo);
native NPC_GetAmmo(npcid);
native NPC_SetKeys(npcid, upAndDown, leftAndRight, keys);
native NPC_GetKeys(npcid, &upAnddown, &leftandRight, &keys);
native NPC_MeleeAttack(npcid, time, bool:secondaryAttack = false);
native NPC_StopMeleeAttack(npcid);
native bool:NPC_IsMeleeAttacking(npcid);
native NPC_SetFightingStyle(npcid, style);
native NPC_GetFightingStyle(npcid);
native NPC_EnableReloading(npcid, bool:enable);
native bool:NPC_IsReloadEnabled(npcid);
native bool:NPC_IsReloading(npcid);
native NPC_EnableInfiniteAmmo(npcid, bool:enable);
native bool:NPC_IsInfiniteAmmoEnabled(npcid);
native NPC_GetWeaponState(npcid);
native NPC_SetAmmoInClip(npcid, ammo);
native NPC_GetAmmoInClip(npcid);
native NPC_Shoot(npcid, weapon, hitId, hitType, Float:endPointX, Float:endPointY, Float:endPointZ, Float:offsetX, Float:offsetY, Float:offsetZ, bool:isHit, checkInBetweenFlags);
native bool:NPC_IsShooting(npcid);
native NPC_AimAt(npcid, Float:pointX, Float:pointY, Float:pointZ, bool:shoot, shootDelay, bool:updateAngle, Float:offsetFromX, Float:offsetFromY, Float:offsetFromZ, checkInBetweenFlags);
native NPC_AimAtPlayer(npcid, playerid, bool:shoot, shootDelay, bool:updateAngle, Float:offsetX, Float:offsetY, Float:offsetZ, Float:offsetFromX, Float:offsetFromY, Float:offsetFromZ, checkInBetweenFlags);
native NPC_StopAim(npcid);
native bool:NPC_IsAiming(npcid);
native bool:NPC_IsAimingAtPlayer(npcid, playerid);
native NPC_SetWeaponAccuracy(npcid, weaponid, Float:accuracy);
native Float:NPC_GetWeaponAccuracy(npcid, weaponid);
Callbacks:
forward OnNPCFinishMove(npcid);
forward OnNPCCreate(npcid);
forward OnNPCDestroy(npcid);
forward OnNPCTakeDamage(npcid, damagerid, Float:damage, WEAPON:weapon, bodypart);
forward OnNPCGiveDamage(npcid, damagedid, Float:damage, WEAPON:weapon, bodypart);
forward OnNPCDeath(npcid, killerid, reason);
forward onNPCSpawn(npcid);
forwatd OnNPCWeaponStateChange(npcid, newState, oldState);
Videos:
Short video of basic usage: https://cdn.discordapp.com/attachments/966398440051445790/1229681168878669895/ompnpc.mp4
Good job! I'll try this on my walking npcs)
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?
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.
[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))
not bad not bad.)) 500 npc slots, 50 player slots))
Server crashed when i try to spawn npc in OnNPCConnect.
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?
not bad not bad.)) 500 npc slots, 50 player slots)) Server crashed when i try to spawn npc in OnNPCConnect.
Also, update your launcher!
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)
[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
One more bug, in OnNPCConnect(npcid) npcid always 0
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?)