Files
dsrc/sku.0/sys.server/compiled/game/script/systems/skills/auto_level.script
T

140 lines
3.5 KiB
Plaintext

/*
systems.skills.auto_level.script
Used to cause an auto-leveling of player
*/
//libraries
include library.respec;
include library.sui;
include library.utils;
//constants
const string PID_NAME = "autoLevel";
const string OBJVAR_AUTO_LEVEL_TO = "autoLevelTo";
const string_id SID_CONSUME_PROMPT = new string_id("spam", "consume_auto_level_prompt");
const string_id SID_CONSUME_TITLE = new string_id("spam", "consume_auto_level_title");
const string_id SID_CONSUME_ITEM = new string_id("spam", "consume_auto_level");
const string_id SID_CONSUME_TOO_HIGH = new string_id("spam", "consume_auto_level_too_high");
//triggers
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
//can only consume if you have it picked up
if(utils.isNestedWithinAPlayer(self))
{
mi.addRootMenu (menu_info_types.SERVER_MENU1, SID_CONSUME_ITEM);
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
sendDirtyObjectMenuNotification(self);
//can only use it if it is in your inventory
if (item == menu_info_types.SERVER_MENU1 && utils.isNestedWithinAPlayer(self))
{
//validate for existing SUI
if(sui.hasPid(player, PID_NAME))
{
int pid = sui.getPid(player, PID_NAME);
forceCloseSUIPage(pid);
}
int autoLevelTo = getIntObjVar(self, OBJVAR_AUTO_LEVEL_TO);
int currentLevel = getLevel(player);
if(currentLevel >= autoLevelTo)
{
sendSystemMessage(player, SID_CONSUME_TOO_HIGH);
sui.removePid(player, PID_NAME);
return SCRIPT_CONTINUE;
}
//double check that they want to consume this item
int pid = sui.msgbox(self, player, "@" + SID_CONSUME_PROMPT, sui.YES_NO, "@" + SID_CONSUME_TITLE, "handlerSuiAutoLevel");
sui.setPid(player, pid, PID_NAME);
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}
trigger OnGetAttributes(obj_id player, string[] names, string[] attribs)
{
int idx = utils.getValidAttributeIndex(names);
if(idx == -1)
return SCRIPT_CONTINUE;
if(!exists(self))
return SCRIPT_CONTINUE;
if(hasObjVar(self, OBJVAR_AUTO_LEVEL_TO))
{
names[idx] = "level";
attribs[idx] = "" + getIntObjVar(self, OBJVAR_AUTO_LEVEL_TO);
idx++;
}
return SCRIPT_CONTINUE;
}
//messageHandlers
messageHandler handlerSuiAutoLevel ()
{
//check params
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
//get players id
obj_id player = sui.getPlayerId(params);
if(!isIdValid(player))
return SCRIPT_CONTINUE;
//get button pressed
int bp = sui.getIntButtonPressed(params);
//if they pressed cancel then we bail out and do nothing
if ( bp == sui.BP_CANCEL )
{
sui.removePid(player, PID_NAME);
return SCRIPT_CONTINUE;
}
if(!sui.hasPid(player, PID_NAME))
return SCRIPT_CONTINUE;
int autoLevelTo = getIntObjVar(self, OBJVAR_AUTO_LEVEL_TO);
int currentLevel = getLevel(player);
if(currentLevel >= autoLevelTo)
{
sendSystemMessage(player, SID_CONSUME_TOO_HIGH);
sui.removePid(player, PID_NAME);
CustomerServiceLog("auto_level", "Player " + getPlayerName(player) + "(" + player + ") tried to use the auto-level holocron and level their character from " + currentLevel + " to " + autoLevelTo + ", but could not because their current level is higher than the auto-level.");
return SCRIPT_CONTINUE;
}
if(respec.autoLevelPlayer(player, autoLevelTo, true))
{
CustomerServiceLog("auto_level", "Player " + getPlayerName(player) + "(" + player + ") chose to use the auto-level holocron and level their character from " + currentLevel + " to " + autoLevelTo + ".");
destroyObject(self);
sui.removePid(player, PID_NAME);
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}