Jump to content

Container Script - Magic Box


Keleigh3000

Recommended Posts

OK, not a magic box exactly, but the subject line can only contain so much. Basically, I want to script a container so that the PC puts certain specific items in it and after a defined period of time passes in game those items are replaced by the same number of a different item. So, an easy bake oven script, essentially.

 

Any help that is given will be appreciated. Thanks.

Link to comment
Share on other sites

The following script will bake as many as you put in, but only in full batches. What I mean is, say your bake time is 4 hours. If you put in 3 raw items at noon, and 3 more raw items at 2PM, you will get 3 finished items at 4PM as expected. However, ones you put in at 2PM won't actually start baking until the first batch is done, so the second batch won't be ready until 8PM.

float Timer
short Converting
short NumItems

BEGIN gamemode
   
if GetItemCount MyRawItem > 0
   if Converting == 0
      set NumItems to GetItemCount MyRawItem
      set Converting to 1
      set Timer to GameDaysPassed
   elseif Converting == 1
      if (GameDaysPassed - Timer) > CookTime ; CookTime in days
         if NumItems > GetItemCount MyRawItem
            ; Took some (but not all) out before they were done
            set NumItems to GetItemCount MyRawItem
         endif
         removeitem MyRawItem NumItems
         additem MyFinishedItem NumItems
         set Converting to 0
      endif
   endif
else
   if Converting == 1
      set Converting to 0  ; took them out before they're done, start over
   endif
endif

END

An alternative would be to put a message in the OnActivate block that says "oven in use", and doesn't activate the container so you can't open it again until a full batch is done - like an actual easy bake oven :smile:

float Timer
short Converting
short NumItems

BEGIN OnActivate

if Converting == 1
   showmessage OvenInUseMessage
else
   activate
endif

END

BEGIN GameMode
   
if GetItemCount MyRawItem > 0
   if Converting == 0
      set Converting to 1
      set Timer to GameDaysPassed
   elseif Converting == 1
      if (GameDaysPassed - Timer) > CookTime ; CookTime in days
         set NumItems to GetItemCount MyRawItem
         removeitem MyRawItem NumItems
         additem MyFinishedItem NumItems
         set Converting to 0
      endif
   endif
endif

END
Link to comment
Share on other sites

  • 4 weeks later...

One more question on this, if anyone is about this morning. I'm using the second script above as the core of my "oven", is there any way that the "oven in use" message could display the remaining time on the timer? (Preferably in a reasonably normal fashion, i.e 6 hours, or 6.5 hours rather than .2471 days or some such.) Thanks...

Link to comment
Share on other sites

You can put a replaceable parameter in the message text like so:

%.0f Hours Remaining.

This will round to the nearest hour. If you want a fractional hour, change the zero in the message box format specifier to the number of decimal places you want to show (e.g. %.1f for one decimal). Then use code like this to pass the number of hours to the showmessage command:

float CookTimeHours
set CookTimeHours to CookTime * 24
showmessage OvenInUseMessage CookTimeHours
Link to comment
Share on other sites

  • 2 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...