[API request] Alter materials and find jobs from script

Discussion about Mods for Prison Architect

Moderator: NBJeff

User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

[API request] Alter materials and find jobs from script

Postby Brento666 » Sat Sep 12, 2015 6:39 pm

Hi Introversion/reader,

I'm stuck on a few things for my mod, I'm currently missing API functionality for switching materials and for my custom entities to find/do (custom) Jobs.

-I've increased the time it takes to normally dismantle brick/cement/perimeter walls and tunnels. Next I created explosive charges for optional fast (but potentially dangerous) demolition... Allas atm my script behind the charges can only damage (or kill) prisoners, staff and nearby objects. The entities in the blastzone also get accelerated away, and I spawn some debris all of which looks quite cool.

BUT the idea behind the charges is to demolish walls and (exposed) tunnels; and that is what I cannot achieve in script with the current API.

Code: Select all

--exert from my Detonate() function:
function Detonate()
    local objectTypes = { "BrickWall", "ConcreteWall", "BuildingConcrete", "BuildingFrame", "PerimeterWall", "Fence" }
    --local objectTypes = { "Wall" }
    for i,objectType in ipairs( objectTypes ) do
        FindObjectsToDestroy(objectType, 5.0, 1.0)
    end
end

function FindObjectsToDestroy(typeName, distance, damage)
    local objects = Object.GetNearbyObjects(typeName, distance) --doesn't return any wall/tunnel(!)
    for obj, dist in pairs(objects) do
        --obj.Damage=1;
        obj.Delete(); --these lines are never reached
    end
end


I've tried other ways of getting rid of walls, tried to see if the existing function GetMaterial(x,y) has a Settable counterpart;
But Object.SetMaterial(x, y, "ConcreteFloor") doesn't exist.

Tried to spawn stuff at this (wall/charge) position;
Object.Spawn( "Rubble", this.Pos.x, this.Pos.y ); doesn't effect wall
Object.Spawn( "BurntFloor", this.Pos.x, this.Pos.y ); doesn't do anything

I've even tried temporarily (and during testing permanently) moving nearby doors to the position of a wall to see if that would get the walls to go away;

Code: Select all

local objects = Object.GetNearbyObjects("JailDoor", 10)
for obj, dist in pairs(objects) do
   local doorX, doorY = obj.Pos.x, obj.Pos.y;
   obj.Pos.x, obj.Pos.y = this.Pos.x, this.Pos.y;
   obj.Pos.x, obj.Pos.y = doorX, doorY;
   return
end

Sadly this makes a door move to a nearby empty space (for an instant and then back to where it was).

-> So I'm stuck on destroying walls/tunnels; I would need GetNearbyObjects or a newly created function to return wall/tunnel objects... or to have a SetMaterial function or perhaps to be able to just spawn materials to positions.
(The alpha 36 random events do manage to randomly cause portions of wall to crumble, but the way it accomplishes that seems obfuscated to me. So perhaps there is already a way and I am just lacking information on this.)



-Next I have a similar problem with script behind my custom surgeon and psychiatrist entities; If I spawn (create) any job, custom or not, currently only workmen, janitors, doctors and prisoners will try fulfill it. I cannot for instance get the foreman to do a custom construction job (place explosive charge). Nor does the warden respond to any jobs with "Worker Warden" detailed.
And as you might know custom entities are completely inert without script... I have seen others make new staff members "wander" around the place, but have yet to see anyone make a custom entity do a single job.

-> For my mod to function as intended, I need to be able to get nearby jobs from script... GetNearbyObjects will not return any Jobs. I'd like it very much if GetNearbyObjects or a newly created function would return (my custom) jobs...
From there I would need even more; I could have the entity navigate to a job, but currently don't know of a way get an entity to start doing that job. (I have not tried forcing an entity's id's into slots and setting an objects inUse flag, as I can't navigate to a specific slot with any degree of precision atm.)

Thanks for reading my API requests, if you are introversion and/or can help me in any way; I would be even more thankfull!!
Trixi
level2
level2
Posts: 245
Joined: Wed Mar 04, 2015 9:22 am
Location: Ulm, Germany
Contact:

Re: [API request] Alter materials and find jobs from script

Postby Trixi » Sat Sep 12, 2015 7:06 pm

Trying to set integer for your setting variables. i had similar issues with changing my stacked log to stacked log2:

thats my code i set the log stack to log2:


Code: Select all

    while i < 10000 do
      Object.SetProperty( "Contents", i); -- why the f*** setProperty for Contents is a number
      if this.Contents == "Log2" then
        return;
      end
      i = i + 1;
    end


i know very ineffective, but working
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Sat Sep 12, 2015 7:30 pm

Tnx Trixi, do you mean to suggest Contents could maybe hold walls and/or tunnel values? I haven't played around with Object.Contents but will give it a go to see what it can hold! Much appreciated!
Trixi
level2
level2
Posts: 245
Joined: Wed Mar 04, 2015 9:22 am
Location: Ulm, Germany
Contact:

Re: [API request] Alter materials and find jobs from script

Postby Trixi » Sun Sep 13, 2015 1:21 am

