(Help!) Grounds Checker mod

Discussion about Mods for Prison Architect

Moderator: NBJeff

GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

(Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 4:53 am

Hello there! I have been really excited this past half hour because i have been making BIG headway in my mod, but i ran into a big problem. I don't know how to script a simple job, i want my "Grounds Checker" (A new staff member i added) to basically check the WHOLE outdoor of the prison randomly one "tile" at a time for tunnels dug by prisoners with an about 10% chance of succeeding per tile.

Kind of like how the workman is building something and it takes like ten seconds most of the time, i wan't my Grounds Checker to check one tile at a time like that. If anyone could direct me to a script that would help me out (Or even give me one), that would be awesome! Thanks.

Also, if anyone knows anything about setting staff wages and how to make a staff member "wander" when idle then please send the code to me. Thanks again!
Puman
level1
level1
Posts: 48
Joined: Fri Aug 29, 2014 1:21 pm

Re: (Help!) Grounds Checker mod

Postby Puman » Fri Jan 02, 2015 7:41 am

Adding staff hasn't really been implemented in the mod-system. If you want them to behave you have to code it all by yourself. There is some code for 'idling' in my Hot Chicks mod. Last I checked you couldn''t add jobs either, you'd have to implement that in code too.
Puman
level1
level1
Posts: 48
Joined: Fri Aug 29, 2014 1:21 pm

Re: (Help!) Grounds Checker mod

Postby Puman » Fri Jan 02, 2015 7:43 am

Have you been successful in detecting tunnels by the way?
JASPer.Gamer.9.0
level3
level3
Posts: 380
Joined: Fri Sep 06, 2013 12:29 am

Re: (Help!) Grounds Checker mod

Postby JASPer.Gamer.9.0 » Fri Jan 02, 2015 9:50 am

Puman wrote:Have you been successful in detecting tunnels by the way?

Please edit your posts, so that you will use less space in the forums. Also, multiple posts are useless to the topic.
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: (Help!) Grounds Checker mod

Postby Chad » Fri Jan 02, 2015 1:27 pm

Why do you want that type of staff? Doesn't the dog handler do exactly the same?

As Puman said, you have to code everything by yourself and I'm not sure if you can detect tunnels via the mod system. I've tried to detect small pipes or cables, but failed. If you could detect tunnels, you have to code your own AI, because wandering around randomly wouldn't work well. There is no way to assign new staff to routes or rooms.

For wages you have to code it by yourself too (haven't found a property for that). There may be a way to hack around, but I'm not sure.

JASPer.Gamer.9.0 wrote:Please edit your posts, so that you will use less space in the forums. Also, multiple posts are useless to the topic.

I really don't like double posts too, but your post is more useless, as it doesn't contribute anything to the topic. Next time you can write PM if you doesn't like the behavior of other users ;)
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 5:47 pm

Puman wrote:Have you been successful in detecting tunnels by the way?


So far i just finished implementing him into the staff toolbar and making his sprite handle right, and i haven't done anything with the script yet.

Chad wrote:Why do you want that type of staff? Doesn't the dog handler do exactly the same?


Yes, in a way. I wan't this staff member to have an even lower chance to find digging, but be able to "un"-dig it. Instead of, like the dog, just showing a trowel alert which could be a possible false alarm. At first, i thought the trowel alert was just that they found a trowel lying around somewhere, and in thinking so, i lost four prisoners in about 10 seconds... Nobody had a need for freedom anyway!

Chad wrote:As Puman said, you have to code everything by yourself and I'm not sure if you can detect tunnels via the mod system. I've tried to detect small pipes or cables, but failed. If you could detect tunnels, you have to code your own AI, because wandering around randomly wouldn't work well. There is no way to assign new staff to routes or rooms.


:oops: Well this could be a problem. I don't have much coding experience (what i have is from gamemaker scripting :shock: ), and the way you say it makes it seem i have to code EVERYTHING. Hoping that wasn't true, but....ehh...

Chad wrote:For wages you have to code it by yourself too (haven't found a property for that). There may be a way to hack around, but I'm not sure.


Well, if you ever do find a code for the wages, let me know.
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 7:29 pm

Ok, so i looked around and got some scripts that i thought would work. I know that prisoners dig an object probably named something other than "tunnel" right now, but it's a work in progress. Right now i thought it would work, but the staff member still doesn't do anything. I put in a code to make him "wander...ish" by applying a volocity after 1 second, but that didn't do anything. Here is my code.

This is within my mod folder/data/scripts/groundschecker.lua. I checked to make sure i got the object name right for the lua script, but it was. So that's not the problem

CODE wrote:

Code: Select all

function Create()
  if Object.GetNearbyObjects( "Tunnel", 100.0 ) => 1 then
    Object.CreateJob("TunnelCheck");
    Object.SetProperty("Job", true);
    Object.SetProperty("Tootip", "job_tunnelcheck");
    Object.SetProperty("Count", 0.0);
   return;
end

function JobComplete_TunnelCheck()
  if Object.GetNearbyObjects( "Tunnel", 100.0 ) => 1 then
    Object.CreateJob("TunnelCheck");
    Object.SetProperty("Tootip", "job_tunnelcheck");
   if Object.GetNearbyObjects( "Tunnel", 100.0 ) =< 0 then
     Object.SetProperty("Job", false);
     return;
end

function Update( timePassed )
  if count > 1.0 then
    if GetProperty("Job", false)
     Object.ApplyVelocity( 1, 0, true)
     if GetProperty("Job", true)
       Object.ApplyVelocity( 0, 0, false)
      count = 0.0
      return;
   return;
end


Object.SetProperty ("Job") is a variable which i am using to say "Is the job in progress?"

I cant tell if count is working. I want it to basically....count.

At function Create() when i say to check for the "Tunnel" object i am wanting to check for it and if it returns with "there is more than zero around" i want my staff member to move to where it is and check there. If there are not any within the 100 check radius, i want it to count for one second, and then start moving sideways (X, is left/right...right?)
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: (Help!) Grounds Checker mod

Postby Chad » Fri Jan 02, 2015 7:43 pm

First, Object.GetNearbyObjects() needs 3 parameters for your example, or 2 if you use this. Second, GetNearbyObjects returns a table with all matching objects (the objects itself and the distance), not a number. Better is the following:

Code: Select all

allTunnels = this.GetNearbyObjects("Tunnel",100)
for table, distance in pairs(allTunnels) do
  -- do your stuff, you could save all tunnels in a table, set a flag and then move the checker to the position
end


For me the Tooltip is a great debug tool. You could start small with that:

Code: Select all

allTunnels = this.GetNearbyObjects("Tunnel",100)
local counter = 0
for table, distance in pairs(allTunnels) do
 counter = counter + 1
end
this.Tooltip = tostring(counter) .. " tunnels found."


So you could minimize other errors and check if there is actually a way to find tunnels. Ideal would be a savegame where you already know, that there are tunnels to find.

I hope I could help! Good luck, feel free to ask and share your results.

Edit:

there is a file lua_functions_list.txt in the games data folder with all useable functions, parameters and return values.
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 8:37 pm

Thanks! Most of the functions i was using were from the lua_functions_list.
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 9:11 pm

How would i go by opening the debugger console? I inserted your code and you said to use that, but i don't know how to open it. I found the debugger save file, but it doesn't have anything to say about my script?
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: (Help!) Grounds Checker mod

Postby Chad » Fri Jan 02, 2015 9:19 pm

GamingBud wrote:How would i go by opening the debugger console? I inserted your code and you said to use that, but i don't know how to open it. I found the debugger save file, but it doesn't have anything to say about my script?


You don't need the debug console. You actually get the information in the objects tooltip when you hover over it.
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 10:04 pm

Ok Chad. I inserted the second code you gave me and in-game i placed the staff member and hovered over him. All it said was

Grounds Checker
Carrying staff key

I placed your second code inside of the groundschecker.lua script and just pasted it first without deleting my other script
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: (Help!) Grounds Checker mod

Postby Chad » Fri Jan 02, 2015 10:16 pm

GamingBud wrote:Ok Chad. I inserted the second code you gave me and in-game i placed the staff member and hovered over him. All it said was

Grounds Checker
Carrying staff key

I placed your second code inside of the groundschecker.lua script and just pasted it first without deleting my other script


If you provide the full code of your Update() function, I'll check it for you!
GamingBud
level2
level2
Posts: 194
Joined: Mon Dec 29, 2014 8:33 pm

Re: (Help!) Grounds Checker mod

Postby GamingBud » Fri Jan 02, 2015 10:18 pm

Oh, X). My bad, i didn't know i was supposed to insert it into the Function Update( timePassed ) part :P

EDIT: I inserted it into the update function and it still did not say anything in the tooltip. Here is the full code

Code: Select all

function Create()
  if Object.GetNearbyObjects( "Tunnel", 100.0 ) => 1 then
    Object.CreateJob("TunnelCheck");
    Object.SetProperty("Job", true);
    Object.SetProperty("Tootip", "job_tunnelcheck");
    Object.SetProperty("Count", 0.0);
   return;
end

function JobComplete_TunnelCheck()
  if Object.GetNearbyObjects( "Tunnel", 100.0 ) => 1 then
    Object.CreateJob("TunnelCheck");
    Object.SetProperty("Tootip", "job_tunnelcheck");
   if Object.GetNearbyObjects( "Tunnel", 100.0 ) =< 0 then
     Object.SetProperty("Job", false);
     return;
end

function Update( timePassed )
  allTunnels = this.GetNearbyObjects("Tunnel",100)
local counter = 0
for table, distance in pairs(allTunnels) do
 counter = counter + 1
end
this.Tooltip = tostring(counter) .. " tunnels found."
  if count > 1.0 then
    if GetProperty("Job", false)
     Object.ApplyVelocity( 1, 0, true)
     if GetProperty("Job", true)
       Object.ApplyVelocity( 0, 0, false)
      count = 0.0
      return;
   return;
end
User avatar
Chad
level3
level3
Posts: 255
Joined: Wed Sep 26, 2012 8:00 pm

Re: (Help!) Grounds Checker mod

Postby Chad » Fri Jan 02, 2015 10:44 pm

Your lua code was really bad (sorry). Heres a minimal working example:

Code: Select all

function Create()

end

function Update(timePassed)
   allTunnels = this.GetNearbyObjects("Tunnel",100)
   local counter = 0
   for table, distance in pairs(allTunnels) do
      counter = counter + 1
   end
   this.Tooltip = tostring(counter) .. " tunnels found."
end


if statements always look like that:

if x == y then
-- do something
end

Your code misses then's and end's (the debug console popped out, crying with errors). You should start with that minimal script, check if he can find tunnels and continue if he does.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 5 guests