Example targeting script:
Code: Select all
void main()
{
// Get the last player to use targeting mode
object oPC = GetLastPlayerToSelectTarget();
// Get the targeting mode data
object oTarget = GetTargetingModeSelectedObject();
vector vTarget = GetTargetingModeSelectedPosition();
// If the user manually exited targeting mode without selecting a target, return
if (!GetIsObjectValid(oTarget) && vTarget == Vector())
return;
// Save the targeting data to the PC object for later use
//location lTarget = Location(GetArea(oTarget), vTarget, 0.0f);
//SetLocalObject(oPC, "TARGETING_OBJECT", oTarget);
//SetLocalLocation(oPC, "TARGETING_POSITION", lTarget);
string sTargetMode = GetLocalString(oPC, "TARGET_MODE");
//Section used for chat commands
if (sTargetMode == "following")
{
AssignCommand(oPC, ActionForceFollowObject(oTarget));
}
else if (sTargetMode == "rename")
{
string sRename = GetLocalString(oPC, "RENAME_STRING");
SetName(oTarget, sRename);
}
else if (sTargetMode == "description")
{
string sDescription = GetLocalString(oPC, "DESCRIPTION_STRING");
SetDescription(oTarget, sDescription);
}
//SetLocalString(oPC, "TARGET_MODE", "");//Set target mode back to nothing. May not be needed
}
Code: Select all
//Target Modes
else if (sSaid == "/follow")
{
SetLocalString(oSpeaker, "TARGET_MODE", "following");
SendMessageToPC(oSpeaker, "Select a person or creature to follow.");
EnterTargetingMode(oSpeaker, OBJECT_TYPE_CREATURE);
}
else if (GetStringLeft(sSaid, 8) == "/rename ")
{
string sRemove = StringParse(sSaid, " ");
string sName = StringRemoveParsed(sSaid, sRemove, " ");
SendMessageToPC(oSpeaker, "Select an item to rename.");
SetLocalString(oSpeaker, "TARGET_MODE", "rename");
SetLocalString(oSpeaker, "RENAME_STRING", sName);
EnterTargetingMode(oSpeaker, OBJECT_TYPE_ITEM);
}
else if (GetStringLeft(sSaid, 13) == "/description ")
{
string sRemove = StringParse(sSaid, " ");
string sDescription = StringRemoveParsed(sSaid, sRemove, " ");
SendMessageToPC(oSpeaker, "Select an item to change the description of.");
SetLocalString(oSpeaker, "TARGET_MODE", "description");
SetLocalString(oSpeaker, "DESCRIPTION_STRING", sDescription);
EnterTargetingMode(oSpeaker, OBJECT_TYPE_ITEM);
}
Example line to add to OnModuleLoad:
Code: Select all
//Used to set the module OnPlayerTarget event since it's not in the module properties. Have to do it manually.
SetEventScript(GetModule(), EVENT_SCRIPT_MODULE_ON_PLAYER_TARGET, "name of module target script here");