No i mean that

Code: Select all

Object.SetMaterial(x, y, "ConcreteFloor")


Could work with

Code: Select all

Floor = 3; -- try to look up the number
Object.SetMaterial(x, y, Floor)


or sth like that. For vanilla content the integer number should be stay the same, but for modding content you have real problems, as you dont know which integervalue for the settingmethod is used for your own materials ....
User avatar
aubergine18
level2
level2
Posts: 231
Joined: Sun Jul 05, 2015 3:24 pm

Re: [API request] Alter materials and find jobs from script

Postby aubergine18 » Sun Sep 13, 2015 1:30 pm

It's weird how some properties use one data type for getter and a different data type for setter. In the case of Object.Contents for a stack, which I've not experimented with myself, I worry that any changes to the materials.txt could alter the numeric indexes.

Also, I've never seen the SetMaterial() function in the Object library - does that even work?

As for deleting walls, rather than move a door why not spawn a new door then delete it? Spawning the door is what causes the wall tile to be removed.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Sun Sep 13, 2015 5:55 pm

Hi aubergine18,
Maybe my wording was a bit off; I never meant to imply there was currently a SetMaterials function available.
I only tried it because documentation on api changes aren't centralized or complete atm! And I thought if GetMaterials exists, I'd try to see if there's a Setter-equivalent...And there isn't.
->I also mentioned the (fictitious) SetMaterials function because I'm missing a clean neat way for altering materials in the current api-functionality. (So maybe introversion could/would implement it or something else)

Thanks for the tip; I'll give spawning doors (and removing them instantly) a go!
Trixi
level2
level2
Posts: 245
Joined: Wed Mar 04, 2015 9:22 am
Location: Ulm, Germany
Contact:

Re: [API request] Alter materials and find jobs from script

Postby Trixi » Sun Sep 13, 2015 6:16 pm

Hello Aubergine

You do you have any faster solution than this code snipped i postet above. This feels quite mad as it just work as try and error.

Well i could simply spawn 3 logs. But this will produce new stack jobs for workers.

Or i could use another object but then i have to search for it.....

It hurts instead setting a simple value to loop all possible values until i met the value i want.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Mon Sep 14, 2015 4:54 pm

Hi Yall, here's an update on my efforts.

Aubergine18: Spawning a door to rid of walls: door spawns next to wall or over wall, but doesn't cause walls to go away. (I think I tried this before trying to use existing doors, anyway, tried it again with no luck.)
->Next I'm gonna try spawning fires at wall location until GetMaterial shows wall is gone, then delete fires. I'm hopefull with enough fire the walls will break (almost) instantly.

Trixi: If you're spawning logs from the same scripted object multiple times; Iterate the values once to find the Log2 value, then keep the Log2 value for use in future iterations.

Code: Select all

local Log2 = -1

function SetLog2(obj)
    if Log2 > -1 then
       obj.SetProperty( "Contents", Log2);
    else
      while i < 10000 do
        obj.SetProperty( "Contents", i);
        if obj.Contents == "Log2" then
          Log2 = i;
          return;
        end
        i = i + 1;
    end
  end
end
Trixi
level2
level2
Posts: 245
Joined: Wed Mar 04, 2015 9:22 am
Location: Ulm, Germany
Contact:

Re: [API request] Alter materials and find jobs from script

Postby Trixi » Mon Sep 14, 2015 5:16 pm

Brento666 wrote:Hi Yall, here's an update on my efforts.

Aubergine18: Spawning a door to rid of walls: door spawns next to wall or over wall, but doesn't cause walls to go away. (I think I tried this before trying to use existing doors, anyway, tried it again with no luck.)
->Next I'm gonna try spawning fires at wall location until GetMaterial shows wall is gone, then delete fires. I'm hopefull with enough fire the walls will break (almost) instantly.


spawning anything with a luaskript doesnt check anything whats on the field. So you can spawn 1.000.000 objects at the same field, including walls, doors, normal objects and Utilitys


Trixi: If you're spawning logs from the same scripted object multiple times; Iterate the values once to find the Log2 value, then keep the Log2 value for use in future iterations.

Code: Select all

local Log2 = -1

function SetLog2(obj)
    if Log2 > -1 then
       obj.SetProperty( "Contents", Log2);
    else
      while i < 10000 do
        obj.SetProperty( "Contents", i);
        if obj.Contents == "Log2" then
          Log2 = i;
          return;
        end
        i = i + 1;
    end
  end
end


Well, im starting the Routine from the Stack itself that i want to Change, or even not. Luckily this Routine is only called on activating the mod, or want to Change the behaviour back to orignal game with the logs. My log2 does the same as the log, except that it wont be exportet.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Wed Sep 16, 2015 12:44 am

spawning anything with a luaskript doesnt check anything whats on the field. So you can spawn 1.000.000 objects at the same field, including walls, doors, normal objects and Utilitys

This seems the case yes. I'm hopeful we'll see a future update with the option to set materials, but atm there's still allot of things that need to be made accessible to the scripts and I don't know if this is even on the list...

