[Tutorial: NPC] #2 Recording player actions

Started by habi, Apr 07, 2022, 05:02 AM

Previous topic - Next topic


Player actions can be recorded and reproduced by NPCs.
In the last tutorial, i have shown how to create an NPC which will not talk!.
npctest.nut file is an example of NPC which has little more intelligence. The scripts are from samp. One day, while testing something the above npc said (via chatbox) "I see player at a distance of x units driving a car"

Now, we will see how to record player actions.
For this, you have to modify your gamemode script. From now onwards i will say gamemode script for our server script i.e. main.nut, functions.nut, etc and not NPC scripts which also are nut files.

function onPlayerCommand(player, cmd, text)
return MessagePlayer("Specify file name", player);
local s;
s=StartRecordingPlayerData(player.ID, PLAYER_RECORDING_TYPE_ONFOOT, text);
s=StartRecordingPlayerData(player.ID, PLAYER_RECORDING_TYPE_DRIVER, text);
MessagePlayer ("[Recording] Started", player);
else if(cmd=="stoprecord")
local s = StopRecordingPlayerData(player.ID);
MessagePlayer("[Recording]Stopped", player);

Now we are ready to go. There are two types of recordings - onfoot recordings and driver recordings. onfoot recordings means the players action are recorded as he is onfoot. samp onfoot recordings seems not to include gun firings, but i have made an attempt to record gun firings too. However, snipper rifle and bomb are atm out of scope.

The .rec file
Now, we have made the command "recordme". Go to your server, spawn and type like /recordme roaming
If message appear, your actions will be recorded!
Roam around run, jump, shoot something and when you had enough type "stoprecord".
Now in your server folder, you can see a new folder "recordings". Open it and you will find a file named 'roaming.rec'.
How to use the .rec file?
Move the roaming.rec file to npcscripts/recordings.
Creating an NPC which will repeat the actions recorded.
Now, we will create an NPC which will run, jump, shoot and roam around just like you did.

Creating the NPC script
For this, you may create a new npc script or edit the existing one. There is an npc script called onfoot_test.nut. Find it, open it. It is specially created for this purpose.

In that somewhere you can find a line something like
StartRecordingPlayback(1, "walktest"); (Edit: Actually there is no recording with this name available in recordings folder. The intended name was shotrun )
Change it to
StartRecordingPlayback (1, "roaming");
Save the file

The NPC script
// onfoot_test.nut
/* Copyright SA-MP 2009
modified by habi 2022*/

function OnNPCScriptLoad(){ }

function NextPlayback()


function OnRecordingPlaybackEnd()


function OnNPCSpawn()


function OnNPCExitVehicle()


Finally, connecting the npc
Now as we done in previous tutorial, you need to connect the npc. Do it by ConnectNPC function.
function onScriptLoad()
ConnectNPC("[Bot]Ace", "onfoot_test.nut");
Now open your server and check for someone running, jumping or shooting.!

Vehicle recordings are similar, but there are a couple of things. I will update this post or come up with a new one.
For that time, bye.

Next tutorial: Recording vehicle drivings