Page 1 of 1
Build and install an object with lua scripting
Posted: Wed Sep 07, 2016 11:54 am
by neoxes
Hi all!
I'm working on a mod and I'm wondering if there's a way to simulate the build and installation of an object with lua scripting. Thanks for replying!
Re: Build and install an object with lua scripting
Posted: Wed Sep 07, 2016 6:16 pm
by murgh
Why not, just spawn the stuff.
Re: Build and install an object with lua scripting
Posted: Wed Sep 07, 2016 6:45 pm
by neoxes
murgh wrote:Why not, just spawn the stuff.
I know that function, but I don't want to spawn the object, I'd like to build and install it. This way, the workers get materials from the storage.
This is my objective:
- I want to "paint" objects (changing their sprite) like Brento mod, but I'd like to do it via interface, without building a paint tool.
So:
- Install a paintable object (scripting it and adding "Paintable" property)
- User can choose a color via interface (this code is really simple)
- If user changes the color, paint material is ordered and delivered to storage
- Workers go to the storage and bring paint to the object
- Workers paint the object
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 3:10 am
by dsdude123
neoxes wrote:murgh wrote:Why not, just spawn the stuff.
I know that function, but I don't want to spawn the object, I'd like to build and install it. This way, the workers get materials from the storage.
This is my objective:
- I want to "paint" objects (changing their sprite) like Brento mod, but I'd like to do it via interface, without building a paint tool.
So:
- Install a paintable object (scripting it and adding "Paintable" property)
- User can choose a color via interface (this code is really simple)
- If user changes the color, paint material is ordered and delivered to storage
- Workers go to the storage and bring paint to the object
- Workers paint the object
This is possible. This can be done by making a job when the color is changed. Here is an example of changing the color of a door to red.
When a color is selected (in this case red) you could have your Lua script call the following function:
Code: Select all
function ChangeColor(string color)
if color = "red" then
this.PaintColor = 1 --better to store the color in a numerical value rather than a string
this.CreateJob("PaintObject")
end
end
The function this.CreateJob will then call the following job in a jobs.txt file included with your mod:
Code: Select all
BEGIN Job
Name PaintObject
JobTime 10
Material PaintBucket
Tool PaintBrush
Worker Workman
END
After that job is completed, the following function is called by the game, this function then changes the color:
Code: Select all
function JobComplete_PaintObject()
if this.PaintColor = 1 then
this.SubType = 1
end
end
Please note that for the above code to work (particualary the function this.SubType) you will need to define multiple sprites for the object, you will need a sprite for each color, below is an example of an entry for the object in materials.txt. The first sprite listed would be the unpainted object or the default color and is subtype 0. The second sprite would be for the color red and is subtype 1:
Code: Select all
BEGIN Object
Name Door
Price -450
Width 1
Height 1
ConstructionTime 2.00000
Toughness 10.0000
MaxStackSize 1
RenderDepth 0
NumSlots 1
Properties StaticObject
Properties Paintable
Properties Scripted
Group StaticObject
BlockedBy Wall
BlockedBy StaticObject
BEGIN Sprite
x 0
y 8
w 2
h 2
END
BEGIN Sprite
x 0
y 10
w 2
h 2
END
END
Hope this helps!
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 10:08 am
by neoxes
Thanks pal!
Anyway, I already made that code, the problem is that when you script that way a job the worker doesn't go to storage to the get "paint", just work on the object.
I'd like to reproduce those steps (example for a door):
- User places a Door, that is a scriptable object. In Door.lua, Update funcion creates the Interface (various buttons associated with colors).
- When the user click on the interface, choosing a color, I want to:
----- Create an object (not spawn, create), teleportable (or not) to the storage: Paint <------------ HOW CAN I DO THIS?
----- Worker go to storage and bring the Paint to the Door <------------ HOW CAN I DO THIS?
----- Now, your code fits in, Worker completes the Job and paint the door changing its sprite.
Something like flooring or walling, you know? If you create a new material, you can use "ObjectRequired Object" to do what i want to do. The same, but with a door.
Any idea?
Ops... I missed the line: Material Paintbucket, is that the key, right?
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 10:23 am
by murgh
Looks like you're trying to invent the wheel twice:
https://steamcommunity.com/sharedfiles/ ... =540380855There is already a mod doing this
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 10:35 am
by neoxes
I know that mod, I'm using it and I'm triyng to improve it!
With Brento's mod, you have to install a new object "PaintTool", this object search for a near moddable object, paint it and disappear. You can't choose the paint, you have to circle between the sprites, wasting money and time!
I don't like that way, it has too many complications with coding (find near objects, find if is paintable, etc...). So... I'm improving it! Objects will have a new property (you don't have to find them) and the color can be choosen by interface.
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 10:49 am
by murgh
Yeah, that one can have a complete overhaul, it's too complicated to use as it is now. That's why I checked it out only once and then never bothered with it again due to it's unfriendly way of user interaction.
Re: Build and install an object with lua scripting
Posted: Thu Sep 08, 2016 10:55 pm
by dsdude123
neoxes wrote:Thanks pal!
Anyway, I already made that code, the problem is that when you script that way a job the worker doesn't go to storage to the get "paint", just work on the object.
I'd like to reproduce those steps (example for a door):
- User places a Door, that is a scriptable object. In Door.lua, Update funcion creates the Interface (various buttons associated with colors).
- When the user click on the interface, choosing a color, I want to:
----- Create an object (not spawn, create), teleportable (or not) to the storage: Paint <------------ HOW CAN I DO THIS?
----- Worker go to storage and bring the Paint to the Door <------------ HOW CAN I DO THIS?
----- Now, your code fits in, Worker completes the Job and paint the door changing its sprite.
Something like flooring or walling, you know? If you create a new material, you can use "ObjectRequired Object" to do what i want to do. The same, but with a door.
Any idea?
Ops... I missed the line: Material Paintbucket, is that the key, right?
To move the paint to storage, you will need a ProductionRule in production.txt, here is an example:
Code: Select all
BEGIN ProductionRule
Rule Storage
Material PaintBucket
Room Storage
Distribution Nearest
END
You also may need to give the PaintBucket object the AutoOrder property, info on that property is available here:
https://github.com/aubergine10/Prison-Architect-API/wiki/AutoOrderDid you try using the line: Material PaintBucket?
Re: Build and install an object with lua scripting
Posted: Sat Sep 10, 2016 9:40 am
by neoxes
dsdude123 wrote:neoxes wrote:Thanks pal!
Anyway, I already made that code, the problem is that when you script that way a job the worker doesn't go to storage to the get "paint", just work on the object.
I'd like to reproduce those steps (example for a door):
- User places a Door, that is a scriptable object. In Door.lua, Update funcion creates the Interface (various buttons associated with colors).
- When the user click on the interface, choosing a color, I want to:
----- Create an object (not spawn, create), teleportable (or not) to the storage: Paint <------------ HOW CAN I DO THIS?
----- Worker go to storage and bring the Paint to the Door <------------ HOW CAN I DO THIS?
----- Now, your code fits in, Worker completes the Job and paint the door changing its sprite.
Something like flooring or walling, you know? If you create a new material, you can use "ObjectRequired Object" to do what i want to do. The same, but with a door.
Any idea?
Ops... I missed the line: Material Paintbucket, is that the key, right?
To move the paint to storage, you will need a ProductionRule in production.txt, here is an example:
Code: Select all
BEGIN ProductionRule
Rule Storage
Material PaintBucket
Room Storage
Distribution Nearest
END
You also may need to give the PaintBucket object the AutoOrder property, info on that property is available here:
https://github.com/aubergine10/Prison-Architect-API/wiki/AutoOrderDid you try using the line: Material PaintBucket?
I'll try this weekend, thanks for your help!
Re: Build and install an object with lua scripting
Posted: Tue Sep 13, 2016 10:57 am
by neoxes
Works! Thank you all!!!!!!
Just a question, Markers have to be defined for every sprite or just the first one?