Ludeon Forums

RimWorld => Mods => Help => Topic started by: tytytyty74 on December 29, 2016, 02:08:52 PM

Title: how to check if an object exists
Post by: tytytyty74 on December 29, 2016, 02:08:52 PM
I am trying to make a mod for surgery automation, but i need to know how to check if there is a medical bed in front of the object.
Title: Re: how to check if an object exists
Post by: Grim on December 29, 2016, 03:38:08 PM
Hello,

I know you can get a list of all a colonists buildings with Find.VisibleMap.listerBuildings.allBuildingsColonist then it should just be a case of comparing the location of your object to the location of the medical bed using .position on the building objects.

Something like (Pseudo code)



List<Building> colonistBuildings;

colonistBuildings = Find.VisibleMap.listerBuildings.allBuildingsColonist;

colonistMedicalBeds = colonistBuildings.Find(x => x.LabelCap == "Medical Bed")

foreach(var medbed in colonistMedicalBeds)
{
    // yourObjects position + 1 unit to right should check if any of the medical beds are to the right of your object
     var myObjectPositionwithOffset = new Vector2(myObject.position.x + 1, myObject.position.y);

     if(medbed.position == myObjectPositionwithOffset)
    {
        //do stuff
     }
}



I'm not sure if this will work as I haven't tested it but this is how I would go about it.
Title: Re: how to check if an object exists
Post by: tytytyty74 on December 29, 2016, 08:11:16 PM
how do I set a position vector, I don't know where the person is placing it, I'm getting how to place the object with https://github.com/HaploX1/ExampleDllMod (https://github.com/HaploX1/ExampleDllMod) as a reference, also, new vector2 doesn't work, and colonistbuildings.find doesn't return an array