HELP coffee machine
Moderator: NBJeff
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
setting .Hidden on any object seems to have no effect in the current api (all of the 1.0 added boolean properties are currently un-settable). it's possible the property is something to do with hidden contraband
You'll almost certainly need to define your markers, and ensure that any additional sprites have the markers defined.
In terms of coffee mugs, once prisoner has drank their coffee they could discard it (clear .carrying and .carrierId by setting i,u to -1) and then use mugObj.ApplyVelocity() to make it look like it's been thrown away, maybe with a little rotation too. In the mug Update() it could check to see when it's carrierId gets cleared and then set a time x seconds in future to self-delete.
Object.Spawn() works fine every time I've used it. Game.DebugOut() the x and y vals before passing them in to Spawn() just to check that they are not 0 or nil, as it's likely the values you're passing in that are broken. Spawn() is one of the few pieces of API that isn't full of bugs.
It would really help if you could upload your mod to github so we can look at materials.txt and .lua files when trying to work out what's causing issues. Remember that if you put in a slot, the object will move to where the slot is (defined by markers on the sprite). So if the markers for your slot are at some crazy off-map location (or not set at all), then the object put in the slot will slap up against the map border in that general direction.
You'll almost certainly need to define your markers, and ensure that any additional sprites have the markers defined.
In terms of coffee mugs, once prisoner has drank their coffee they could discard it (clear .carrying and .carrierId by setting i,u to -1) and then use mugObj.ApplyVelocity() to make it look like it's been thrown away, maybe with a little rotation too. In the mug Update() it could check to see when it's carrierId gets cleared and then set a time x seconds in future to self-delete.
Object.Spawn() works fine every time I've used it. Game.DebugOut() the x and y vals before passing them in to Spawn() just to check that they are not 0 or nil, as it's likely the values you're passing in that are broken. Spawn() is one of the few pieces of API that isn't full of bugs.
It would really help if you could upload your mod to github so we can look at materials.txt and .lua files when trying to work out what's causing issues. Remember that if you put in a slot, the object will move to where the slot is (defined by markers on the sprite). So if the markers for your slot are at some crazy off-map location (or not set at all), then the object put in the slot will slap up against the map border in that general direction.
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
Regarding warning icon, found this in objects.spritebank:
BEGIN "[i 3]" Name Alert x 35 y 12 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 4]" Name AlertElectrical x 35 y 12 w 2 h 2 RotateType 0 TopAligned false END
I've not tested to see if there is an undocumented way to spawn it (like the `SmokeGenerator` object), but you could try:
Object.Spawn('Alert', <x>, <y>)
If that doesn't work you'll have to define a custom object that uses the sprite; even then it's possible it won't animate. If you get it working, please let us know
Also found these which may be of use for your mod:
BEGIN "[i 78]" Name Cup x 28 y 94 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 401]" Name MoneyBag x 28 y 126 w 2 h 2 RotateType 0 TopAligned false END
And just storing these here for my own future reference:
BEGIN "[i 457]" Name PoweredIcon x 35 y 0 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 458]" Name PoweredOffIcon x 35 y 0 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 649]" Name WaterIcon x 35 y 4 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 650]" Name WaterOffIcon x 35 y 4 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 652]" Name Wave x 35 y 8 w 2 h 2 RotateType 0 TopAligned false END
Out of interest, have you experimented with the somePrisoner.AvailableMoney property via scripting? If so, did setting the value work?
BEGIN "[i 3]" Name Alert x 35 y 12 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 4]" Name AlertElectrical x 35 y 12 w 2 h 2 RotateType 0 TopAligned false END
I've not tested to see if there is an undocumented way to spawn it (like the `SmokeGenerator` object), but you could try:
Object.Spawn('Alert', <x>, <y>)
If that doesn't work you'll have to define a custom object that uses the sprite; even then it's possible it won't animate. If you get it working, please let us know
Also found these which may be of use for your mod:
BEGIN "[i 78]" Name Cup x 28 y 94 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 401]" Name MoneyBag x 28 y 126 w 2 h 2 RotateType 0 TopAligned false END
And just storing these here for my own future reference:
BEGIN "[i 457]" Name PoweredIcon x 35 y 0 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 458]" Name PoweredOffIcon x 35 y 0 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 649]" Name WaterIcon x 35 y 4 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 650]" Name WaterOffIcon x 35 y 4 w 2 h 2 RotateType 0 TopAligned false END
BEGIN "[i 652]" Name Wave x 35 y 8 w 2 h 2 RotateType 0 TopAligned false END
Out of interest, have you experimented with the somePrisoner.AvailableMoney property via scripting? If so, did setting the value work?
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:Object.Spawn() works fine every time I've used it. Game.DebugOut() the x and y vals before passing them in to Spawn() just to check that they are not 0 or nil, as it's likely the values you're passing in that are broken. Spawn() is one of the few pieces of API that isn't full of bugs.
The x and y was not nil, the problem was the script in the spawned object...
Code: Select all
function Create()
this.rx = this.Pos.x;
this.ry = this.Pos.y;
end
function Update(dt)
if this.Pos.x ~= this.rx or this.Pos.y ~= this.ry then
this.Pos.x = this.rx;
this.Pos.y ~= this.ry;
end
end
For some reason the X and Y on Create is nil...
aubergine18 wrote:I've not tested to see if there is an undocumented way to spawn it (like the `SmokeGenerator` object), but you could try:
Object.Spawn('Alert', <x>, <y>)
If that doesn't work you'll have to define a custom object that uses the sprite; even then it's possible it won't animate. If you get it working, please let us know
I dont think that you can spawn a sprite. You must create a material in materials.txt with "Sprite = Alert" and then Object.Spawn(thematerialname,x,y);
aubergine18 wrote:Out of interest, have you experimented with the somePrisoner.AvailableMoney property via scripting? If so, did setting the value work?
Yes it works.
Code: Select all
if somePrisoner.AvailableMoney >= cost then
somePrisoner.AvailableMoney = somePrisoner.AvailableMoney - cost;
end
Last edited by DarknessEyes on Fri Oct 23, 2015 7:57 pm, edited 1 time in total.
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
regarding the sprite, I know you can't spawn a sprite... what I meant was is that, like SmokeGenerator - which isn't in materials.txt or anywhere other .txt file, there might be some variation of the word 'Alert' that can be used to spawn an object even though that object isn't mentioned in materials.txt. Maybe 'AlertIcon' or 'AlertIndicator' or something like that.
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:regarding the sprite, I know you can't spawn a sprite... what I meant was is that, like SmokeGenerator - which isn't in materials.txt or anywhere other .txt file, there might be some variation of the word 'Alert' that can be used to spawn an object even though that object isn't mentioned in materials.txt. Maybe 'AlertIcon' or 'AlertIndicator' or something like that.
oh. ty
Now i have a problem with
Code: Select all
function Slot1Info()
if this.Slot1.i == -1 then
return "empty";
else
inmate = GetObject("Prisoner",this.Slot1.i);
locker = GetObject(lockername,this.Slot1.i);
if inmate then
return "inmate";
elseif locker and locker.Type == lockername then
return "locker";
elseif locker then
locker.Loaded = false;
this.Slot1.i = -1;
this.Slot1.u = -1;
return "invalid";
else
this.Slot1.i = -1;
this.Slot1.u = -1;
return "invalid";
end
end
endFor some reason it returns "invalid" (the last one after else) when an prisoner or the material SlotLocker is using it...
Edited:
Alert is the one i wanted!
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
By material do you mean a BEGIN Object definition with Properties Material, or a BEGIN Material definition? If the latter, Materials are invisible to GetNearbyObjects() (you have to use GetMaterial() instead).
Also, depending on where the slot marker is in relation to the origin of the x,y of the drink machine, distance between them might be greater than 1... try increasing the search distance to 2 and see if that helps.
Also, depending on where the slot marker is in relation to the origin of the x,y of the drink machine, distance between them might be greater than 1... try increasing the search distance to 2 and see if that helps.
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:By material do you mean a BEGIN Object definition with Properties Material, or a BEGIN Material definition? If the latter, Materials are invisible to GetNearbyObjects() (you have to use GetMaterial() instead).
Code: Select all
BEGIN Object
Name DESlotLocker
Sprite Alert
Properties Material
Properties Scripted
Price -1
Properties Sellable
ENDaubergine18 wrote:Also, depending on where the slot marker is in relation to the origin of the x,y of the drink machine, distance between them might be greater than 1... try increasing the search distance to 2 and see if that helps.
The spawn in both cases are at this.Pos.x and at this.Pos.y
Code: Select all
function Slot0Info()
if this.Slot0.i == -1 then
return "empty";
else
stack = GetObject("Stack",this.Slot0.i);
locker = GetObject(lockername,this.Slot0.i);
if stack and stack.Contents == stockname then
return "stack";
elseif locker and locker.Type == lockername then
return "locker";
elseif stack then
stack.Loaded = false;
this.Slot0.i = -1;
this.Slot0.u = -1;
return "invalid";
elseif locker then
locker.Loaded = false;
this.Slot0.i = -1;
this.Slot0.u = -1;
return "invalid";
else
this.Slot0.i = -1;
this.Slot0.u = -1;
return "invalid";
end
end
endthis code is for slot0, its almost like the one for slot1 but this one works
returns empty if empty
returns stack if the coffee beans are loaded.
returns locker if the DESlotLocker is blocking the slot0
Edited in slot1Info code posted in previous post:
Spawn locker and attach it to slot1
Returns invalid from slot1info and detaches it.
Then returns empty..
Then repeat the above
Edited:
WTH. i swapped the slots... seems that you only can attach objects to slot0?!?
to attach an object to a slot im using
Code: Select all
spawn = Object.Spawn(lockername,this.Pos.x,this.Pos.y);
spawn.Loaded = true;
spawn.CarrierId.i = this.Id.i;
spawn.CarrierId.u = this.Id.u;
this.Slot0.i = spawn.Id.i;
this.Slot0.u = spawn.Id.u;
Blocking slot0 with an object doesnt prevent prisoners from using slot0 to get coffee...
This game modding is very annoying... Lacks alots on functions... Time to try next method using only one slot...
Slot0 where stacks are loaded...
Machine spawn a coffee mug 1 slot away...
Machine checks if the coffee mug is still there every 1 sec... If not there and stock >= 1 then spawn a new one...
Needs.txt will point prisoners to the mug...
Last edited by DarknessEyes on Fri Oct 23, 2015 9:24 pm, edited 1 time in total.
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
It doesn't matter where it's spawned. When you add something to a slot, it's x,y is moved to the position of the slot (which is defined by the marker). Unless the marker is at 0,0 (offset from x,y) then the thing in the slot will not be at the same position as whatever it is that the slot is part of.
Also, you can attach stuff to multiple slots - see my Circuit Isolator mod in workshop which uses 3 slots, and all 3 have markers defining their position in the materials.txt.
Also, x,y works weirdly in-game. It's something like the middle of the object (maybe bottom-middle) rather than the bottom left. Some objects are also top-aligned. Not had chance to fully investigate but often you'll find that x,y doesn't match up fully with the map coordinate you're expecting.
Also, you can attach stuff to multiple slots - see my Circuit Isolator mod in workshop which uses 3 slots, and all 3 have markers defining their position in the materials.txt.
Also, x,y works weirdly in-game. It's something like the middle of the object (maybe bottom-middle) rather than the bottom left. Some objects are also top-aligned. Not had chance to fully investigate but often you'll find that x,y doesn't match up fully with the map coordinate you're expecting.
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:It doesn't matter where it's spawned. When you add something to a slot, it's x,y is moved to the position of the slot (which is defined by the marker). Unless the marker is at 0,0 (offset from x,y) then the thing in the slot will not be at the same position as whatever it is that the slot is part of.
Also, you can attach stuff to multiple slots - see my Circuit Isolator mod in workshop which uses 3 slots, and all 3 have markers defining their position in the materials.txt.
Also, x,y works weirdly in-game. It's something like the middle of the object (maybe bottom-middle) rather than the bottom left. Some objects are also top-aligned. Not had chance to fully investigate but often you'll find that x,y doesn't match up fully with the map coordinate you're expecting.
I swapped slots in all files...
locking slot0 with an object doesnt prevent prisoners from using slot0 to get coffee...
Using slot1 to load the beans returns "invalid" with Slot1info...
This game modding is very annoying... Lacks alots on functions... Time to try next method using only one slot...
Slot0 where stacks of beans is loaded...
Machine spawn a coffee mug 1 slot away and decreases stack by one...
Machine checks if the coffee mug is still there every 1 sec... If not there and stack >= 1 then spawn a new one and reduce stack by one...
Needs.txt will point prisoners to the mug...
(the mug will not be attached to any slot)
The mug will seach for its mother (the vending machine that spawned it) and the mother will search for her son.
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:It doesn't matter where it's spawned. When you add something to a slot, it's x,y is moved to the position of the slot (which is defined by the marker). Unless the marker is at 0,0 (offset from x,y) then the thing in the slot will not be at the same position as whatever it is that the slot is part of.
Also, you can attach stuff to multiple slots - see my Circuit Isolator mod in workshop which uses 3 slots, and all 3 have markers defining their position in the materials.txt.
Also, x,y works weirdly in-game. It's something like the middle of the object (maybe bottom-middle) rather than the bottom left. Some objects are also top-aligned. Not had chance to fully investigate but often you'll find that x,y doesn't match up fully with the map coordinate you're expecting.
Do you have to define markers? or their by default at center of the object?
btw here is the full code i have
Code: Select all
local debug = true;
local cost = 5.0;
local lockername = "DESlotLocker";
local stockname = "DECoffeeBox";
local stockmin = 5;
local stockmax = 15;
function Err(message)
if debug then
time = FRound(Game.Time(),0);
Game.DebugOut("<"..tostring(time).."> "..message);
end
end
function Clock(secs)
mins = 0;
while secs >= 60 do
secs = secs - 60;
mins = mins + 1;
end
if mins <= 0 then
return secs.."s";
else
return mins.."m "..secs.."s";
end
end
function FRound(num,idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num));
end
function GetObject(type,id,dist)
objs = Object.GetNearbyObjects(type,dist or 1);
for o,d in pairs(objs) do
if o.Id.i == id then
return o;
end
end
end
function Slot0Info()
if this.Slot0.i == -1 then
return "empty";
else
inmate = GetObject("Prisoner",this.Slot0.i);
locker = GetObject(lockername,this.Slot0.i);
if inmate then
return "inmate";
elseif locker then
return "locker";
else
this.Slot0.i = -1;
this.Slot0.u = -1;
return "invalid";
end
end
end
function Slot1Info()
if this.Slot1.i == -1 then
return "empty";
else
stack = GetObject("Stack",this.Slot1.i);
locker = GetObject(lockername,this.Slot1.i);
if stack and stack.Contents == stockname then
return "stack";
elseif locker and locker.Type == lockername then
return "locker";
elseif stack then
stack.Loaded = false;
this.Slot1.i = -1;
this.Slot1.u = -1;
return "invalid";
elseif locker then
locker.Loaded = false;
this.Slot1.i = -1;
this.Slot1.u = -1;
return "invalid";
else
this.Slot1.i = -1;
this.Slot1.u = -1;
return "invalid";
end
end
end
function Create()
this.otime = 0;
this.stock = 1;
this.cash = 0;
this.job = false;
this.timeout = Game.Time() + 900;
Err("Create: script loaded.");
end
function Update(dt)
if not this.otime then
this.otime = 0;
end
if not this.stock then
this.stock = 0;
end
gtime = FRound(Game.Time(),0);
if gtime > this.otime then
this.otime = gtime;
slot0 = Slot0Info();
slot1 = Slot1Info();
Err(slot0.." / "..slot1);
if slot1 == "empty" and this.stock >= stockmax then
spawn = Object.Spawn(lockername,this.Pos.x,this.Pos.y);
spawn.Loaded = true;
spawn.CarrierId.i = this.Id.i;
spawn.CarrierId.u = this.Id.u;
this.Slot1.i = spawn.Id.i;
this.Slot1.u = spawn.Id.u;
Err("Slot1: Spawn locker.");
elseif slot1 == "locker" and this.stock <= stockmin then
locker = GetObject(lockername,this.Slot1.i);
locker.Delete();
Err("Slot1: Deleted locker.");
elseif slot1 == "stack" then
stack = GetObject("Stack",this.Slot1.i);
while this.stock < stockmax and stack.Quantity > 0 do
this.stock = this.stock + 1;
stack.Quantity = stack.Quantity - 1;
Err("Slot1: Increased stock by one.");
end
if stack.Quantity >= 1 then
stack.Loaded = false;
this.Slot1.i = -1;
this.Slot1.u = -1;
Err("Slot1: Stock full.");
end
end
if slot0 == "empty" and this.stock <= 0 then
spawn = Object.Spawn(lockername,this.Pos.x,this.Pos.y);
spawn.Loaded = true;
spawn.CarrierId.i = this.Id.i;
spawn.CarrierId.u = this.Id.u;
this.Slot0.i = spawn.Id.i;
this.Slot0.u = spawn.Id.u;
Err("Slot0: Spawn locker.");
elseif slot0 == "locker" and this.stock >= 1 then
locker = GetObject(lockername,this.Slot0.i);
locker.Delete();
Err("Slot0: Deleted locker.");
elseif slot0 == "prisoner" then
prisoner = GetObject("Prisoner",this.Slot0.i);
if prisoner.AvailableMoney >= cost then
this.stock = this.stock - 1;
prisoner.AvailableMoney = prisoner.AvailableMoney - cost;
prisoner.Needs.Sleep = 0;
Err("Slot0: Prisoner need full.");
else
prisoner.Loaded = false;
this.Slot0.i = -1;
this.Slot0.u = -1;
Err("Slot0: invalid prisoner.");
end
end
if this.stock > 0 then
this.stock = this.stock - 1;
end
end
this.Tooltip = "Stock: "..this.stock.."\nThis: "..this.Id.u.."\nSlot0: "..this.Slot0.u.."\nSlot1: "..this.Slot1.u;
end- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
I assume you used NumSlots setting in materials.txt to limit the number of slots the game can use by default? (your script can still use all 8 slots, regardless of NumSlots setting)
EDIT: Yes, if you want to be sure that the markers are where you think they are, you must define them, otherwise you're relying directly on code written by IV - and as the mantis bug tracker illustrates, with over 9000 bugs logged so far, they are not great at coding. The more manual control you can take over things the better, as it reduces your reliance on their buggy code.
EDIT: Yes, if you want to be sure that the markers are where you think they are, you must define them, otherwise you're relying directly on code written by IV - and as the mantis bug tracker illustrates, with over 9000 bugs logged so far, they are not great at coding. The more manual control you can take over things the better, as it reduces your reliance on their buggy code.
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:I assume you used NumSlots setting in materials.txt to limit the number of slots the game can use by default? (your script can still use all 8 slots, regardless of NumSlots setting)
EDIT: Yes, if you want to be sure that the markers are where you think they are, you must define them, otherwise you're relying directly on code written by IV - and as the mantis bug tracker illustrates, with over 9000 bugs logged so far, they are not great at coding. The more manual control you can take over things the better, as it reduces your reliance on their buggy code.
Yes i have 2 slots set. Using slot1 to stock materials doesnt even work.
Code: Select all
BEGIN ProductionRule
Rule Storage
Material DESnackBox
Container DESnackMachine
Distribution Random
Condition NotLoaded
MinSlotId 1
MaxSlotId 1
ENDHow do u mark the slots? Im using default sprites
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
Ah, in that case you'll be getting the default markers - if there are any... viewtopic.php?f=88&t=55643
-
DarknessEyes
- level2

