Files
dsrc/sku.0/sys.server/compiled/game/script/event/area_tefme.java
T

251 lines
10 KiB
Java

package script.event;
import script.*;
import script.base_class.*;
import script.combat_engine.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
import script.base_script;
import script.library.utils;
public class area_tefme extends script.base_script
{
public area_tefme()
{
}
public static final String[] HELP_TEXT =
{
"=========================================",
"KEY WORDS (These are case sensitive): setStartPhrase, setEndPhrase, setAreaRange, setSingleMode, setAreaMode, showStats, detach.",
"setStartPhrase: Set the phrase that you will speak to cause yourself to become TEF'd. Default is \"Come get me\"",
"setEndPhrase: Set the phrase that you will speak to attempt to end your TEFs. Default is \"Not in the face!\"",
"setAreaRange: Set the range for area wide TEF mode.",
"setSingleMode: Puts you in single target mode, meaning only your look-at target will get a TEF against you.",
"setAreaMode: Puts you in area wide mode.",
"showStats: Check what mode you are in and current variables.",
"detach: Detachs this script and clears objvars.",
"========================================="
};
public int OnAttach(obj_id self) throws InterruptedException
{
if (!isPlayer(self))
{
detachScript(self, "event.area_tefme");
}
removeObjVar(self, "event.tefme");
if (!isGod(self))
{
detachScript(self, "event.area_tefme");
sendSystemMessage(self, "You must be in God Mode for this script to take hold.", null);
removeObjVar(self, "event.tefme");
return SCRIPT_CONTINUE;
}
if (isGod(self))
{
int godLevel = getGodLevel(self);
if (godLevel < 15)
{
detachScript(self, "event.area_tefme");
sendSystemMessage(self, "You do not have the appropriate access level to use this script.", null);
removeObjVar(self, "event.tefme");
return SCRIPT_CONTINUE;
}
}
sendSystemMessage(self, "Say \"Help\" for usage and options. Remember to refresh God Mode after teleporting or warping.", null);
String startPhrase = "Come get me";
String endPhrase = "Not in the face!";
setObjVar(self, "event.tefme.currentState", 0);
setObjVar(self, "event.tefme.startPhrase", startPhrase);
setObjVar(self, "event.tefme.endPhrase", endPhrase);
setObjVar(self, "event.tefme.range", 100);
setObjVar(self, "event.tefme.mode", 0);
return SCRIPT_CONTINUE;
}
public int OnHearSpeech(obj_id self, obj_id objSpeaker, String strText) throws InterruptedException
{
if (objSpeaker != self)
{
return SCRIPT_CONTINUE;
}
if (isGod(self))
{
int godLevel = getGodLevel(self);
if (godLevel < 15)
{
detachScript(self, "event.area_tefme");
sendSystemMessage(self, "You do not have the appropriate access level to use this script.", null);
removeObjVar(self, "event.tefme");
return SCRIPT_CONTINUE;
}
}
if (!isGod(self))
{
detachScript(self, "event.area_tefme");
sendSystemMessage(self, "You must be in God Mode to use this script.", null);
removeObjVar(self, "event.tefme");
return SCRIPT_CONTINUE;
}
int currentState = getIntObjVar(self, "event.tefme.currentState");
String startPhrase = getStringObjVar(self, "event.tefme.startPhrase");
String endPhrase = getStringObjVar(self, "event.tefme.endPhrase");
int range = getIntObjVar(self, "event.tefme.range");
int mode = getIntObjVar(self, "event.tefme.mode");
if (mode == 0 && currentState == 0)
{
if (strText.equalsIgnoreCase(startPhrase))
{
obj_id[] objPlayers = getPlayerCreaturesInRange(self, range);
if (objPlayers != null && objPlayers.length > 0)
{
for (int i = 0; i < objPlayers.length; i++)
{
if (objPlayers[i] != self)
{
pvpSetPersonalEnemyFlag(self, objPlayers[i]);
String playerName = getName(objPlayers[i]);
sendSystemMessage(self, playerName + " can now attack you!", null);
}
}
}
}
if (strText.equalsIgnoreCase(endPhrase))
{
pvpRemoveAllTempEnemyFlags(self);
sendSystemMessage(self, "Clearing your TEFs. Note that you may still be able to attack some players for a period of time.", null);
}
}
if (mode == 1 && currentState == 0)
{
if (strText.equalsIgnoreCase(startPhrase))
{
obj_id target = getLookAtTarget(self);
if (isIdValid(target) && target != self)
{
pvpSetPersonalEnemyFlag(self, target);
String playerName = getName(target);
sendSystemMessage(self, playerName + " can now attack you!", null);
}
}
if (strText.equalsIgnoreCase(endPhrase))
{
pvpRemoveAllTempEnemyFlags(self);
sendSystemMessage(self, "Clearing your TEFs. Note that you may still be able to attack some players for a period of time.", null);
}
}
if (currentState == 1)
{
if (strText.equalsIgnoreCase(endPhrase))
{
sendSystemMessage(self, "Your start phrase must be different from your end phrase dummy.", null);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.tefme.startPhrase", strText);
setObjVar(self, "event.tefme.currentState", 0);
sendSystemMessage(self, "You will TEF yourself when you say the following phrase: " + strText, null);
return SCRIPT_CONTINUE;
}
if (currentState == 2)
{
if (strText.equalsIgnoreCase(startPhrase))
{
sendSystemMessage(self, "Your end phrase must be different from your start phrase dummy.", null);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.tefme.endPhrase", strText);
setObjVar(self, "event.tefme.currentState", 0);
sendSystemMessage(self, "You will attempt to lose your TEFs when you say the following phrase: " + strText, null);
return SCRIPT_CONTINUE;
}
if (currentState == 3)
{
String rangeStr = strText;
range = utils.stringToInt(rangeStr);
if (range < 1 || range > 256)
{
sendSystemMessage(self, "Range must be between 1 and 255. Please note that these are numbers. Try again.", null);
return SCRIPT_CONTINUE;
}
setObjVar(self, "event.tefme.range", range);
setObjVar(self, "event.tefme.currentState", 0);
sendSystemMessage(self, "Your TEF range is set to " + strText + "m.", null);
return SCRIPT_CONTINUE;
}
if (currentState > 3)
{
setObjVar(self, "event.tefme.currentState", 0);
sendSystemMessage(self, "Somehow currentState was above 3. Resetting it to 0.", null);
return SCRIPT_CONTINUE;
}
if (mode > 1)
{
setObjVar(self, "event.tefme.mode", 0);
sendSystemMessage(self, "Somehow mode was above 1. Resetting it to 0.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("setStartPhrase"))
{
setObjVar(self, "event.tefme.currentState", 1);
sendSystemMessage(self, "The next phrase you say will be set as the trigger to TEF yourself.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("setEndPhrase"))
{
setObjVar(self, "event.tefme.currentState", 2);
sendSystemMessage(self, "The next phrase you say will be set as the trigger to attempt to remove your TEFs.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("setAreaRange"))
{
setObjVar(self, "event.tefme.currentState", 3);
sendSystemMessage(self, "Speak the range you wish to use for the AOE TEF.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("setSingleMode"))
{
setObjVar(self, "event.tefme.mode", 1);
sendSystemMessage(self, "Single TEF Mode active. Your look-at target will recieve a TEF for you when you speak the startPhrase.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("setAreaMode"))
{
setObjVar(self, "event.tefme.mode", 0);
sendSystemMessage(self, "Area Mode active. Everyone within " + range + "m will get a TEF against you when you speak the startPhrase.", null);
return SCRIPT_CONTINUE;
}
if (strText.equals("showStats"))
{
String currentModeStr = "Area Mode";
if (mode == 0)
{
currentModeStr = "Area Mode";
}
if (mode == 1)
{
currentModeStr = "Single Target Mode";
}
sendSystemMessage(self, "You are currently in " + currentModeStr, null);
sendSystemMessage(self, "Your start phrase is: " + startPhrase, null);
sendSystemMessage(self, "Your end phrase is: " + endPhrase, null);
sendSystemMessage(self, "Your current AOE range is set to " + range + "m", null);
return SCRIPT_CONTINUE;
}
if ((toLower(strText)).equals("detach"))
{
detachScript(self, "event.area_tefme");
removeObjVar(self, "event.tefme");
return SCRIPT_CONTINUE;
}
if ((toLower(strText)).equals("help"))
{
for (int i = 0; i < HELP_TEXT.length; i++)
{
sendSystemMessage(self, HELP_TEXT[i], null);
}
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}
}