How do I charge prisoners to use the phone? [AvailableMoney code help!)

Discussion about Mods for Prison Architect

Moderator: NBJeff

TommyTee
level0
Posts: 5
Joined: Sun Jan 15, 2017 9:17 am

How do I charge prisoners to use the phone? [AvailableMoney code help!)

Postby TommyTee » Sun Jan 15, 2017 9:21 am

So I set the flag RequiresCash in needs.txt and only prisoners with cash are using the object BUT no cash is taken from them.

How do have cash actually taken off the prisoner please once they use an object?

For example
I want prisoners to be charged for using the payphone

So if prisoner A has $6 once hes used the phone he should only have $1 left

I can't figure it out. The RequiresCash flag stops prisoners with less than $5 dollar using but it doesn't actually take money off.

Thanks in advance for any help I'd really appreciate it
Last edited by TommyTee on Sun Jan 15, 2017 1:01 pm, edited 1 time in total.
TommyTee
level0
Posts: 5
Joined: Sun Jan 15, 2017 9:17 am

Re: How do I charge prisoners to use the phone?

Postby TommyTee » Sun Jan 15, 2017 12:18 pm

Okay so I checked out another thread and a coffee machine mod to see how it works.

I created a .lua called Payphone.lua (as it's Payphone in materials.txt) and used this code:

local cost = 5.0;

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 Create()
this.Inmate = this.Id.u;
end

function Update(dt)
if tonumber(this.Slot0.i) > -1 then
inmate = GetObject("Prisoner",this.Slot0.i);
if inmate~=nil and inmate.Id.u ~= this.Inmate then
local cash = tonumber(inmate.AvailableMoney) or 0;
if cash >= cost then
this.inmate = inmate.Id.u;
inmate.AvailableMoney = cash - cost;
end
end
end
end


But it's not working. Again, prisoners with cash are using the phone but no money is being taken off them. He had $12 when he went to the phone and used it, and still had $12 when he stopped.

What's wrong with the above code anyone please?? And why did they make it so difficult to charge prisoners for stuff have such a migraine been trying for hours and hours -_-
TommyTee
level0
Posts: 5
Joined: Sun Jan 15, 2017 9:17 am

Re: How do I charge prisoners to use the phone? [AvailableMoney code help!)

Postby TommyTee » Sun Jan 15, 2017 1:19 pm

Tried this one and it still isn't working

local costPerUse = 5.0;

function GetObject(type,id,dist)
objs = Object.GetNearbyObjects(type,dist or 2);
for o,d in pairs(objs) do
if o.Id.i == id then
return o;
end
end
end

function Update(dt)
if somePrisoner.AvailableMoney >= costPerUse then
somePrisoner.AvailableMoney = somePrisoner.AvailableMoney - costPerUse;
end
end


and this one

local costPerUse = 5.0;

function GetObject(type,id,dist)
objs = Object.GetNearbyObjects(type,dist or 2);
for o,d in pairs(objs) do
if o.Id.i == id then
return o;
end
end
end

function SearchInmate()
if this.Slot0.i == -1 then
return false;
else
inmate = GetObject("Prisoner",this.Slot0.i);
if inmate then
return true;
else
this.Slot0.i = -1;
this.Slot0.u = -1;
return false;
end
end
end

function Update(dt)
if inmate.AvailableMoney >= costPerUse then
inmate.AvailableMoney = inmate.AvailableMoney - costPerUse;
end
end


Why won't it just take the prisoners money :(
TommyTee
level0
Posts: 5
Joined: Sun Jan 15, 2017 9:17 am

Re: How do I charge prisoners to use the phone? [AvailableMoney code help!)

Postby TommyTee » Wed Jan 18, 2017 4:43 am

Can somebody PLEASE help???

Code: Select all

local cost = 10.0

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 Create()
   this.User = this.Id.u;
end

function Update(dt)
   if tonumber(this.Slot0.i) > -1 then
      user = GetObject("Prisoner",this.Slot0.i);
     
      if user~=nil and user.Id.u ~= this.User then
           
            local cash = tonumber(user.AvailableMoney) or 0;
           
            if cash >= cost then
                  this.User = user.Id.u;
                  user.AvailableMoney = cash - cost;
          end
      end


This isn't working. I've set Properties Scripted, lua is named correctly everything. But when they use the object no money is taken off them. They all leave the object with the same amount of cash on them as before they used.

Somebody must know, please?!
K4jot7x
level0
Posts: 8
Joined: Mon Oct 06, 2014 5:40 pm

Re: How do I charge prisoners to use the phone? [AvailableMoney code help!)

Postby K4jot7x » Fri Jun 23, 2017 4:19 am

see

viewtopic.php?f=88&t=60472&p=607991#p607991

the Provider in the needs file must add words

BEGIN Provider
Slot 0
END

-- just setting to Property RequiresMoney can also work

edit too:

local cash = tonumber(user.AvailableMoney or 0); -- this will raise an error before it triggers LUA's nil/false comparison.. automatically come up 0, so changing prisoners balance to negative values

add to auto update also a means of waiting seconds more for action and logging which prisoner was already charged. their money will deplete fast

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 0 guests