include library.utils; include library.player_structure; include library.structure; inherits item.special.nomove_base trigger OnAttach() { setObjVar(self, "noTrade", true); propogateNoTrade(self, true); return SCRIPT_CONTINUE; } trigger OnLostItem(obj_id destContainer, obj_id transferer, obj_id item) { if (containsNoTradeItem(self)) return SCRIPT_CONTINUE; removeObjVar(self, "noTrade"); propogateNoTrade(self, false); detachScript(self, "item.special.nomove_container"); return SCRIPT_CONTINUE; } boolean containsNoTradeItem(obj_id container) { obj_id[] contents = getContents(container); for (int i = 0; i < contents.length; i++) { if (hasObjVar(contents[i], "noTrade")) return true; } return false; } void propogateNoTrade(obj_id container, boolean isNoTrade) { obj_id player = utils.getContainingPlayer(container); obj_id inventory = getObjectInSlot(player, utils.SLOT_INVENTORY); obj_id parent = getContainedBy(container); while (isIdValid(parent) && !getTemplateName(parent).equals(structure.TEMPLATE_CELL) && parent != inventory && !player_structure.isBuilding(parent)) { // Propogate noTrade flag up if (isNoTrade) { if (!hasObjVar(parent, "noTrade")) { attachScript(parent, "item.special.nomove_container"); return; } } // Clear noTrade flag up else { if (containsNoTradeItem(parent)) return; if (hasScript(parent, "item.special.nomove_container")) { removeObjVar(parent, "noTrade"); detachScript(parent, "item.special.nomove_container"); } else { // permanent no trade item, abort out return; } } parent = getContainedBy(parent); } }