include library.ai_lib; include library.pet_lib; include library.utils; include library.create; include library.space_combat; const string CREATURE_NAME_FILE = "item_n"; ///////////////////////////////////////// trigger OnGetAttributes(obj_id player, string[] names, string[] attribs) { int idx = utils.getValidAttributeIndex(names); obj_id itemControlDevice = getObjIdObjVar(self, "item.controlDevice"); if (hasObjVar(itemControlDevice, "dataModuleRating")) { //names[idx] = "data_module_rating"; int datastorage = getIntObjVar(self, "dataModuleRating"); //attribs[idx] = " " + datastorage; //idx++; //if (idx >= names.length) // return SCRIPT_CONTINUE; } if (hasObjVar(itemControlDevice, "usedMemory")) { names[idx] = "droid_program_expended_memory"; int usedMemory = getIntObjVar(itemControlDevice, "usedMemory"); attribs[idx] = " " + usedMemory; idx++; if (idx >= names.length) return SCRIPT_CONTINUE; } if(idx >= names.length) return SCRIPT_CONTINUE; return SCRIPT_CONTINUE; } /* trigger OnDestroy() { if ( hasObjVar( self, "item.controlDestroyed" ) ) return SCRIPT_CONTINUE;//already handled this stuff if ( hasObjVar( self, "item.controlDevice" ) ) { obj_id controlDevice = getObjIdObjVar( self, "item.controlDevice" ); if ( isIdValid( controlDevice ) ) messageTo( controlDevice, "destroySelf", null, 1, false ); } return SCRIPT_CONTINUE; } */ trigger OnObjectMenuRequest(obj_id player, menu_info mi) { if ( ai_lib.aiIsDead(player) ) return SCRIPT_CONTINUE; if ( player != getOwner( self ) ) return SCRIPT_CONTINUE; obj_id itemControlDevice = getObjIdObjVar( self, "item.controlDevice" ); if ( ai_lib.isInCombat( self ) ) return SCRIPT_CONTINUE; int opt_menu = 0; if(!space_combat.isAnInitializedNavicomp (self)) opt_menu = mi.addRootMenu(menu_info_types.INIT_NAVICOMP_DPAD, new string_id(pet_lib.MENU_FILE,"init_navicomp_dpad")); // mi.addSubMenu(opt_menu, menu_info_types.SERVER_PET_DPAD, new string_id(MENU_FILE,"menu_dpad")); return SCRIPT_CONTINUE; } trigger OnObjectMenuSelect(obj_id player, int item) { if ( ai_lib.aiIsDead(player) ) { debugServerConsoleMsg(null, "NAVICOMPUTER.OnObjectMenuSelect ***************** FAIL AT POINT A "); return SCRIPT_CONTINUE; } if ( ai_lib.isInCombat( self ) ) { debugServerConsoleMsg(null, "NAVICOMPUTER.OnObjectMenuSelect ***************** FAIL AT POINT B "); return SCRIPT_CONTINUE; } if ( player != getOwner(self) ) { debugServerConsoleMsg(null, "NAVICOMPUTER.OnObjectMenuSelect ***************** FAIL AT POINT C "); return SCRIPT_CONTINUE; } obj_id itemControlDevice = getObjIdObjVar( self, "item.controlDevice" ); //if ( !isIdValid( petControlDevice) ) if (!hasCertificationsForItem (player, self)) { //sendSystemMessageTestingOnly(player, "You aren't certified to operate this device."); string_id strSpam = new string_id("space/space_interaction", "not_certified_device"); sendSystemMessage(player, strSpam); return SCRIPT_CONTINUE; } if ( item == menu_info_types.INIT_NAVICOMP_DPAD ) { if (!verifyNoOtherInitializedNavicomps (player)) { //sendSystemMessageTestingOnly(player, "You already have an initilized and active navicomp with storage on it."); //sendSystemMessageTestingOnly(player, "You can only have a single active navicomp at a time."); //sendSystemMessageTestingOnly(player, "You must get rid of the old one before you can activate this one."); string_id strSpam = new string_id("space/space_interaction", "already_active_navicomp"); string_id strSpam2 = new string_id("space/space_interaction", "already_active_navicomp2"); string_id strSpam3 = new string_id("space/space_interaction", "already_active_navicomp3"); sendSystemMessage(player, strSpam); } else initializeNavicomputer (player, self); } else debugServerConsoleMsg(null, "NAVICOMPUTER.OnObjectMenuSelect ***************** FAIL AT POINT D "); return SCRIPT_CONTINUE; } //////////////////////////////////////////////// trigger OnGiveItem(obj_id item, obj_id player) { obj_id owner = getOwner( self ); if (!isIdValid(owner)) return SCRIPT_OVERRIDE; if ( player != owner ) return SCRIPT_OVERRIDE; obj_id itemControlDevice = getObjIdObjVar( self, "item.controlDevice" ); obj_id navicompDpad = getObjectInSlot(itemControlDevice, "datapad"); if (!isIdValid (navicompDpad)) return SCRIPT_OVERRIDE; // putIn(item, petInv); return SCRIPT_CONTINUE; } trigger OnReceivedItem(obj_id objSource, obj_id objTransferer, obj_id objItem) { // if(isPlayer(objItem)) // obj_id itemControlDevice = getObjIdObjVar(self, "item.controlDevice"); return SCRIPT_CONTINUE; } /////////////////////////////////////////////////////////// void initializeNavicomputer (obj_id player, obj_id navicomp) { createNavicomputerControlDevice(player, navicomp); //sendDirtyObjectMenuNotification (navicomp); return; } void createNavicomputerControlDevice(obj_id player, obj_id navicomp) { // Verify validity of pertinent data if ( !isIdValid( navicomp ) ) return; if ( !isIdValid( player ) ) return; obj_id datapad = utils.getPlayerDatapad(player); if ( !isIdValid( datapad ) ) return; if (!canManipulate(player, navicomp, true, true, 15, true)) return; string itemName = getStringObjVar( navicomp, "item.objectName" ); if ( itemName == null || itemName == "" ) return; string controlTemplate = "object/intangible/ship/" + itemName + ".iff"; obj_id itemControlDevice = createObject(controlTemplate, datapad, ""); if (!isIdValid(itemControlDevice)) { //sendSystemMessageTestingOnly(player, "failed to create valid controlDevice for navicomp"); string_id strSpam = new string_id("space/space_interaction", "failed_to_create_controller"); sendSystemMessage(player, strSpam); return; } else { setOwner (itemControlDevice, player); string_id nameId = new string_id(create.CREATURE_NAME_FILE, itemName); setName(itemControlDevice, nameId); attachScript(itemControlDevice, "item.tool.navicomputer_control_device"); //setObjVar( itemControlDevice, "item.current", navicomp); //setObjVar(navicomp, "item.controlDevice", itemControlDevice); setObjVar( itemControlDevice, "item.objectName", itemName); if ( hasObjVar( navicomp, "dataModuleRating" )) { int itemDataStorageModuleValue = getIntObjVar(navicomp, "dataModuleRating"); setObjVar(itemControlDevice, "dataModuleRating", itemDataStorageModuleValue); initNavicompDatapad(itemControlDevice, navicomp, player); } destroyObject(navicomp); } return; } void initNavicompDatapad(obj_id itemControlDevice, obj_id navicomp, obj_id player) { /* if (!hasObjVar( itemControlDevice, "item.current" )) return; obj_id navicomputer = getObjIdObjVar (itemControlDevice, "item.current"); */ /* if (hasObjVar( itemControlDevice, "item.objectName" )) { string objectName = getStringObjVar(navicomp, "item.objectName"); debugServerConsoleMsg(null, "***************** Just read the item.objectName StringObjVar off of the navicomp. It was: "+objectName); string datapadTemplate = "object/tangible/datapad/character_datapad.iff"; if ( objectName == "navicomputer_2" ) datapadTemplate = "object/tangible/datapad/droid_datapad_2.iff"; else if ( objectName == "navicomputer_3" ) datapadTemplate = "object/tangible/datapad/droid_datapad_3.iff"; else if ( objectName == "navicomputer_4" ) datapadTemplate = "object/tangible/datapad/droid_datapad_4.iff"; else if ( objectName == "navicomputer_5" ) datapadTemplate = "object/tangible/datapad/droid_datapad_5.iff"; else if ( objectName == "navicomputer_6" ) datapadTemplate = "object/tangible/datapad/droid_datapad_6.iff"; else datapadTemplate = "object/tangible/datapad/droid_datapad_1.iff"; debugServerConsoleMsg(null, "***************** Datapad TEMPLATE chosen for creation is: "+datapadTemplate); obj_id dpad = getObjectInSlot(itemControlDevice, "datapad"); debugServerConsoleMsg(null, "***************** OLD dpad already in navicomp controller was obj_id: "+dpad); if (isIdValid (dpad)) destroyObject (dpad); obj_id newerDatapad = createObject(datapadTemplate, itemControlDevice, "datapad"); debugServerConsoleMsg(null, "***************** NEW dpad created in navicomp controller is obj_id: "+dpad); if (isIdValid( newerDatapad )) if (!setOwner( newerDatapad, player )) debugServerConsoleMsg(null, "***************** FAILED to setowner on the new navicom controller dpad"); else debugServerConsoleMsg(null, "********** Tried to create the PCD's new datapad object, but the NEW inventory's obj_id came back as invalid. Failed to create it?"); } else debugServerConsoleMsg(null, "No object name on navicomp controller object for dpad creation purposes"); */ obj_id dpad = getObjectInSlot(itemControlDevice, "datapad"); if (isIdValid (dpad)) { //debugServerConsoleMsg(null, "We are going to try to setOwner on the dpad on the flight computer dpad."); if (!setOwner( dpad, player )) debugServerConsoleMsg(null, "***************** FAILED to setowner on the navicom controller dpad"); string_id nameId = new string_id(create.CREATURE_NAME_FILE, "flight_computer_datapad"); if (!setName( dpad, nameId )) debugServerConsoleMsg(null, "***************** FAILED to setowner on the navicom controller dpad"); } } //returns TRUE if there AREN'T any NAVICOMP CONTROL DEVICES detected on player that was passed in. boolean verifyNoOtherInitializedNavicomps (obj_id player) { if ( !isIdValid( player ) ) return false; obj_id datapad = utils.getPlayerDatapad(player); if ( !isIdValid( datapad ) ) return false; obj_id[] dpadContents = getContents(datapad); for ( int i = 0; i < dpadContents.length; i++ ) { if ( hasObjVar(dpadContents[i],"item.current" )) return false; } return true; } trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer) { //debugServerConsoleMsg(null, "NAVICOMPUTER.OnAboutToBeTransferred ********** entered function "); if ( !isIdValid( destContainer ) ) return SCRIPT_OVERRIDE; //debugServerConsoleMsg(null, "NAVICOMPUTER.OnAboutToBeTransferred ********** obj_id of destContainer is valid "); //if ( !isIdValid( transferer ) ) // commented out because during the crafting process, the item is created out of thin air, thus no transferer obj_id // return SCRIPT_OVERRIDE; //debugServerConsoleMsg(null, "NAVICOMPUTER.OnAboutToBeTransferred ********** obj_id of transferer is valid "); obj_id newMaster = getContainedBy( destContainer ); //if ( !isPlayer( newMaster ) ) // Used to check to verify transferring to player, but broke crafting. // return SCRIPT_OVERRIDE; // Can't think of a good reason to check for this anymore. // It doesn't matter if transfer to droids, as we're disabling transfer of initialized units, so what the hey? Commented out. if ( isIdValid(self) ) { obj_id currentContainer = getContainedBy( self ); if ( hasObjVar(self,"item.controlDevice" )) { //sendSystemMessageTestingOnly (transferer, "Warning: You cannot transfer a Flight-Computer that has already been activated by a pilot."); string_id strSpam = new string_id("space/space_interaction", "cant_transfer_active_computer"); sendSystemMessage(transferer, strSpam); return SCRIPT_OVERRIDE; } if (!canBeTransferred( self, newMaster, transferer )) { debugServerConsoleMsg(null, "NAVICOMPUTER.OnAboutToBeTransferred ********** canBeTransferred returned FALSE. "); return SCRIPT_OVERRIDE; } } return SCRIPT_CONTINUE; } boolean canBeTransferred( obj_id navicomp, obj_id newMaster, obj_id transferer ) { if ( space_combat.isAnInitializedNavicomp (navicomp)) if (!hasCertificationsForItem (newMaster, navicomp)) { //sendSystemMessageTestingOnly (transferer, "Warning: The newOwner does NOT have the appopriate certification for the object you are trying to give!"); string_id strSpam = new string_id("space/space_interaction", "no_cert_on_receiver"); sendSystemMessage(transferer, strSpam); return false; } return true; } /* Disabling this block because of the new paradigm for flight computers. There is no longer a tangible object once the unit is initialized trigger OnTransferred(obj_id sourceContainer, obj_id destContainer, obj_id transferer) { destroyCurrentControlDevice( self ); return SCRIPT_CONTINUE; } void destroyCurrentControlDevice( obj_id navicomp) { if ( !isIdValid( navicomp ) ) return; if ( hasObjVar(navicomp,"item.controlDevice" )) { obj_id controlDevice = getObjIdObjVar (navicomp,"item.controlDevice" ); if ( isIdValid (controlDevice) ) destroyObject (controlDevice); } return; } */