The value of "DOUBLECLICK" has nothing to do with the NPC in question; it is fixed. Whenever an NPC is double-clicked, his usecode function is called with the 'event' set to 1. Likewise, when the function is called by an script, 'event' is usually 2, when you spend too much time near an NPC (that is not on the party) 'event' is 0, etc. There is a list of values in "content/bgkeyring/src/headers/constants.uc".
"var IOLO = -1;" is because Iolo's NPC number is 1. NPCs are referred to by negative numbers; take the number from the cheat screen and multiply by -1. The exception is the avatar, which is identified by -356.
You assign a function to an NPC by the function's identification number. When the function is declared, you have one of the following syntaxes:
Code: Select all
void FunctionName_1 object#(numberhere) ()
{
// code here
}
void FunctionName_2 shape#(numberhere) ()
{
// code here
}
void FunctionName_3 numberhere (arglist)
{
// code here
}
var FunctionName_4 numberhere (arglist)
{
// code here
}
In order:
* 'void' means that a function does not return anything. 'object#' and 'shape#' require 'void'.
* 'arglist' is an optional list of parameters passed to the function. 'shape#' and 'object#' functions cannot have any arguments.
* 'shape#' and 'object#' mean that the function can be used in scripted animations. A 'shape#' function will automagically work for the shape it represents (see 'numberhere') and will be called as needed when an object of the given shape is double-clicked. For NPCs, eggs and weapons, you will want an 'object#' function instead; see 'numberhere' for details. Both types of functions have/require an item reference that must be supplied when the function is called; this is accessed by the 'item' variable, and it is a reference to the object in question (that is, the NPC/shape/egg for which the function was called).
* 'var' means that the function returns a value.
* 'numberhere': this identifies the function. In most cases, you will want to omit it or set it to -1; 'object#' and 'shape#' do not let you omit it, and 'shape#' functions do not let you set it to -1. If 'numberhere' is -1, the function will be autonumbered by UCC (and I
*strongly* suggest adding "#autonumber 0xC00" at the top of your usecode file, at about the same place you add the "#game" directive).
For the first 256 NPCs (*zero* to 255), 'numberhere' *must* be 1024 + NPC number; for Iolo, that would be 1025 (note that 1025 = 0x401 in hexadecimal numbers). For these NPCs, a function with that usecode number will be called if such a function exists.
For NPCs whose numbers are 256 or more, you can set the function by name in Exult Studio when you edit the NPC; likewise, you can set the function by name for eggs. In both cases, you can set 'numberhere' to -1. In these cases, the function will be called
only if you assign it in ES; if an NPC has no function assigned to it, its shape function will be called instead, while nothing at all will happen for eggs.
For shapes, 'numberhere' *must* be the shape number as seen in ES. If such a function exists for a given number, the function will be automatically called. The first 1024 shapes (*zero* to 1023) correspond to the first 1024 usecode functions (again, *zero* to 1023); you should avoid having functions in that range unless you want to override the shape's function.
For weapons, you still have to specify the function by usecode number; in that case, 'numberhere' must be the same as what was specified in the weapon tab in ES.
In all cases: if a function overrides a pre-existing function from the original game, you can call the latter by appending ".original" to the function name when calling it; thus, "Iolo.original()" would call Iolo's original usecode function (assuming you have a function named "Iolo").