REO-EE/_module/nss/rhs_furn_tool.nss
Jaysyn904 f82740bbbd Initial commit
Initial commit
2024-02-22 13:22:03 -05:00

100 lines
3.8 KiB
Plaintext

#include "rhs_include"
#include "nwnx_events"
#include "x2_inc_switches"
#include "zzdlg_main_inc"
void main()
{
object oPC;
object oTarget;
object oArea;
location lTargetLocation;
// Linux
if(RHS_USING_LINUX)
{
oPC = OBJECT_SELF;
oArea = GetArea(oPC);
oTarget = GetEventTarget();
vector vPosition = GetEventPosition();
lTargetLocation = Location(oArea, vPosition, 0.0);
}
// Windows
else
{
if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
oPC = GetItemActivator();
oArea = GetArea(oPC);
oTarget = GetItemActivatedTarget();
lTargetLocation = GetItemActivatedTargetLocation();
}
object oDatabase = GetItemPossessedBy(oPC, PC_DATABASE);
int iAreaPCID = GetLocalInt(oArea, RHS_HOUSE_OWNER_ID_NUMBER);
int iPCID = GetLocalInt(oDatabase, PC_ID_NUMBER);
// Check if oPC is trying to move furniture
int bMovingFurniture = GetLocalInt(oPC, RHS_FURNITURE_MOVING_OBJECT);
if(bMovingFurniture)
{
object oFurnitureBeingMoved = GetLocalObject(oPC, RHS_FURNITURE_MOVING_OBJECT_REFERENCE);
object oFurnitureArea = GetArea(oFurnitureBeingMoved);
// Invalid object or the wrong area - remove temporary variables and inform user
if(!GetIsObjectValid(oFurnitureBeingMoved) || oFurnitureArea != GetAreaFromLocation(lTargetLocation))
{
FloatingTextStringOnCreature(ColorTokenRed() + "Error! Cannot move that object to that location." + ColorTokenEnd(), oPC, FALSE);
DeleteLocalInt(oPC, RHS_FURNITURE_MOVING_OBJECT);
DeleteLocalObject(oPC, RHS_FURNITURE_MOVING_OBJECT_REFERENCE);
return;
}
// Otherwise, move the object to the new location and update the database
else
{
string sResref = GetResRef(oFurnitureBeingMoved);
float fFacing = GetFacing(oFurnitureBeingMoved);
RHS_RemoveFurniture(OBJECT_INVALID, oFurnitureBeingMoved, iAreaPCID);
RHS_ClearInventory(oFurnitureBeingMoved);
DestroyObject(oFurnitureBeingMoved);
oFurnitureBeingMoved = CreateObject(OBJECT_TYPE_PLACEABLE, sResref, lTargetLocation);
AssignCommand(oFurnitureBeingMoved, SetFacing(fFacing));
DelayCommand(0.2, RHS_AddFurniture(OBJECT_INVALID, oFurnitureBeingMoved, iAreaPCID));
}
}
// Area is either a preview or a non-house area - inform player they can't manipulate furniture
if(iAreaPCID <= 0)
{
FloatingTextStringOnCreature(ColorTokenRed() + "Furniture can only be manipulated in player-owned " + RHS_HOUSE_TERM_LOWER_PLURAL + ".", oPC, FALSE);
return;
}
// Check if oPC is a 'Trustee'. Trustees are able to manipulate furniture in other people's houses
if(iAreaPCID != iPCID)
{
string sTable = RHS_TABLE_FRIENDS + IntToString(iAreaPCID);
string sPermission = GetMySQLData(sTable, "Setting", iPCID, "ID", RHS_SCHEMA);
// Not a trustee - inform player they cannot manipulate furniture
if(sPermission != "T")
{
FloatingTextStringOnCreature(ColorTokenRed() + "You do not have sufficient permissions to perform that action." + ColorTokenEnd(), oPC, FALSE);
return;
}
}
// If the target was an object, use that object's location
if(GetIsObjectValid(oTarget))
{
lTargetLocation = GetLocation(oTarget);
}
// By this point either oPC is the owner or is a trustee. They are allowed to access the furniture management menu.
// Store necessary variables for later retrieval and execute the furniture menu
SetLocalString(oPC, RHS_FURNITURE_TOOL_TARGET_LOCATION, APSLocationToString(lTargetLocation));
_dlgStart(oPC, oDatabase, RHS_FURNITURE_MENU, 1, 1, 1);
}