- Posts: 105
- Joined: Sat Apr 26, 2014 11:47 pm
Re: HELP coffee machine
aubergine18 wrote:Ah, in that case you'll be getting the default markers - if there are any... viewtopic.php?f=88&t=55643
I think i found the problem O.o
Item is 1w1h and have 2 slots... slots0 is over slot1... so slot1 is invalid?!?
Is is possible to define 2 slots in an item 1w1h? Or the vending machine must be 2w1h?
I cant understand the markers O.o
Last edited by DarknessEyes on Sat Oct 24, 2015 12:05 am, edited 2 times in total.
- aubergine18
- level2

- Posts: 231
- Joined: Sun Jul 05, 2015 3:24 pm
Re: HELP coffee machine
Yes, you can define multiple slots on a 1x1 or any size object. I'm not sure if there are limitations in respect to proximity of slots.
If you're using base-game sprite (defined in objects.spritebank and the image either in objects.png or people.png) then you're in for a world of pain when it comes to customising anything to do with the sprite or it's slot markers; namely you'll have to clone the whole objects.spritebank file to your mod - you then get three major problems:
1. Only one mod at a time can replace objects.spritebank - so your mod will conflict with any others that do the same
2. As Trixi found recently, if multiple active mods try to change objects.spritebank it can cause game crash
3. If a game update changes the vanilla objects.spritebank the altered version in your mod will be out of sync with the base game
That being said, I still don't see why having two slots in same place would cause a problem - that would in theory only change the way things look on screen, but shouldn't affect the game data as to what can go in each slot.
Can you upload your mod to github.com so I can take a proper look at it all in one place and send pull requests if I spot any errors?
If you're using base-game sprite (defined in objects.spritebank and the image either in objects.png or people.png) then you're in for a world of pain when it comes to customising anything to do with the sprite or it's slot markers; namely you'll have to clone the whole objects.spritebank file to your mod - you then get three major problems:
1. Only one mod at a time can replace objects.spritebank - so your mod will conflict with any others that do the same
2. As Trixi found recently, if multiple active mods try to change objects.spritebank it can cause game crash
3. If a game update changes the vanilla objects.spritebank the altered version in your mod will be out of sync with the base game
That being said, I still don't see why having two slots in same place would cause a problem - that would in theory only change the way things look on screen, but shouldn't affect the game data as to what can go in each slot.
Can you upload your mod to github.com so I can take a proper look at it all in one place and send pull requests if I spot any errors?
Who is online
Users browsing this forum: No registered users and 6 guests

