[Tutorial] NPC #1 Creating idle NPCs

Started by habi, Apr 06, 2022, 11:54 AM

Previous topic - Next topic

habi

Introduction
In this tutorial, i will show you how to create your first NPC.
Download the application from here
Put everything in the zip file to your server directory. Sometimes, you may be asked to install x86 c++ redistributable.(thanks, vito)

Put the plugin npc04relxx in your plugins directory and add the name to plugins list in server.cfg. (Note: the npc application do not rely on squirrel gamemode but can be used by other languages. But at present, it is scripted only for squirrel gamemode)

I said the npc application do not rely on squirrel gamemode. Your server may be scripted using java, still the app can be made to work.

Each NPC has it's own script. This is our new method. The 'intelligence' of each NPC is scripted in this script. The script has events like OnNPCScriptLoad, etc. The complete list is available on the wiki listed in the link above. Also not that the OnNPCScriptLoad, etc the letter O is capital letter.

Few NPC scripts come along with download
We have a few NPC scripts already available. It is in the npcscripts directory. All NPC script files must be placed in this directory.

The script
You can see a file npcidle.nut. It is just a basic script which spawns an NPC which will be idle the whole time.(It will stand and watch everything, but will not talk.!)
//npcidle.nut
function OnNPCScriptLoad(params)
{
print("npcidle: running\n");
}

Connecting an npc
How to connect an NPC?
Open your squirrel gamemode script file(main.nut) and add this line.
//main.nut
function onScriptLoad()
{
ConnectNPC("[Bot]Mike", "npcidle.nut");
}
Now start your server and check if npc connected.

Example-2

function onScriptLoad()
{
    ConnectNPCEx("[NPC]Niki", -1067.21, -60.3589, 11.2696, 0.12, 4)
}


Next tutorial: Recording player actions