ConnectNPC: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
No edit summary
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
<poem style="border: 2px solid #d6d2c5; background-color: #ffff00; padding: 1em;">
The '''execArg''' parameter will be added in v1.8 (not released as of 24 January 2024)
</poem>
<poem style="border: 2px solid #d6d2c5; background-color: #00ff00; padding: 1em;">
Version 1.6 has added parameter plugins. Version 1.5 patch2 has added parameter enableconsoleinput. Earlier versions do not have this parameter
</poem>
{{Welcome|
{{Welcome|
desc=Connect an NPC to the server|
desc=Connect an NPC to the server|
params=<syntaxhighlight lang="lua">(name, script="", host="127.0.0.1")</syntaxhighlight>
params=<syntaxhighlight lang="lua">(name, script="", enableconsoleinput=false, host="127.0.0.1", plugins="", execArg="")</syntaxhighlight>
<poem>::name : The name for the NPC to use.
<poem>::name : The name for the NPC to use.
::script : The script NPC must use. This script must reside in npcscripts folder.(with the ".nut" extension)
::script : The script NPC must use. This script must reside in npcscripts folder.(with the ".nut" extension)
::host : This paramter is optional. </poem>|
::enableconsoleinput : true/false. If true, text typed in the console is passed to the npcscript by calling the function [[OnConsoleInput]], if available. If true, the console will not be hidden. If false, text cannot be typed in the console and visibility of console depends on [[ShowNPCConsole]] called earlier. The text will be compiled and executed if OnConsoleInput function is not available!
::host : The IP address of the host running vcmp server.
::plugins : The string containing list of [[NPC Plugins|plugins]] to be loaded.
::execArg : The string will be ''compiled and executed'' by the squirrel machine before loading the script. <source inline>ConnectNPC("bot7","",false,"","","function OnNPCSpawn(){SendChat(\\\"I spawned.\\\")}")</source>. See [[V1_8_beta_release_notes#execArg usage in ConnectNPC|this note]] </poem>|
retval= This function always return 1.|
retval= This function always return 1.|
example=<source lang="lua">
example=<source lang="lua">
Line 12: Line 21:
}
}
</source>|
</source>|
note=Prior to version 1.5, script was mandatory.|
note=The parameter enableconsoleinput=true on Linux causes the program to wait for 'Enter' key indefinitely. This is fixed in v1.6 beta.|
relfuncs=*[[ConnectNPCEx]]
relfuncs=*[[ConnectNPCEx]]
*[[IsPlayerNPC]]
*[[IsPlayerNPC]]
}}
}}

Latest revision as of 16:25, 24 January 2024

The execArg parameter will be added in v1.8 (not released as of 24 January 2024)

Version 1.6 has added parameter plugins. Version 1.5 patch2 has added parameter enableconsoleinput. Earlier versions do not have this parameter


Description:
Connect an NPC to the server


Parameters:

(name, script="", enableconsoleinput=false, host="127.0.0.1", plugins="", execArg="")

name : The name for the NPC to use.
script : The script NPC must use. This script must reside in npcscripts folder.(with the ".nut" extension)
enableconsoleinput : true/false. If true, text typed in the console is passed to the npcscript by calling the function OnConsoleInput, if available. If true, the console will not be hidden. If false, text cannot be typed in the console and visibility of console depends on ShowNPCConsole called earlier. The text will be compiled and executed if OnConsoleInput function is not available!
host : The IP address of the host running vcmp server.
plugins : The string containing list of plugins to be loaded.
execArg : The string will be compiled and executed by the squirrel machine before loading the script. ConnectNPC("bot7","",false,"","","function OnNPCSpawn(){SendChat(\\\"I spawned.\\\")}"). See this note


Return Values:
This function does not return any specific values.

Important Note:
The parameter enableconsoleinput=true on Linux causes the program to wait for 'Enter' key indefinitely. This is fixed in v1.6 beta.

Example

function onScriptLoad()
{
	ConnectNPC("[Bot]John", "test.nut");
}

Related Functions

The following functions may be helpful as they relate to this function in one way or another.