01.07.2012, 15:21
(
Last edited by Mauzen; 08/08/2020 at 02:00 AM.
Reason: Version 0.4
)
Its been a while since I wrote about my experiences with the .rec files. Later, Joe Staff released a code snippet to generate rec files. Now I finally made use of this, as I planned to do all the time, and started creating a plugin to control NPCs by manipulating and creating rec files.
The generate code is now completely rewritten for a better performance, and more possibilities.
What RNPC does
RNPC currently offers complete control over OnFoot-NPCs. Easy or complex actions can be assembled in the script using the "build mode". Since 0.4, NPCs can also be killed. You can read about how it all works on the wiki page. Theres also some example code.
The plugin comes with a npcmode and include, that do most of the job.
What RNPC should do
RNPC is just in developement, but might already be useful for some people.
Im looking forward to add these functionalities some time:
Bugs
Creating a new recording file (using RNPC_CreateBuild) on the same slot the NPC is currently playing back will crash the NPC.
Fix: To be sure, create the new build on another slot. Due to the way of communcation, stopping the playback just before creating a new one is a typical race condition, the NPC might, or might not have stopped the playback when writing to the file then. So this can be a reason of seemingly random crashes. Since 0.3.3 you can use RNPC_CreateBuild_s to prevent this automatically.
Starting vehicle playbacks is delayed if the vehicle is far away from its recorded position.
Fix: This is a SA-MP issue, however it can be fixed when specifiing the vehicleid in RNPC_StartBuildPlayback. This will start the recording twice with a small delay, which seems to fix the problem.
Bad performance? Especially when controlling many NPCs in short intervals performance might suck. I highly suggest not to have your npcmodes on a physical hdd. At least outsource them to a ssd, this fixes most performance issues, increases the maximum lag-free number of npcs by a factor of 10 or so. Best case would be a ramdisk though. File access is the one huge bottleneck for this plugin, minimizing access times by putting those files in ram basically allows unlimited NPCs, or at least shifts the bottleneck to the CPU. Ive got a script somewhere to automatically mount/unmount a ramdisk as npcmodes folder in linux, ask me for that if you like, or better check how to do it yourself.
Missing DLLs?
If you get error messages about missing DLLs when starting the server, try installing Visual C++ redistributables.
MSVCP120.dll is part of this: http://www.microsoft.com/en-us/downl....aspx?id=40784 (x86 version)
Thanks to [D]ry[D]esert
Background info
The system behind it is quite easy.
When MoveRNPC is called, the plugin generates a .rec file for the movement from A to B. Then a clientmessage is sent to the npc, telling him that theres a new action in his record file. He plays it back, and reports back when its done.
The "build mode" is meant to assemble more complex actions than just walking. When starting it, the record file is created, and new segments are added whenever something is added in the script. This way the .rec file is built step-by-step, and can easily be played back after finishing it. As this is quite complicated if you arent familiar with the way .rec files work, Ill add CNPC-like Mid-level functions later.
The source currently contains MapAndreas. Dont get confused by that, I altered an old project and as im going to need MapAndreas anyways at a later stage I just kept it there.
Changelog
0.1: Initial release
0.2: Huge amount of changes, the plugin is now really useable for normal servers:
Currently working on
(I cant and wont give any information about release dates)
(realtime) .rec file editing, NPC communication remake (no more strcmp) and better possibilities to add own NPC directives (that actually is a great way to reduce server load and so allow more NPCs, more about that idea later), enabling NPCs damaging normal players in lagcomp mode.
Some suggestion for useful SA-MP NPC updates
Ive been suggesting some of that stuff for years now. All of them would make NPCs in general, and especially RNPC much more powerful. This is my personal selection, just listing the "important" ones that got no nice script/plugin solution, so I still hope at least some of them will be realized some time. Sure theres a suggestion thread, but I thought this thread would be an even better place for this, as it also explains why RNPC is that limited in some aspects.
Version 0.3.1.1 Fixed RNPC_StopPlayback (25.2.2013), full package with 0.3.1 release version plugin (updated link)
Version 0.3.3 (24.5.2014) test release, complete with .dll .so and source (26.5.2014: Small fixes, thanks to [D]ry[D]esert, juandiegox and EnzoMetlc)
Version 0.3.4 (18.6.2014) Full package Consider this post for changes and infos
Version 0.4 (26.6.2014) Full package Consider this post for detailled changes and infos
Version 0.4.1 (3.12.2014) Full package consider this post for a detailled changelog (Special thanks to BlackWolf120)
Links fixed now, in case i go missing again, feel free to post mirrors here, if you like a mod could also add them in this post then.
Other stuff
ARNPC include by TheArcher - An "addon" for RNPC that fixes a bunch of bugs, and adds a bunch of new functions like RNPCFollowPlayer
RNPC Pool include - Great for reducing the amount of wasted player slots for NPCs, essential for streaming NPCs
An include for 0.4 for creating very basic zombie bots to test the new damage management
SAfull.hmap for lazy guys who dont want to get it from MapAndreas
Have fun, and give some feedback
The generate code is now completely rewritten for a better performance, and more possibilities.
What RNPC does
RNPC currently offers complete control over OnFoot-NPCs. Easy or complex actions can be assembled in the script using the "build mode". Since 0.4, NPCs can also be killed. You can read about how it all works on the wiki page. Theres also some example code.
The plugin comes with a npcmode and include, that do most of the job.
What RNPC should do
RNPC is just in developement, but might already be useful for some people.
Im looking forward to add these functionalities some time:
- Vehicle support (done in V0.3)
- Automatic playback queues (for creating routes or complex actions) (done in V0.2)
- Support for NPC actions like animations, keys, etc (done in V0.2)
- Automatic pathfinding (done by pamdex, but not yet included in new versions)
- Killing NPCs (done in V0.4)
- Mid-level functions to get rid of the build mode
- NPC streaming (see the RNPC Pool include in the download section)
- REC file repositioning to move existing actions to other places
- Own threads for rec file creation/modification
Bugs
Creating a new recording file (using RNPC_CreateBuild) on the same slot the NPC is currently playing back will crash the NPC.
Fix: To be sure, create the new build on another slot. Due to the way of communcation, stopping the playback just before creating a new one is a typical race condition, the NPC might, or might not have stopped the playback when writing to the file then. So this can be a reason of seemingly random crashes. Since 0.3.3 you can use RNPC_CreateBuild_s to prevent this automatically.
Starting vehicle playbacks is delayed if the vehicle is far away from its recorded position.
Fix: This is a SA-MP issue, however it can be fixed when specifiing the vehicleid in RNPC_StartBuildPlayback. This will start the recording twice with a small delay, which seems to fix the problem.
Bad performance? Especially when controlling many NPCs in short intervals performance might suck. I highly suggest not to have your npcmodes on a physical hdd. At least outsource them to a ssd, this fixes most performance issues, increases the maximum lag-free number of npcs by a factor of 10 or so. Best case would be a ramdisk though. File access is the one huge bottleneck for this plugin, minimizing access times by putting those files in ram basically allows unlimited NPCs, or at least shifts the bottleneck to the CPU. Ive got a script somewhere to automatically mount/unmount a ramdisk as npcmodes folder in linux, ask me for that if you like, or better check how to do it yourself.
Missing DLLs?
If you get error messages about missing DLLs when starting the server, try installing Visual C++ redistributables.
MSVCP120.dll is part of this: http://www.microsoft.com/en-us/downl....aspx?id=40784 (x86 version)
Thanks to [D]ry[D]esert
Background info
The system behind it is quite easy.
When MoveRNPC is called, the plugin generates a .rec file for the movement from A to B. Then a clientmessage is sent to the npc, telling him that theres a new action in his record file. He plays it back, and reports back when its done.
The "build mode" is meant to assemble more complex actions than just walking. When starting it, the record file is created, and new segments are added whenever something is added in the script. This way the .rec file is built step-by-step, and can easily be played back after finishing it. As this is quite complicated if you arent familiar with the way .rec files work, Ill add CNPC-like Mid-level functions later.
The source currently contains MapAndreas. Dont get confused by that, I altered an old project and as im going to need MapAndreas anyways at a later stage I just kept it there.
Changelog
0.1: Initial release
0.2: Huge amount of changes, the plugin is now really useable for normal servers:
- New "build mode" system and .rec generate code
- Complete support for all OnFoot attributes
- Greatly increased performance
- When using the defined movement speeds (RNPC_SPEED_WALK etc) the correct walking animation will be set.
- Removed some old functions
- Fixed some minor bugs
- Linux version included
- Support for vehicle recordings
- Included MapAndreas 1.1
- Support for acceleration with a new movement generation
- Some bugfixes and new functions
- Probably a lot new bugs
- ConnectRNPC now returns the correct ID without the need for timers or extra stuff
- Fixed a bug with RNPC_StartBuildPlayback and RNPC_StartPlayback that could cause them to have no effect
- Added IsPlayerRNPC(playerid) to check if a player is a valid and ready RNPC
- Added optional parameter use_zmap to RNPC_AddMovement/RNPC_ConcatMovement to use MapAndreas for z-coordinates (MapAndreas has to be initialized correctly)
- Update notifier
- Some new functions
- Better and safer functionality of some functions
- Updated to MapAndreas 1.2
- Shoot NPCs
- Drive over NPCs
- Kill NPCs
- A bunch of new functions and callbacks
- Some bugfixes and improved sync
- Fixed a critical bug that caused NPCs to crash
- Fixed wrong NPC facing angle in recordings without movements
- Optional: fixed wrong AddPause time
Currently working on
(I cant and wont give any information about release dates)
(realtime) .rec file editing, NPC communication remake (no more strcmp) and better possibilities to add own NPC directives (that actually is a great way to reduce server load and so allow more NPCs, more about that idea later), enabling NPCs damaging normal players in lagcomp mode.
Some suggestion for useful SA-MP NPC updates
Ive been suggesting some of that stuff for years now. All of them would make NPCs in general, and especially RNPC much more powerful. This is my personal selection, just listing the "important" ones that got no nice script/plugin solution, so I still hope at least some of them will be realized some time. Sure theres a suggestion thread, but I thought this thread would be an even better place for this, as it also explains why RNPC is that limited in some aspects.
- Sync the full aimvector in rec files, not just the facing angle: right now there is absolutely no chance to make a NPC look/aim up and down, without memory hacking (except using quaternions to rotate the whole character, but thats useless) Though this is a really important thing to create nice NPCs.
- Allow access to more information in npc scripts: Using npc scripts combined with dynamic rec file creation allows great NPC AIs without affecting the servers performance a lot. But the possibilities currently are very limited, as a_npc doesnt allow access to many player/vehicle/server information. NPCs are treated pretty much like normal players, so I guess the server also sends the same information to them. So why not create natives to access them all?
- Ignore lag compensation mode for NPCs: I understand this might be a difficult one, depending on how the lagcomp mode is treated internally. But seriously, right now you have to decide to either get damage from shooting NPCs (lagcomp off) or being able to shoot NPCs (lagcomp on). And invulnerable NPCs that are able to kill you are just as useless as killable NPCs that cant harm you. So it would be a GREAT improvement, if the server would ignore the lagcomp mode for NPCs, and instead always relies on the clients for that.
Version 0.3.1.1 Fixed RNPC_StopPlayback (25.2.2013), full package with 0.3.1 release version plugin (updated link)
Version 0.3.3 (24.5.2014) test release, complete with .dll .so and source (26.5.2014: Small fixes, thanks to [D]ry[D]esert, juandiegox and EnzoMetlc)
Version 0.3.4 (18.6.2014) Full package Consider this post for changes and infos
Version 0.4 (26.6.2014) Full package Consider this post for detailled changes and infos
Version 0.4.1 (3.12.2014) Full package consider this post for a detailled changelog (Special thanks to BlackWolf120)
Links fixed now, in case i go missing again, feel free to post mirrors here, if you like a mod could also add them in this post then.
Other stuff
ARNPC include by TheArcher - An "addon" for RNPC that fixes a bunch of bugs, and adds a bunch of new functions like RNPCFollowPlayer
RNPC Pool include - Great for reducing the amount of wasted player slots for NPCs, essential for streaming NPCs
An include for 0.4 for creating very basic zombie bots to test the new damage management
SAfull.hmap for lazy guys who dont want to get it from MapAndreas
Have fun, and give some feedback