/* item.instance_reset.script Used to reset an instance of the players choice */ //libraries include library.hue; include library.instance; include library.player_structure; include library.prose; include library.space_transition; include library.sui; include library.utils; //constants const string PID_NAME = "hangar"; const string SCRIPT_VAR_SCD_LIST = "hangar.scds"; const string SCRIPT_VAR_RESTORING_SHIP = "hangar.restoring"; const string SCRIPT_VAR_DECORATING_SHIP = "hangar.decorating"; const string TERMINAL_OBJVAR_DECORATED_LIST = "hangar.decoratedShips"; const string SHIP_OBJVAR_DECORATED_SHIP = "hangar.decoratedShip"; const string CUSTOMER_SERVICE_LOG = "hangar"; const int MESSAGE_DELAY = 5; const int MAX_ITERATIONS = 5; const int MAX_STORED_SHIPS = 10; const int MAX_STORED_POBS = 1; const string_id SID_WHILE_DEAD = new string_id("player_structure", "while_dead" ); const string_id SID_TERMINAL_MANAGEMENT = new string_id("player_structure", "hangar_management"); const string_id SID_HANGAR_STORE_SHIPS = new string_id("player_structure", "hangar_store_ships"); const string_id SID_HANGAR_RESTORE_SHIPS = new string_id("player_structure", "hangar_restore_ships"); const string_id SID_INTIALIZING_HANGAR = new string_id("player_structure", "intializing_hangar"); const string_id SID_NO_SHIPS = new string_id("player_structure", "no_ships"); const string_id SID_SHIP_LIST_STORE_PROMPT = new string_id("player_structure", "ship_list_store_prompt"); const string_id SID_SHIP_LIST_RESTORE_PROMPT = new string_id("player_structure", "ship_list_restore_prompt"); const string_id SID_LIST_TITLE = new string_id("player_structure", "list_title"); const string_id SID_HANGAR_COULD_NOT_INTIALIZE = new string_id("player_structure", "hangar_could_not_intialize"); const string_id SID_SHIP_MOVE_STORE_PROMPT = new string_id("player_structure", "move_store_prompt"); const string_id SID_SHIP_MOVE_RESTORE_PROMPT = new string_id("player_structure", "move_restore_prompt"); const string_id SID_SHIP_MOVE_TITLE = new string_id("player_structure", "ship_move_title"); const string_id SID_SHIP_WAS_STORED = new string_id("player_structure", "ship_was_stored"); const string_id SID_SHIP_WAS_RESTORED = new string_id("player_structure", "ship_was_restored"); const string_id SID_TRANSFER_FAILED_GENERIC = new string_id("player_structure", "transfer_failed_generic"); const string_id SID_MAX_SHIPS_STORED = new string_id("player_structure", "max_ships_stored"); const string_id SID_PLACE_SHIP_DECORATION = new string_id("player_structure", "hangar_place_ship_decoration"); const string_id SID_PLACE_SHIP_DECORATION_PROMPT = new string_id("player_structure", "hangar_place_ship_decoration_prompt"); const string_id SID_PLACE_SHIP_DECORATION_SUCCESS = new string_id("player_structure", "hangar_place_ship_decoration_success"); const string_id SID_REMOVE_SHIP_DECORATION_SUCCESS = new string_id("player_structure", "hangar_remove_ship_decoration_success"); const string HANGAR_MINI_SHIPS_TABLE = "datatables/tcg/hangar_mini_ships.iff"; trigger OnObjectMenuRequest(obj_id player, menu_info mi) { obj_id structure = self; //not while dead or incapped if(isDead(player) || isIncapacitated(player) ) { sendSystemMessage( player, SID_WHILE_DEAD ); return SCRIPT_CONTINUE; } if(player_structure.isStructureCondemned(self) && player_structure.isOwner(structure, player)) { player_structure.doCondemnedSui(self, player); return SCRIPT_OVERRIDE; } //only the owner can use the terminal if(player_structure.isOwner(structure, player)) { boolean canStoreShips = false; boolean canRecallShips = false; //get all the scds in the players datapad obj_id[] datapadShipControlDevices = space_transition.findShipControlDevicesForPlayer(player); if(datapadShipControlDevices != null && datapadShipControlDevices.length > 0) { canStoreShips = true; } obj_id playerHangar = utils.getPlayerHangar(player); // There is no need to display the ship restore and ship decoration menu items if there are no ships in the hangar. if( isIdValid(playerHangar) && hasObjVar(player, player_structure.OBJVAR_HANGAR_CREATED) ) { obj_id[] shipControlDevices = space_transition.findShipControlDevicesInHangarSlot(player); if( shipControlDevices != null && shipControlDevices.length > 0 ) { for ( int i = 0; i < shipControlDevices.length; ++i ) { obj_id storedShip = shipControlDevices[i]; if( isIdValid(storedShip) ) { if ( !hasObjVar(storedShip, player_structure.OBJVAR_STORED_HANGAR_LITE) ) { canRecallShips = true; break; } } } } } if(canStoreShips || canRecallShips) { int management_root = mi.addRootMenu(menu_info_types.SERVER_TERMINAL_MANAGEMENT, SID_TERMINAL_MANAGEMENT); if(canStoreShips) { mi.addSubMenu(management_root, menu_info_types.SERVER_MENU1, SID_HANGAR_STORE_SHIPS); } if(canRecallShips) { mi.addSubMenu(management_root, menu_info_types.SERVER_MENU2, SID_HANGAR_RESTORE_SHIPS); mi.addSubMenu(management_root, menu_info_types.SERVER_MENU3, SID_PLACE_SHIP_DECORATION); } } } return SCRIPT_CONTINUE; } trigger OnObjectMenuSelect(obj_id player, int item) { sendDirtyObjectMenuNotification(self); obj_id structure = self; //find the hangar on the player obj_id playerHangar = utils.getPlayerHangar(player); //validate the hangar //if it doesnt exist we need to create it if(!isIdValid(playerHangar) && !hasObjVar(player, player_structure.OBJVAR_HANGAR_CREATED)) { playerHangar = createObject("object/tangible/datapad/character_hangar_datapad.iff", player, "hangar"); //verify that a hangar object was created properly if(!isIdValid(playerHangar)) { CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+") tried to create a hangar in their 'hangar' slot, and failed. Usually this means there is already a hangar in that slot, or for some reason the player is missing that slot."); sendSystemMessage(player, SID_HANGAR_COULD_NOT_INTIALIZE); return SCRIPT_CONTINUE; } //objvar is stamped on player with the OID of the hangar when it is created and attached properly setObjVar(player, player_structure.OBJVAR_HANGAR_CREATED, playerHangar); //we need to persist this object persistObject(playerHangar); //tell the player we are initializing the hangar sendSystemMessage(player, SID_INTIALIZING_HANGAR); dictionary dict = new dictionary(); dict.put("player", player); dict.put("iteration", 1); dict.put("storing", true); //wait 5 seconds to make sure the hangar object persists and attaches messageTo(self, "handleHangarInitialize", dict, MESSAGE_DELAY, false); return SCRIPT_CONTINUE; } //we have an objvar saying we have a hangar, yet returned null when we tried to get its id if(!isIdValid(playerHangar) && hasObjVar(player, player_structure.OBJVAR_HANGAR_CREATED)) { obj_id storeHangerId = getObjIdObjVar(player, player_structure.OBJVAR_HANGAR_CREATED); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+") returned an invalid id for their hangar slot, but had the objar stating they have a hangar. Hangar objvar Id is " + storeHangerId); sendSystemMessage(player, SID_TRANSFER_FAILED_GENERIC); return SCRIPT_CONTINUE; } //make sure they dont already have a UI up if(sui.hasPid(player, PID_NAME)) { int pid = sui.getPid(player, PID_NAME); forceCloseSUIPage(pid); } //store ships if(item == menu_info_types.SERVER_MENU1 && player_structure.isOwner(structure, player)) { //function used to list all the ships the player can store callSuiOfShipsToStore(player, self, playerHangar); } //recall ships else if(item == menu_info_types.SERVER_MENU2 && player_structure.isOwner(structure, player)) { //function used to list all the ships the player can restore callSuiOfStoredShips(player, self, playerHangar); } // Place a ship decoration else if(item == menu_info_types.SERVER_MENU3 && player_structure.isOwner(structure, player)) { placeShipDecoration(player, self, playerHangar); } 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(!player_structure.isOwner(self, player)) return SCRIPT_CONTINUE; obj_id playerHangar = utils.getPlayerHangar(player); if(!isIdValid(playerHangar)) { return SCRIPT_CONTINUE; } resizeable string[] storedShipNames = new string[0]; obj_id[] shipsStored = space_transition.findShipControlDevicesInHangarSlot(player); if( shipsStored == null || shipsStored.length <= 0 ) { names[idx] = "ship_in_hangar"; attribs[idx] = "none"; idx++; } else { for ( int i = 0; i < shipsStored.length; ++i ) { obj_id storedShip = shipsStored[i]; if( isIdValid(storedShip) ) { if ( !hasObjVar(storedShip, player_structure.OBJVAR_STORED_HANGAR_LITE) ) { utils.addElement(storedShipNames, getEncodedName(storedShip)); } } } if ( storedShipNames == null || storedShipNames.length <= 0 ) { names[idx] = "ship_in_hangar"; attribs[idx] = "none"; idx++; } else { for (int j = 0; j < storedShipNames.length; ++j) { names[idx] = "ship_in_hangar"; attribs[idx] = storedShipNames[j]; idx++; } } } return SCRIPT_CONTINUE; } /* * * GENERAL FUNCTIONS * */ void placeShipDecoration(obj_id player, obj_id hangarControls, obj_id playerHangar) { if(!isIdValid(player) || !exists(player) || !isIdValid(hangarControls) || !exists(hangarControls) || !isIdValid(playerHangar) || !exists(playerHangar)) { return; } //get all the scds in the players hangar obj_id[] shipControlDevices = getContents(playerHangar); resizeable obj_id[] hangarStoredShips = new obj_id[0]; if( shipControlDevices == null || shipControlDevices.length <= 0 ) { sendSystemMessage(player, SID_NO_SHIPS); return; } for ( int i = 0; i < shipControlDevices.length; ++i ) { obj_id storedShip = shipControlDevices[i]; if( isIdValid(storedShip) ) { if ( !hasObjVar(storedShip, player_structure.OBJVAR_STORED_HANGAR_LITE) ) { utils.addElement(hangarStoredShips, storedShip); } } } if( hangarStoredShips == null || hangarStoredShips.length <= 0 ) { sendSystemMessage(player, SID_NO_SHIPS); return; } //track the unlocalized version utils.setScriptVar(hangarControls, SCRIPT_VAR_SCD_LIST, hangarStoredShips); //have to localize it for the player string[] localizedList = new string[hangarStoredShips.length]; for(int i = 0; i < localizedList.length; ++i) { localizedList[i] = getEncodedName(hangarStoredShips[i]); if(hasObjVar(hangarStoredShips[i], SHIP_OBJVAR_DECORATED_SHIP)) { localizedList[i] += " (Placed)"; } } //display list to player utils.setScriptVar(hangarControls, SCRIPT_VAR_DECORATING_SHIP, true); int pid = sui.listbox(hangarControls, player, "@" + SID_PLACE_SHIP_DECORATION_PROMPT, sui.OK_CANCEL, "@" + SID_LIST_TITLE, localizedList, "onShipDecorationResponse", true, false); sui.setPid(player, pid, PID_NAME); } //creates a sui list box of all ships in players datapad boolean callSuiOfShipsToStore(obj_id player, obj_id terminal, obj_id hangar) { if(!isIdValid(player) || !exists(player)) return false; if(!isIdValid(terminal) || !exists(terminal)) return false; if(!isIdValid(hangar) || !exists(hangar)) return false; //there is a cap on the number of ships you can have in your hangar obj_id[] shipsInHangar = getContents(hangar); resizeable obj_id[] hangarStoredShips = new obj_id[0]; if( shipsInHangar != null && shipsInHangar.length > 0 ) { for ( int i = 0; i < shipsInHangar.length; ++i ) { obj_id storedShip = shipsInHangar[i]; if( isIdValid(storedShip) ) { if ( !hasObjVar(storedShip, player_structure.OBJVAR_STORED_HANGAR_LITE) ) { utils.addElement(hangarStoredShips, storedShip); } } } if ( hangarStoredShips != null && hangarStoredShips.length >= MAX_STORED_SHIPS ) { sendSystemMessage(player, SID_MAX_SHIPS_STORED); return false; } } //get all the scds in the players datapad obj_id[] shipControlDevices = space_transition.findShipControlDevicesForPlayer(player); if(shipControlDevices == null || shipControlDevices.length <= 0) { sendSystemMessage(player, SID_NO_SHIPS); return false; } //track the unlocalized version utils.setScriptVar(terminal, SCRIPT_VAR_SCD_LIST, shipControlDevices); //have to localize it for the player string[] localizedList = new string[shipControlDevices.length]; for(int i = 0; i < localizedList.length; ++i) { localizedList[i] = getEncodedName(shipControlDevices[i]); } //display list to player int pid = sui.listbox(terminal, player, "@" + SID_SHIP_LIST_STORE_PROMPT, sui.OK_CANCEL, "@" + SID_LIST_TITLE, localizedList, "onShipListResponse", true, false); sui.setPid(player, pid, PID_NAME); return true; } //creates a sui list box of all ships in players hangar slot boolean callSuiOfStoredShips(obj_id player, obj_id terminal, obj_id hangar) { if(!isIdValid(player) || !exists(player)) return false; if(!isIdValid(terminal) || !exists(terminal)) return false; if(!isIdValid(hangar) || !exists(hangar)) return false; //get all the scds in the players hangar obj_id[] shipControlDevices = getContents(hangar); resizeable obj_id[] hangarStoredShips = new obj_id[0]; if( shipControlDevices == null || shipControlDevices.length <= 0 ) { sendSystemMessage(player, SID_NO_SHIPS); return false; } for ( int i = 0; i < shipControlDevices.length; ++i ) { obj_id storedShip = shipControlDevices[i]; if( isIdValid(storedShip) ) { if ( !hasObjVar(storedShip, player_structure.OBJVAR_STORED_HANGAR_LITE) ) { utils.addElement(hangarStoredShips, storedShip); } } } if( hangarStoredShips == null || hangarStoredShips.length <= 0 ) { sendSystemMessage(player, SID_NO_SHIPS); return false; } //track the unlocalized version utils.setScriptVar(terminal, SCRIPT_VAR_SCD_LIST, hangarStoredShips); //have to localize it for the player string[] localizedList = new string[hangarStoredShips.length]; for(int i = 0; i < localizedList.length; ++i) { localizedList[i] = getEncodedName(hangarStoredShips[i]); } //display list to player utils.setScriptVar(terminal, SCRIPT_VAR_RESTORING_SHIP, true); int pid = sui.listbox(terminal, player, "@" + SID_SHIP_LIST_RESTORE_PROMPT, sui.OK_CANCEL, "@" + SID_LIST_TITLE, localizedList, "onShipListResponse", true, false); sui.setPid(player, pid, PID_NAME); return true; } /* * * MESSAGE HANDLERS * */ messageHandler handleHangarInitialize() { //perform validation if(params == null || params.isEmpty()) return SCRIPT_CONTINUE; obj_id player = params.getObjId("player"); if(!isIdValid(player) || !exists(player)) return SCRIPT_CONTINUE; //keeps track of how many times we have tried to find the hangar int iteration = params.getInt("iteration"); //hangar is a slot on the player obj_id playerHangar = utils.getPlayerHangar(player); //if we cannot find it, we need to message again and try then if(!isIdValid(playerHangar)) { if(iteration > MAX_ITERATIONS) { sendSystemMessage(player, SID_HANGAR_COULD_NOT_INTIALIZE); obj_id storeHangarId = getObjIdObjVar(player, player_structure.OBJVAR_HANGAR_CREATED); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+")'s Hangar could not be found after 5 5 second messageTos. Hangar Id should be "+storeHangarId+", we know this from the objvar set on the player when the hangar is first created."); return SCRIPT_CONTINUE; } params.put("iteration", ++iteration); sendSystemMessage(player, SID_INTIALIZING_HANGAR); messageTo(self, "handleHangarInitialize", params, MESSAGE_DELAY, false); return SCRIPT_CONTINUE; } //tracks whether we are going to store the ship or not boolean storing = params.getBoolean("storing"); //one SUI for storing one for recalling if(storing) callSuiOfShipsToStore(player, self, playerHangar); else callSuiOfStoredShips(player, self, playerHangar); return SCRIPT_CONTINUE; } messageHandler onShipDecorationResponse() { obj_id player = params.getObjId("player"); obj_id playerHangar = utils.getPlayerHangar(player); // debugSpeakMsg(player, "onShipDecorationResponse"); if(!isIdValid(player) || !exists(player) || !isIdValid(self) || !exists(self) || !isIdValid(playerHangar) || !exists(playerHangar)) { return SCRIPT_CONTINUE; } if(!utils.hasScriptVar(self, SCRIPT_VAR_SCD_LIST)) { // debugSpeakMsg(player, "!utils.hasScriptVar(self, SCRIPT_VAR_SCD_LIST)"); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } //get button pressed int bp = sui.getIntButtonPressed(params); int idx = sui.getListboxSelectedRow(params); //if they pressed cancel then we bail out and do nothing if(bp == sui.BP_CANCEL || idx == -1) { sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } int pageId = params.getInt("pageId"); //double check that this is the only SUI window open if(!sui.hasPid(player, PID_NAME)) { // debugSpeakMsg(player, "!sui.hasPid(player, PID_NAME)"); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } int pid = sui.getPid(player, PID_NAME); //verify that this UI matches the pid stored on player if(pageId != pid) { // debugSpeakMsg(player, "pageId != pid"); forceCloseSUIPage(pageId); forceCloseSUIPage(pid); sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } //check to make sure player is still the owner if(!player_structure.isOwner(self, player)) { // debugSpeakMsg(player, "!player_structure.isOwner(self, player)"); sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } //get the list of ships off terminal obj_id[] shipList = utils.getObjIdArrayScriptVar(self, SCRIPT_VAR_SCD_LIST); if(shipList == null || shipList.length <= 0) { // debugSpeakMsg(player, "shipList == null || shipList.length <= 0"); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } //dont need the whole list anymore utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); //get ship selected obj_id shipSelected = shipList[idx]; if(!isIdValid(shipSelected) || !exists(shipSelected)) { // debugSpeakMsg(player, "!isIdValid(shipSelected) || !exists(shipSelected)"); utils.removeScriptVar(self, SCRIPT_VAR_DECORATING_SHIP); return SCRIPT_CONTINUE; } // If this ship is already in the house, then destroy its model. if(hasObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP)) { // debugSpeakMsg(player, "hasObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP)"); obj_id shipDecoration = getObjIdObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); if(!isIdValid(shipDecoration) || !exists(shipDecoration)) { removeObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); return SCRIPT_CONTINUE; } destroyObject(shipDecoration); removeObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); sendSystemMessage(player, SID_REMOVE_SHIP_DECORATION_SUCCESS); } // If this ship is not in the house, then place a model at the player. else { obj_id objShip = space_transition.getShipFromShipControlDevice(shipSelected); if(!isIdValid(objShip)) { // debugSpeakMsg(player, "!isIdValid(objShip)"); return SCRIPT_CONTINUE; } string strChassisType = getShipChassisType(objShip); dictionary hangarMiniShip = new dictionary(); hangarMiniShip = dataTableGetRow(HANGAR_MINI_SHIPS_TABLE, strChassisType); if(hangarMiniShip == null) { // debugSpeakMsg(player, "hangarMiniShip == null"); return SCRIPT_CONTINUE; } string template = hangarMiniShip.getString("template"); if(template == null || template.length() <= 0) { // debugSpeakMsg(player, "template == null || template.length() <= 0"); return SCRIPT_CONTINUE; } location loc = getLocation(player); obj_id house = getTopMostContainer(player); if(!isIdValid(house) || !exists(house)) { return SCRIPT_CONTINUE; } if(!player_structure.isOwner(house, player)) { // debugSpeakMsg(player, "!player_structure.isOwner(house, player)"); return SCRIPT_CONTINUE; } string houseTemplate = getTemplateName(house); if(!houseTemplate.equals("object/building/player/player_house_hangar.iff")) { // debugSpeakMsg(player, "!houseTemplate.equals(object/building/player/player_house_hangar.iff)"); return SCRIPT_CONTINUE; } obj_id toyShip = createObject(template, loc); if(isIdValid(toyShip)) { persistObject(toyShip); string houseName = getName(house); // Unlocalized houseName = localize(new string_id(houseName.substring(0, houseName.indexOf(":")), houseName.substring(houseName.indexOf(":") + 1, houseName.length()))); setObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP, toyShip); setObjVar(toyShip, "validHouse", "object/building/player/player_house_hangar.iff"); setObjVar(toyShip, "validHouseName", houseName); attachScript(toyShip, "item.special.nomove_furniture_house_only"); string index = "/shared_owner/index_texture_1"; if(strChassisType.equals("player_yt2400")) { index = "/private/index_texture_1"; } // Colorization and texturing int intColor0 = hue.getVarColorIndex(objShip, "/shared_owner/index_color_1"); int intColor1 = hue.getVarColorIndex(objShip, "/shared_owner/index_color_2"); int intTextureIndex = getRangedIntCustomVarValue(objShip, index); if(intColor0 > -1) hue.setColor(toyShip, "/shared_owner/index_color_1", intColor0); if(intColor1 > -1) hue.setColor(toyShip, "/shared_owner/index_color_2", intColor1); if(intTextureIndex > -1) hue.setRangedIntCustomVar(toyShip, index, intTextureIndex); sendSystemMessage(player, SID_PLACE_SHIP_DECORATION_SUCCESS); // debugSpeakMsg(player, "toyShip: " + toyShip + " template: " + template + " intColor0: " + intColor0 + " intColor1: " + intColor1 + " intTextureIndex: " + intTextureIndex); } } return SCRIPT_CONTINUE; } //handler for the list of instanes to choose from messageHandler onShipListResponse() { if(params == null || params.isEmpty()) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //get players id obj_id player = sui.getPlayerId(params); if(!isIdValid(player)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //we need the list or we cannot continue if(!utils.hasScriptVar(self, SCRIPT_VAR_SCD_LIST)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //get button pressed int bp = sui.getIntButtonPressed(params); int idx = sui.getListboxSelectedRow(params); //if they pressed cancel then we bail out and do nothing if ( bp == sui.BP_CANCEL || idx == -1) { sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } int pageId = params.getInt("pageId"); //double check that this is the only SUI window open if(!sui.hasPid(player, PID_NAME)) { utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } int pid = sui.getPid(player, PID_NAME); //verify that this UI matches the pid stored on player if(pageId != pid) { forceCloseSUIPage(pageId); forceCloseSUIPage(pid); sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //check to make sure player is still the owner if(!player_structure.isOwner(self, player)) { sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+") did NOT transfer a ship because they are no longer the owner of the structure."); return SCRIPT_CONTINUE; } //get the list of ships off terminal obj_id[] shipList = utils.getObjIdArrayScriptVar(self, SCRIPT_VAR_SCD_LIST); if(shipList == null || shipList.length <= 0) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //dont need the whole list anymore utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); //get ship selected obj_id shipSelected = shipList[idx]; if(!isIdValid(shipSelected) || !exists(shipSelected)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //set the ID of the scd chosen on object utils.setScriptVar(self, SCRIPT_VAR_SCD_LIST, shipSelected); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+") chose SCD " + getEncodedName(shipSelected) + "("+shipSelected+") as the ship to move."); //confirm that they want to move this ship //different prompt depending on if they are storing or restoring string prompt = "@" + SID_SHIP_MOVE_RESTORE_PROMPT; if(!utils.hasScriptVar(self, SCRIPT_VAR_RESTORING_SHIP)) prompt = "@" + SID_SHIP_MOVE_STORE_PROMPT; int newPid = sui.msgbox(self, player, prompt, sui.YES_NO, "@" + SID_SHIP_MOVE_TITLE, "handlerConfirmShipMove"); sui.setPid(player, newPid, PID_NAME); return SCRIPT_CONTINUE; } //handler for confirmation of reseting timer messageHandler handlerConfirmShipMove() { if(params == null || params.isEmpty()) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //get players id obj_id player = sui.getPlayerId(params); if(!isIdValid(player)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //without the Id of SCD we cannot do anything if(!utils.hasScriptVar(self, SCRIPT_VAR_SCD_LIST)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); 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); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } int pageId = params.getInt("pageId"); //double check that this is the only SUI window open if(!sui.hasPid(player, PID_NAME)) { utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } int pid = sui.getPid(player, PID_NAME); //verify this handler is being fired for the pid stored on player if(pageId != pid) { forceCloseSUIPage(pageId); forceCloseSUIPage(pid); sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //make sure the player is still the owner if(!player_structure.isOwner(self, player)) { sui.removePid(player, PID_NAME); utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "Player " + getPlayerName(player) + "("+player+") did not transfer a ship because they are no longer the owner of the structure."); return SCRIPT_CONTINUE; } //get the name of the instance to remove obj_id shipSelected = utils.getObjIdScriptVar(self, SCRIPT_VAR_SCD_LIST); if(!isIdValid(shipSelected) || !exists(shipSelected)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //dont need to store the name anymore utils.removeScriptVar(self, SCRIPT_VAR_SCD_LIST); obj_id playerHangar = utils.getPlayerHangar(player); obj_id datapad = utils.getPlayerDatapad(player); if(!isIdValid(playerHangar)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } if(!isIdValid(datapad)) { utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); return SCRIPT_CONTINUE; } //if we are not storing a ship, then we are restoring a ship if(!utils.hasScriptVar(self, SCRIPT_VAR_RESTORING_SHIP)) { //when storing a ship, we hide it in the players hangar. //hangar is like the datapad, only it is invisible to the player if(putIn(shipSelected, playerHangar, player)) { CustomerServiceLog(CUSTOMER_SERVICE_LOG, "SCD "+getEncodedName(shipSelected)+" ("+shipSelected+") was transferred to Player " + getPlayerName(player) + "("+player+")'s hangar ("+playerHangar+"), using the hangar terminal."); //tell the player the transfer was a success prose_package pp = new prose_package(); prose.setStringId(pp, SID_SHIP_WAS_STORED); prose.setTT(pp, getEncodedName(shipSelected)); sendSystemMessageProse(player, pp); } else { sendSystemMessage(player, SID_TRANSFER_FAILED_GENERIC); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "SCD "+getEncodedName(shipSelected)+" ("+shipSelected+") was NOT transferred to Player " + getPlayerName(player) + "("+player+")'s hangar ("+playerHangar+"), the putIn command failed."); } } //we are restoring the ship from the players hangar to their datapad else { //stroed ships are in the players hangar slot, and need to be moved back to their datapad if(putIn(shipSelected, datapad, player)) { obj_id shipDecoration = getObjIdObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); if(!isIdValid(shipDecoration) || !exists(shipDecoration)) { removeObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); } else { destroyObject(shipDecoration); removeObjVar(shipSelected, SHIP_OBJVAR_DECORATED_SHIP); } CustomerServiceLog(CUSTOMER_SERVICE_LOG, "SCD "+getEncodedName(shipSelected)+" ("+shipSelected+") was transferred back to Player " + getPlayerName(player) + "("+player+")'s datapad ("+datapad+"), using the hangar terminal.."); //tell the player what lockout was reset prose_package pp = new prose_package(); prose.setStringId(pp, SID_SHIP_WAS_RESTORED); prose.setTT(pp, getEncodedName(shipSelected)); sendSystemMessageProse(player, pp); } else { sendSystemMessage(player, SID_TRANSFER_FAILED_GENERIC); CustomerServiceLog(CUSTOMER_SERVICE_LOG, "SCD "+getEncodedName(shipSelected)+" ("+shipSelected+") was NOT transferred to Player " + getPlayerName(player) + "("+player+")'s datapad ("+datapad+"), the putIn command failed."); } utils.removeScriptVar(self, SCRIPT_VAR_RESTORING_SHIP); } return SCRIPT_CONTINUE; }