-I have had partial success with destroying walls with spawned fire; I get a 25/75 result of complete removal / unwanted burntwall. Sadly burntwall seems immune to more fire :(
I haven't tried tunnels yet, but seeing as walls are currently out of scope I think I'll focus on another part of my mod for now. So explosive-demolition-charges are on-hold for more of the api to be exposed !!
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Wed Sep 16, 2015 11:21 pm

As for the custom entities doing jobs I still haven't found a suitable solution, but I have to adjust what I said earlier;
... custom entities are completely inert without script... I have seen others make new staff members "wander" around the place, but have yet to see anyone make a custom entity do a single job.

This isn't always true; I Just tagged my (still unscripted) psychiatrist with an extra prop "Administrator" in my materials.txt

Code: Select all

Properties           Entity
Properties           Administrator 
Properties           Staff

It now has an office requirement AND will come to life without script... He behaves like any normal administrator and walks straight to his new office and wanders around, seeks a doctor if hurt, does reform programs, BUT sadly still will not do jobs...

An update on my surgeon entities; they are not Administrators, so they don't require an office. Not being an administrator though, they do need script to do anything. I have updated my script for them to wander in vicinity of my new clinical beds (and not all over the place) and to seek a regular doctor if hurt ;D
-Still need proper ways for Admins and scripted entities to do jobs!
Trixi
level2
level2
Posts: 245
Joined: Wed Mar 04, 2015 9:22 am
Location: Ulm, Germany
Contact:

Re: [API request] Alter materials and find jobs from script

Postby Trixi » Wed Sep 16, 2015 11:31 pm

stop, they dont Need a script to do anything.

it would be enough if you make them Jobs in the production.txt in combination with the materials.txt.

Okay rest of the time they are just Standing around.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Thu Sep 17, 2015 12:22 am

Trixi wrote:stop, they dont Need a script to do anything.
it would be enough if you make them Jobs in the production.txt in combination with the materials.txt.
Okay rest of the time they are just Standing around.

SO wait, I need a simple production rule to get my custom entities to for instance a 'Loaded' clinical bed?! Sweet, need to test that asap! Thanks!
-edt: Non administrator entities don't wander and don't seek medical help atm. Hoping to see them respond to production rules.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: [API request] Alter materials and find jobs from script

Postby Brento666 » Tue Sep 22, 2015 10:50 pm

Brento666 wrote:...Hoping to see them respond to production rules.

Sadly no for production rules doing anything. BUT good news, I persisted and have just made my first semi functional worker with full lua "state-machine" type setup!

A set of 4 different surgeons who do a variety of procedures on prisoners needing "Surgery", they can even "Resuscitate" convicts and staff :D When tired I make them rest in a staffroom by looking for the closest drinkmachine (and detect when they arrives). When they're hurt I make 'm go for a regular doctor (and detect if/when healed) :)
When idle or resting I scan the rooms edges (once) and make him wander inside it! Only when K.O.ed or dead do they go passive!!
->A surgeon will still not respond to jobs/production rules, but it responds to patients on surgery tables (the table is scripted as a sensor/director for procedures and outcome).

And it is already freaking awesome to play with!! A little into the procedure I change the surgerytable to a bloodstained sprite variant and spawn blood spatters around. Afterwards I get the Janitor to mop the floor whenever. And (for now) a doctor comes by to clean the sheets, they need cleaning before the table is ready for the next patient!! For now I have 8 different procedures working with different durations, risks, targeted body parts and outcomes...
-next up: More props, gore, surgeon animation/activity while operating and scripted nurses to partially aid surgery (sedation/aftercare/clean sheets)! Tying the needs together via a scripted Warden; on a schedule some (new) prisoners will get an unexplained "Health" need. When getting a checkup there's a chance the cause is found. The health need will either need to be maintained with an adjoining "Medication" need or the health problem may be surgically cured... These needs will not auto-change, the warden script will manage them.


Also good news on the topic of my explosive demolition charges; I can now demolish multiple adjoining walls with a single charge! It kills walls with allot of script controlled pinpoint fires and has great visuals for free thanks to awesome vanilla fire bloom effect! It has countdown bleep sounds, detonation sounds, nicely timed. The fireblast does last for a couple of ingame minutes, but that's acceptable for now!

The charges reek havoc as they also damage and propel (literally) ALL sorts of entities and objects!! It is also a great tool to help test my Surgeon's reanimation skills!
-next for this: enable logical connections and timed triggering for multiple charges by single trigger-device. Use the current script for future dynamite sticks for small blast jobs. Also thinking of a reform program where convicts get to pickaxe at stone blocks; coming from a large quarry where workmen set off dynamite (when inmates aren't around). Exporting...? Diamonds? Gold? Dunno Yet!

Releasing the mod is not top priority atm... but given the amount of experience I now have I should'nt run into the same pitfalls/bugs/crashes I hope :roll:
User avatar
aubergine18
level2
level2
Posts: 231
Joined: Sun Jul 05, 2015 3:24 pm

Re: [API request] Alter materials and find jobs from script

Postby aubergine18 » Wed Sep 30, 2015 10:04 pm

Sounds interesting Brento666 - is the mod released yet?

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 8 guests