include library.create; include library.utils; include library.player_structure; include library.sui; include library.static_item; include library.space_utils; include library.space_transition; /***** TRIGGERS ********************************************************/ //Call registerSelf trigger OnInitialize() { //obj_id topContainer = getTopMostContainer(getSelf()); obj_id container = getLocation(self).cell; if(isIdValid(container)) { boolean check = registerSelf(container); if(check) { string templateString = getTemplateName(self); if(templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_backdrop_generator.iff")) { if(hasObjVar(self, "paintingId")) { obj_id oldBackdrop = getObjIdObjVar(self, "paintingId"); if(isIdValid(oldBackdrop)) { destroyObject(oldBackdrop); } removeObjVar(self, "paintingId"); location backdropLocation = getLocation(self); float myYaw = getYaw (self); backdropLocation.y += 0.3f; string staticString = getStringObjVar(self, "paintingType"); obj_id backdropId = static_item.createNewItemFunction(staticString, container, backdropLocation); if (!isIdValid (backdropId) || isIdNull (backdropId)) { return SCRIPT_CONTINUE; } else { setYaw (backdropId, myYaw); setObjVar(self, "paintingId", backdropId); } } } } } return SCRIPT_CONTINUE; } trigger OnAboutToBeTransferred (obj_id destContainer, obj_id transferer) { obj_id topContainer = getTopMostContainer(self); // Check source container. If needed call unregisterSelf() // Check destination containr, is it valid? If so call register self // If the item is a backdrop generator we want to clear any existing backdrop associated with the generator string templateString = getTemplateName(self); if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_backdrop_generator.iff")) { if(hasObjVar(self, "paintingId")) { obj_id oldBackdrop = getObjIdObjVar(self, "paintingId"); destroyObject(oldBackdrop); removeObjVar(self, "paintingId"); } } if (templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_fog_machine.iff")) { if(hasObjVar(self, "fogId")) { obj_id oldFog = getObjIdObjVar(self, "fogId"); if(isIdValid(oldFog)) { destroyObject(oldFog); } removeObjVar(self, "fogId"); } } // We want to handle leaving the old cell obj_id container = getLocation(self).cell; if(isIdValid(container) && checkArray(container)) { boolean unreg = unregisterSelf(); } if(isIdValid(destContainer)) { boolean reg = registerSelf(destContainer); } return SCRIPT_CONTINUE; } /*This method should verify that the prop meets all the expected conditions for interacting with a stage controller: // - The prop must be in a player house or a POB ship */ // Verify that items in a backpack or in a player is rejected if the player is inside or outside // Verify that an item in a house, on the floor is accepted boolean checkLocation(obj_id cell) { if(getCellName(cell)==null) { return false; } if (!utils.isNestedWithinAPlayer (cell)) { obj_id house = getTopMostContainer(cell); obj_id ship = space_transition.getContainingShip(getSelf()); string templateName =""; if(isIdValid(ship)) { templateName = getTemplateName(ship); } if(isIdValid(house) && (player_structure.isBuilding(house) || space_utils.isPobType(templateName))) { return true; } } return false; } // This method will add the prop (self) to an scriptVar array on the cell (pending a successful locations check). // Check the cell for an appopriate array // get the array if it exists else create a new one // add self to array // add array to cell as a script var boolean registerSelf(obj_id cell) { obj_id self = getSelf(); if(isIdValid(cell) && !checkArray(cell) && checkLocation(cell)) { string template = getTemplate(); resizeable obj_id[] objectList = new Vector(); obj_id topContainer = getTopMostContainer(cell); if(utils.hasScriptVar(topContainer, template)) { resizeable obj_id[] list = utils.getResizeableObjIdArrayScriptVar(topContainer, template); for(int i = 0; i < list.length; i++) { objectList.addElement(list[i]); } } objectList.addElement(self); utils.setScriptVar(topContainer, template, objectList); return true; } return false; } // This method will unregister the prop from the current cell containing the prop. // Check for exisiting array on containing cell // Get array from containing cell // Remove self from array // add array to cell boolean unregisterSelf() { obj_id topContainer = getTopMostContainer(getSelf()); obj_id self = getSelf(); string template = getTemplate(); if(isIdValid(topContainer) && utils.hasScriptVar(topContainer, template)) { resizeable obj_id[] objectList = utils.getResizeableObjIdArrayScriptVar(topContainer, template); for(int i = 0; i < objectList.length; i++) { if(objectList[i].equals(self)) { objectList.removeElement(self); if(objectList.length > 0) { utils.setScriptVar(topContainer, template, objectList); } else { utils.removeScriptVar(topContainer, template); } return true; } } } return false; } //Check container for array //Check array for self boolean checkArray(obj_id cell) { obj_id self = getSelf(); obj_id topContainer = getTopMostContainer(self); string item = getTemplate(); if(isIdValid(topContainer) && utils.hasScriptVar(topContainer, item)) { resizeable obj_id[] objectList = utils.getResizeableObjIdArrayScriptVar(topContainer, item); for(int i = 0; i < objectList.length; i++) { if(objectList[i] == self) { return true; } } } return false; } //Gets the template for the prop type based on it's object template string getTemplate() { string templateString = getTemplateName(getSelf()); string template = ""; if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_backdrop_generator.iff")) { template = "entertainer_console.backdrop"; } if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_pyro_machine.iff")) { template = "entertainer_console.pyrotechnic"; } if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_smoke_machine.iff")) { template = "entertainer_console.smoke"; } if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_fog_machine.iff")) { template = "entertainer_console.fog"; } if ( templateString != null && templateString.equals("object/tangible/item/entertainer_console/stage_light.iff" )) { template = "entertainer_console.light"; } return template; }