I'm trying to make one of my scripts more comfortable to use by providing the ability to pick targets (which requires an event handler script) but I also want to keep the script self-contained, so that users only have to drop the compiled script in a location where the game finds it.
This means that the main() function must be able to distinguish between the two different modes of invocation - from the console via RUNSCRIPT and as event handler.
Checking for the presence of an argument string does not work, since the nested invocation as event handler receives the exact same string as the outer invocation from RUNSCRIPT. Besides, the script will often be run without any arguments.
So far the only reliable criterion that I could find is the existence of the specific event created by RequestTarget(). Tests have been very promising, but knowing nothing about DA:O scripting I wouldn't even know what gotchas to look out for.
Does anyone have experience with stuff like that?
On a related note, I've been trying to define constants based on simple expressions but it didn't seem to work. Is there a way of defining such constants without pre-computing the result and supplying it as a literal? See my failed attempt at defining TARGET_FLAGS_:
// aa_select.nss - dual-mode test script for target selection
// 2014-04-02
#include "2da_constants_h"
const int EVENT_TARGET_SELECTED_ = 123456789;
const int TARGET_FLAGS_ = /**/ 7 /*/ TARGET_TYPE_SELF | TARGET_TYPE_FRIENDLY_CREATURE | TARGET_TYPE_HOSTILE_CREATURE /**/;
void main ()
{
// The only way to distinguish script mode and handler mode is via the event,
// since nested event mode returns the same command line as the outer script.
event e = GetCurrentEvent();
if (!IsEventValid(e) || GetEventType(e) != EVENT_TARGET_SELECTED_)
{
// running as a plain script
object o = GetMainControlled();
DisplayFloatyMessage(o, "PICKING...", FLOATY_HIT, 0xFF80FF, 3.0f);
RequestTarget(TARGET_FLAGS_, 0.0f, 0.0f, EVENT_TARGET_SELECTED_, o, GetCurrentScriptName());
}
else
{
// running as event handler
object oPicked = GetEventObject(e, 0);
DisplayFloatyMessage(oPicked, "*" + GetTag(oPicked) + "*", FLOATY_MESSAGE, 0xFFFF80, 3.0f);
DisplayFloatyMessage(OBJECT_SELF, "PICKED " + GetTag(oPicked), FLOATY_HIT, 0xFF80FF, 3.0f);
string s = GetLocalString(GetModule(), "RUNSCRIPT_VAR");
if (s != "")
{
DisplayFloatyMessage(oPicked, "PARAM '" + s + "'", FLOATY_MESSAGE, 0xFF0000, 3.0f);
}
}
}





Nach oben






