//------------------------------------------------ // locked_slicable.scriptlib // Brandon Reinhart // // Attach to containers that can be sliced. //------------------------------------------------ //------------------------------------------------ // Includes //------------------------------------------------ include library.slicing; include library.xp; include library.utils; //------------------------------------------------ // Constants //------------------------------------------------ const string_id SID_SLICE = new string_id("slicing/slicing", "slice"); const string_id SID_LOCKED = new string_id("slicing/slicing", "locked"); const string_id SID_BROKEN = new string_id("slicing/slicing", "broken"); const string_id SID_SUCCESS = new string_id("slicing/slicing", "container_success"); const string_id SID_FAIL = new string_id("slicing/slicing", "container_fail"); //------------------------------------------------ // OnAttach //------------------------------------------------ trigger OnAttach() { // Mark us as locked. if ( !hasObjVar( self, "slicing.locked") ) setObjVar( self, "slicing.locked", 1 ); if ( !hasObjVar( self, "slicing.slicable" ) ) setObjVar( self, "slicing.slicable", 1 ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnObjectMenuRequest //------------------------------------------------ trigger OnObjectMenuRequest( obj_id player, menu_info mi ) { if ( hasSkill( player, "class_smuggler_phase1_novice" ) && hasObjVar( self, "slicing.locked" ) ) { if ( !hasObjVar( self, "loot_crate" ) ) { // If we aren't a loot crate check to see if we are in the player's inventory. obj_id pInv = utils.getInventoryContainer( player ); if ( !isIdValid(pInv) ) return SCRIPT_CONTINUE; if ( !contains( pInv, self ) ) return SCRIPT_CONTINUE; } mi.addRootMenu( menu_info_types.SERVER_MENU1, SID_SLICE ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // OnObjectMenuSelect //------------------------------------------------ trigger OnObjectMenuSelect( obj_id player, int item ) { // Item was used. if ( item == menu_info_types.SERVER_MENU1 ) { if ( !hasObjVar( self, "loot_crate" ) ) { // If we aren't a loot crate check to see if we are in the player's inventory. obj_id pInv = utils.getInventoryContainer( player ); if ( !isIdValid(pInv) ) return SCRIPT_CONTINUE; if ( !contains( pInv, self ) ) return SCRIPT_CONTINUE; } // You can only slice this if you have the correct skill. if ( !hasSkill( player, "class_smuggler_phase1_novice" ) || !hasObjVar( self, "slicing.locked" ) ) return SCRIPT_CONTINUE; if ( !hasObjVar( self, "slicing.slicable" ) ) { sendSystemMessage( player, SID_BROKEN ); return SCRIPT_CONTINUE; } // Begin the slicing game. slicing.startSlicing( player, self, "finishSlicing", "container" ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // OnAboutToOpenContainer //------------------------------------------------ trigger OnAboutToOpenContainer( obj_id opener ) { // If we are locked we can't open. if ( hasObjVar( self, "slicing.locked" ) ) { sendSystemMessage( opener, SID_LOCKED ); return SCRIPT_OVERRIDE; } return SCRIPT_CONTINUE; } //------------------------------------------------ // finishSlicing //------------------------------------------------ messageHandler finishSlicing() { if ( params == null ) return SCRIPT_CONTINUE; int success = params.getInt( "success" ); obj_id player = params.getObjId( "player" ); if ( success == 1 ) { // Unlock the chest. removeObjVar( self, "slicing.locked" ); // Notify the hacker. sendSystemMessage( player, SID_SUCCESS ); // Grant xp. // xp.grant( player, xp.SLICING, 250 ); // Secondary message. messageTo( self, "handleSlicingSuccess", null, 0.f, true ); } else { // Remove slicability. removeObjVar( self, "slicing.slicable" ); // Notify the hacker. sendSystemMessage( player, SID_FAIL ); } return SCRIPT_CONTINUE; }