Author Topic: I need a way to define 'buildings' and do things to people not in them.  (Read 500 times)

Yeah, basically that.
CityRPG lots are the kind of zone definition I'm thinking of.

Do they specifically have to be inside the building? Or is it just on a baseplate property estate

The best thing I can think of is to throw a box search straight down to see if they're over a baseplate that designates a building, something like this:
Code: [Select]
function player::isInBuilding(%this)
{
initContainerBoxSearch(vectorSub(%this.getHackPosition(),"0 0 50"), "0.5 0.5 100", $TypeMasks::fxBrickObjectType);
while(isObject(%i = containerSearchNext()))
if(%i.getDatablock().getName() $= "BuildingMarkerData")
return 1;
return 0;
}

Oh and it needs to be efficient and stuff
Cause I'll be looping through all buildings on a regular basis

Oh and it needs to be efficient and stuff
Cause I'll be looping through all buildings on a regular basis
I thought of a much better way, then. Use triggers, like so:
Code: [Select]
function BuildingBaseplateData::onPlant(%this)
{
%db = %this.getDatablock();
%x = %db.sizeX/2;
%y = %db.sizeY/2;
%scalevector = vectorAdd(%x SPC %y, "0 0 50");
%this.trigger = new Trigger() {
position = vectorAdd(%this.getPosition(), "0 0 25");
scale = %scalevector;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
datablock = BuildingBaseplateTrigger;
};
}

function BuildingBaseplateTrigger::onEnterTrigger(%db, %this, %obj)
{
if(%obj.getType() !$= "Player")
return;
%obj.isInBuilding = 1;
}

function BuildingBaseplateTrigger::onLeaveTrigger(%db, %this, %obj)
{
if(%obj.getType() !$= "Player")
return;
%obj.isInBuilding = 0;
}

datablock TriggerData(BuildingBaseplateTrigger) { tickPeriodMS = 500; };

function player::isInBuilding(%this)
{
return %this.isInBuilding || 0;
}
« Last Edit: November 27, 2012, 08:04:00 PM by Trinick. »

Then just loop through everybody?

Okay, that'll work

Thanks!

Just make sure the baseplates are square. I didn't add any kind of rotation.

Oh, and I revised my code. I absentmindedly made the trigger the size of the brick instead of having it above the brick.
« Last Edit: November 27, 2012, 08:04:17 PM by Trinick. »

You might get problems when walking between adjacent triggers if the one you're going into registers you've entered it before the one you're leaving registers you've left. You'll definitely run into complications if the triggers overlap. Change the isInBuilding setting when a player enters or leaves to an increment or decrement respectively.