Introduction
This feature was added in 0.3a and will not work in earlier versions! |
The NPCs (Non-Player Characters, also known as 'bots') are a feature introduced since SA-MP 0.3. This new feature allows you to add one or more NPCs inside your server who will work like 'virtual players'. They use a server slot, just like a player would do. What the NPCs do inside your server is scripted using PAWN scripts. The scripts with the 'artificial inteligence' of each NPC isn't scripted inside the gamemode file, nor in a filterscript. They use their own compiled scripts for this task, which have to stay inside the npcmodes directory. That is, if you want to have 20 different NPCs doing different things, you will most likely have to have 20 pawn compiled scripts inside the npcmodes directory. This doesn't mean that you can't use the normal player functions applied to your NPCs (like SetPlayerPos, for example) from inside a gamemode or filterscript.
Each NPC runs in its own process. This can make better use for multi-core proccesors. The new NPC feature adds some more callbacks and functions which can be used just inside NPC scripts. Normally, these scripts just include the a_npc include file, and not the a_samp one as most gamemodes and filterscripts do. There are also a couple of added functions which work in gamemodes and filterscripts to make easier the NPC handling.
The following resources are exclusive for NPC scripts, unless otherwise is stated:
NPC script callbacks
- NPC:OnClientMessage: Called whenever the NPC sees a ClientMessage.
- NPC:OnNPCConnect: Called when the NPC successfully connects to the server.
- NPC:OnNPCDisconnect: Called when the NPC gets disconnected from the server.
- NPC:OnNPCEnterVehicle: Called when a NPC enters a vehicle.
- NPC:OnNPCExitVehicle: Called when a NPC leaves a vehicle.
- NPC:OnNPCModeExit: Called when a NPC-script unloaded.
- NPC:OnNPCModeInit: Called when a NPC script is loaded.
- NPC:OnNPCSpawn: Called when a NPC spawned.
- NPC:OnPlayerDeath: Called when any player dies.
- NPC:OnPlayerStreamIn: Called when a player is streamed in for an NPC.
- NPC:OnPlayerStreamOut: Called when a player is streamed out the NPC.
- NPC:OnPlayerText: Called every time someone says something in the chat.
- NPC:OnRecordingPlaybackEnd: Called when a recorded file being reproduced with NPC:StartRecordingPlayback has reached to its end.
- NPC:OnVehicleStreamIn: Called when a vehicle is streamed by the NPC.
- NPC:OnVehicleStreamOut: Called when a vehicle is streamed out for an NPC.
NPC script functions
- NPC:StartRecordingPlayback: Run a .rec file which has to be saved in the npcmodes/recordings folder.
- NPC:StopRecordingPlayback: Stop the current .rec file which is being ran by the NPC, making it stay idle until some other order is given.
- NPC:PauseRecordingPlayback: Pause playing back the recording.
- NPC:ResumeRecordingPlayback: Resume the paused recording.
- NPC:SendChat: Send a player text by the bot, just like using SendPlayerMessageToAll, but this function is to be used inside the NPC scripts.
- NPC:SendCommand: Force the NPC to write a desired command, and this way, getting the effects it would produce.
- NPC:GetMyPos: Get the current location of the NPC.
- NPC:SetMyPos: Set the position of the NPC.
- NPC:GetMyFacingAngle: Get the current facing angle of the NPC.
- NPC:SetMyFacingAngle: Set the NPC's facing angle.
- NPC:GetDistanceFromMeToPoint: Get the distance between the NPC and a point.
- NPC:IsVehicleStreamedIn: Checks if a vehicle is streamed in for an NPC. Only nearby vehicles are streamed in.
- NPC:IsPlayerStreamedIn: Checks if a player is streamed in for an NPC. Only nearby players are streamed in.
Scripts
- ConnectNPC: Connect an NPC.
- IsPlayerNPC: Check if a player is an NPC or an actual player.
Subcategories
This category has the following 2 subcategories, out of 2 total.
N
- NPC Scripting Callbacks (15 P)
- NPC Scripting Functions (15 P)