[C#] How do i restrict a item inside?

Started by Evul, June 03, 2014, 08:18:13 PM

Previous topic - Next topic

Evul

I want to make something to not be able to be placed outside
How do i write it?

I used the code for outdoor item only how do i make it to if NOT roofed then?

using System;
using Verse;
public class PlacementRestricter_UnderRoof : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
{
if (Find.RoofGrid.Roofed(loc))
{
return new AcceptanceReport("Cannot be placed outside.");
}
return true;
}
}

Evul

I solved it....


using System;
using Verse;
public class PlacementRestricter_UnderRoof : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
{
if (!Find.RoofGrid.Roofed(loc))
{
return new AcceptanceReport("Cannot be placed outside.");
}
return true;
}
}

StorymasterQ

Just a thought, have you thought of what would happen if the roof above the thing is removed via Remove Roof zone? Maybe a "Cannot remove roof"?
I like how this game can result in quotes that would be quite unnerving when said in public, out of context. - Myself

The dubious quotes list is now public. See it here

Evul

Now you adding problems I did not think of :P
I whant it to be destroyed.

Celthric Aysen

My DeviantART|E-Vehicles|Flebe's  Channel
"♫"Every people that i see i will never understand"♪"

Evul

I just whant it to set the health to 0 if the roof is gone.

Cala13er

Quote from: Evul on June 04, 2014, 06:45:09 AM
I just whant it to set the health to 0 if the roof is gone.

How big is the item that you want gone if the roof is destroyed?

Evul

Quote from: Cala13er on June 04, 2014, 07:27:23 AM
Quote from: Evul on June 04, 2014, 06:45:09 AM
I just whant it to set the health to 0 if the roof is gone.

1.1 its a lamp that hangs in the celing
How big is the item that you want gone if the roof is destroyed?

Cala13er

Quote from: Evul on June 04, 2014, 07:35:06 AM
Quote from: Cala13er on June 04, 2014, 07:27:23 AM
Quote from: Evul on June 04, 2014, 06:45:09 AM
I just whant it to set the health to 0 if the roof is gone.
How big is the item that you want gone if the roof is destroyed?
1.1 its a lamp that hangs in the celing

Ahh that's easier then. So you want it to destroy itself on roof removal? I'll get right on it. Have you already got a Building_CeilingLamp or something like that?

Evul

Yes i whant to destroy the lamp when the roof goes away :)

Buildings_Furniture_CeilingLamp.xml
<?xml version="1.0" encoding="utf-8" ?>
<Buildings>

<ThingDef Name="BuildingBase" Abstract="True">
<category>Building</category>
<soundBulletHit>BulletImpactMetal</soundBulletHit>
<selectable>true</selectable>
<drawerType>MapMeshAndRealTime</drawerType>
<surfaceNeeded>Light</surfaceNeeded>
<constructionEffect>ConstructMetal</constructionEffect>
<repairEffect>Repair</repairEffect>
</ThingDef>

<ThingDef ParentName="BuildingBase">
<defName>CeilingLamp</defName>
<eType>BuildingComplex</eType>
<label>Ceiling lamp</label>
<thingClass>Building</thingClass>
<category>Building</category>
<texturePath>Things/Building/CeilingLamp</texturePath>
<altitudeLayer>FlyingItem</altitudeLayer>
<passability>Standable</passability>
<maxHealth>30</maxHealth>
<flammability>1.0</flammability>
<selectable>true</selectable>
<description>Ceiling lamp that lights an area.</description>
<size>(1,1)</size>
<workToBuild>40</workToBuild>
<costList>
<li>
<thingDef>Metal</thingDef>
<count>5</count>
</li>
</costList>
<soundBulletHit>BulletImpactMetal</soundBulletHit>
<leaveResourcesWhenKilled>false</leaveResourcesWhenKilled>
<comps>
<li>
<compClass>CompPowerTrader</compClass>
<basePowerConsumption>125</basePowerConsumption>
<soundPowerOn>PowerOnSmall</soundPowerOn>
<soundPowerOff>PowerOffSmall</soundPowerOff>
</li>
<li>
<compClass>CompGlower</compClass>
<glowRadius>10</glowRadius>
<glowColor>(217,217,208,0)</glowColor>
</li>
</comps>
<designationCategory>Furniture</designationCategory>
<placementRestricters>
<li>PlacementRestricter_UnderRoof</li>
</placementRestricters>
  </ThingDef>
 
</Buildings>