I need some help making a C# code for restricting a item against a wall? How do i do this?
using System;
using Verse;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef checkingDef, IntVec3 loc, IntRot rot)
{
WHAT SHOULD I WRITE HERE!!!
}
{
I don't know much about C# programming, much less with RimWorld's, but perhaps you can check for a Wall tile adjacent to the location?
I'd find the closest walls to the location you are trying to place the object, and see if any of them are in the squares right next to where the object is being placed.
How do I do that? I'm kiiiind a new to C# coding.
Try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in loc.AdjacentSquares8Way())
{
foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
{
if (current2.def.linkFlags == LinkFlags.WallBrick)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.WallLog)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMetal)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMud)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.WallStone)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.WallWood)
{
return "Can not be placed next to a wall";
}
else if (current2.def.linkFlags == LinkFlags.Rock)
{
return "Can not be placed next to a wall";
}
else
{
return true;
}
}
}
return "Can not be placed next to a wall";
}
}
If this does not work, I will get right on to making one that works, I just made this quickly hoping it would work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in loc.AdjacentSquares8Way())
{
foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
{
if (current2.def.linkFlags == LinkFlags.WallBrick)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallLog)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMetal)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallMud)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallStone)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.WallWood)
{
return "Can only be placed next to a powered wall";
}
else if (current2.def.linkFlags == LinkFlags.Rock)
{
return "Can only be placed next to a powered wall";
}
else
{
return true;
}
}
}
return "Can only be placed next to a powered wall";
}
}
It almost worked
It calculated all kind of objects 1 tile away so filth and rocks was also calculated.
But to clarify i want it to only be able to be located next to a powered wall. :)
Oh you want it so it can only be placed next to powered walls? Right I get it now. Will get on it in a second.
Right here you go! This should will work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in loc.AdjacentSquares8Way())
{
foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
{
if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallMetal)
{
return true;
}
else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallWood)
{
return true;
}
else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallStone)
{
return true;
}
else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallWood)
{
return true;
}
else if (current2.def.transmitsPower == true && current2.def.linkFlags == LinkFlags.WallBrick)
{
return true;
}
}
}
return "Must be placed next to wall that transmits power";
}
}
This is also makes it compatible with Industrial RIM v1.2.0 as it has Wood and Stone walls that transmit power.
(Also compatible with other mods that use the linkflags of course ;))
Did not work :3
Even when it have power.
It should tho be able to be placed even tho the wall do not have power at the moment. :P
Wow, I'm worse than I thought. Give me a second Grrrr.
Quote from: Cala13er on June 04, 2014, 08:21:10 AM
Wow, I'm worse than I thought. Give me a second Grrrr.
hehe
FINALLY GOT IT!!! GAWDERR.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using Verse.Sound;
public class PlacementRestricter_NextToWall : PlacementRestricter
{
public override AcceptanceReport CanPlaceWithRestriction(EntityDef Building, IntVec3 loc, IntRot rot)
{
foreach (IntVec3 current in loc.AdjacentSquares8Way())
{
foreach (Thing current2 in Find.ThingGrid.ThingsAt(current))
{
if (current2.def.transmitsPower == true)
{
if (current2.def.eType == EntityType.Wall)
{
return true;
}
}
}
}
return "Must be placed next to wall that transmits power";
}
}
This DOES work.
At least I know why It wasn't working!
Now it works! Awesome!
One thing how do i make it so so Xamarin don't build all the assembly dll files?
Quote from: Evul on June 04, 2014, 08:41:30 AM
Now it works! Awesome!
One thing how do i make it so so Xamarin don't build all the assembly dll files?
I don't use Xamarin.
Quote from: Cala13er on June 04, 2014, 08:45:21 AM
Quote from: Evul on June 04, 2014, 08:41:30 AM
Now it works! Awesome!
One thing how do i make it so so Xamarin don't build all the assembly dll files?
I don't use Xamarin.
Damit ^^