Files
dsrc/sku.0/sys.server/compiled/game/script/structure/house_container_lock.script
T

94 lines
2.6 KiB
Plaintext

include library.utils;
const string_id SID_LOCK_BAD_STRUCTURE = new string_id("spam", "sid_lock_bad_structure");
const string_id SID_LOCK_BAD_LOCK_TARGET = new string_id("spam", "sid_lock_bad_lock_target");
const string_id SID_LOCK_BAD_ALREADY_LOCKED = new string_id("spam", "sid_lock_bad_already_locked");
const string_id SID_LOCK_BAD_INVENTORY_LOCATION = new string_id("spam", "sid_lock_bad_inventory_location");
const string_id SID_LOCK_BAD_LOCK_CONTAINER = new string_id("spam", "sid_lock_bad_lock_container");
const string_id SID_LOCK_APPLIED = new string_id("spam", "sid_lock_applied");
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if(!isIdValid(player))
{
return SCRIPT_CONTINUE;
}
// debugSpeakMsg(player, "OnObjectMenuSelect start");
obj_id structure = getTopMostContainer(self);
obj_id containedBy = utils.getContainingPlayer(self);
if(!isIdValid(containedBy) || containedBy != player)
{
return SCRIPT_CONTINUE;
}
if(!isIdValid(structure) || !exists(structure) || structure == player || getOwner(structure) != player)
{
sendSystemMessage(player, SID_LOCK_BAD_STRUCTURE);
return SCRIPT_CONTINUE;
}
// debugSpeakMsg(player, "OnObjectMenuSelect valid " + structure);
if(item == menu_info_types.ITEM_USE)
{
obj_id target = getIntendedTarget(player);
if(!isIdValid(target))
{
sendSystemMessage(player, SID_LOCK_BAD_LOCK_TARGET);
return SCRIPT_CONTINUE;
}
// If the container is already locked, don't do anything.
if(hasScript(target, "structure.locked_container"))
{
sendSystemMessage(player, SID_LOCK_BAD_ALREADY_LOCKED);
return SCRIPT_CONTINUE;
}
// If the target is not a container, this lock should not be applied to it.
if(!isGameObjectTypeOf(target, GOT_misc_container) && !isGameObjectTypeOf(target, GOT_misc_container_wearable))
{
sendSystemMessage(player, SID_LOCK_BAD_LOCK_TARGET);
return SCRIPT_CONTINUE;
}
// If the target is not yours, then it shouldn't be lockable by you.
if(getOwner(target) != player)
{
sendSystemMessage(player, SID_LOCK_BAD_LOCK_TARGET);
return SCRIPT_CONTINUE;
}
setObjVar(target, "lock_owner", player);
setObjVar(target, "lock_owner_name", getName(player));
clearUserAccessList(target);
clearGuildAccessList(target);
addUserToAccessList(target, player);
attachScript(target, "structure.locked_container");
sendSystemMessage(player, SID_LOCK_APPLIED);
messageTo(self, "destroySelf", null, 1, true);
}
return SCRIPT_CONTINUE;
}
messageHandler destroySelf()
{
destroyObject(self);
return SCRIPT_CONTINUE;
}