Accessing any Object

Discussion about Mods for Prison Architect

Moderator: NBJeff

dean.fitz
level0
Posts: 5
Joined: Tue Jan 01, 2013 12:02 am

Accessing any Object

Postby dean.fitz » Wed Sep 03, 2014 6:06 am

So I have been playing around trying to get access to objects outside "this" object and the one that "this" creates. It turns out that you can, however the method to do so is very limited in its uses. Its very slow, but maybe someone can work out how to get it working quicker...

The idea is to use the fact that Object.GetProperty and Object.SetProperty default to the "this" object if the first parameter is missing. I guessed that the globals me.i and me.u are used to accomplish this. so by changing these globals to match the one used in the internal database, you can then call the property function as if you where that other object. The only way i can think of to find the combination of i and u is to brute force the search space. This is crazy slow, but like I said, maybe someone can work something else out.

Code: Select all

function Create()
    Object.SetProperty("DoLoop",true);
    print()  --get the debug screen
end


function Update( timePassed )
    if Object.GetProperty("DoLoop") then
        local id = Object.GetProperty("Id.i")   --could use id = _G["me.i"]
        local uid = Object.GetProperty("Id.u")

        Game.DebugOut("My type is " .. Object.GetProperty("Type"))
        Game.DebugOut("Starting Loop")

        for i=0,150 do      --150 the first 150 object
            _G["me.i"] = i ..""
            for u=0,2000 do --quit the game to get uid to reset to 0, u value can get very large very quickly
                _G["me.u"] = u ..""
                local t = Object.GetProperty("Type")
                if t then
                    Game.DebugOut(i.." "..u.." : "..t)
                    if(t ==  "Tree") then
                        --setting "Type" didn't work for me
                        Object.SetProperty("SubType",2)
                        Object.SetProperty( "Age", 0)
                    end
                end
            end
        end
        --back to original values
        _G["me.u"] = uid
        _G["me.i"] = id

        Object.SetProperty( "DoLoop", false);       
    end
end


Notes:
1) If you are testing this out then make sure you do it on a new map and a newish instance of PA. This should restart the uid index to 0, otherwise the search wont find the objects in the internal database.
2) you can not access the me.i (or me.u) global using the syntax me.i= xxx, this is becase lua thinks you are trying to access the table me with an index "i".

Code: Select all

me.i = XYZ
--equals
me["i"] = XYZ


see lua pil
jeremy_nz
level0
Posts: 7
Joined: Tue Jun 17, 2014 6:53 pm

Re: Accessing any Object

Postby jeremy_nz » Wed Sep 03, 2014 6:59 am

Im not sure if this is crazy or genius, but thanks for posting.
Could you share some examples of what you've been able to do?
dean.fitz
level0
Posts: 5
Joined: Tue Jan 01, 2013 12:02 am

Re: Accessing any Object

Postby dean.fitz » Wed Sep 03, 2014 8:08 am

Well is more a proof of concept at the moment. I'm cant think of anything to useful to do with it. I was hoping to be able to get access to prisoners and make changes, but most of the interesting stuff is in tables in the prisoner instance and i don't know a way to access that. Also, unless it can be done quicker, there is little modding use.

Anyways, I just thought I would share just in case someone does find a use.

P.S.

Here are a few thoughts that I just come up with on the spot...

You could use it to breed animals, have male and females in a pen, every 1000s (or whatever) males check to see is a female is near, by finding them all and checking their pos vs your pos. Then if near, set a prop to preg. The female on their update will start to grow offspring once they have the preg prop set.

You could have a chemical mist sprayer that give a spray every so often, prisoner in range would get suppressed a bit by the chemicals

But, again, unless its quicker, then it will just bog the game down...
User avatar
Phraxas
level2
level2
Posts: 107
Joined: Sun Aug 31, 2014 12:10 am
Location: USA - PA

Re: Accessing any Object

Postby Phraxas » Wed Sep 03, 2014 5:32 pm

Interesting idea.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 13 guests