Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Untitled on October 30, 2013, 03:51:14 pm

Title: Script Variable Based On Game Variable
Post by: Untitled on October 30, 2013, 03:51:14 pm
I guess the title is right...?

This is probably ridiculously simple (but hard to explain and therefore search, sorry ^-^; ), but how do I set something in a script to be Variable?

Like, I'm using Jet10985 (http://pastebin.com/raw.php?i=bT1DPR5H)'s Hunger/Thirst system, but instead of having a Thirst system, I want each actor's maximum hunger to be different. I have these set to variables that I want to refer to with this modified little thing
  ACTOR_MAXHUNGER_VARIABLES = {
 
  1 => 94,  # ACTOR_ID => VARIABLE_ID
  2 => 95,  # ACTOR_ID => VARIABLE_ID
  3 => 96,  # ACTOR_ID => VARIABLE_ID
  4 => 97  # ACTOR_ID => VARIABLE_ID
  }

But then what would I do to
  # What is the maximum hunger?
  MAX_HUNGER = somehowputavariablehere
?

Hopefully that makes sense, and thanks in advance!
Title: Re: Script Variable Based On Game Variable
Post by: WhiteRose on October 30, 2013, 04:18:08 pm
If you want to access just the in-game variables as you would in an event, I think it's just:

$game_variables[i]


where "i" is the number of the variable. :)
Title: Re: Script Variable Based On Game Variable
Post by: KK20 on October 30, 2013, 05:08:28 pm
The script is going to need substantial amounts of edits to accommodate that feature.

@WhiteRose
That's not quite what he's asking for :P
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on October 30, 2013, 05:20:06 pm
Oh, well that is what I asked for, but I guess not knowing how things are organized in RGSS means I can't exactly use it for what I wanted ^-^;

Hm, guess I'll go back to trying to find a script that already does what I need (while constantly reminding Google that VX Ace is not VX <_<")
Title: Re: Script Variable Based On Game Variable
Post by: WhiteRose on October 30, 2013, 05:43:21 pm
Quote from: KK20 on October 30, 2013, 05:08:28 pm
@WhiteRose
That's not quite what he's asking for :P


At least I gave it a noble attempt. :P
Title: Re: Script Variable Based On Game Variable
Post by: Heretic86 on October 30, 2013, 06:02:43 pm
Google: Search for "VX -VXA -Ace " should make the search results exclude Ace related stuff, done with the - symbol.

Scripting: Variables can be forced to hold more than just Numbers.  If you really wanted to, you could set the $game_variables[Array ID] = an Object, another Array, a String, pretty much anything you want.

In this section of code:

  # What is the maximum hunger?
 MAX_HUNGER = somehowputavariablehere


It sounds like your solution might be this:


 ACTOR_MAXHUNGER_VARIABLES = {
 
 1 => 94,  # ACTOR_ID => VARIABLE_ID
 2 => 95,  # ACTOR_ID => VARIABLE_ID
 3 => 96,  # ACTOR_ID => VARIABLE_ID
 4 => 97  # ACTOR_ID => VARIABLE_ID
 }

 # What is the maximum hunger?
 MAX_HUNGER = ACTOR_MAXHUNGER_VARIABLES[Actor_Id]


It is good practice to figure out how much of this stuff works.


Original Code to Change:
  def change_hunger(actor, amount)
   $game_party.members[actor].hunger -= amount
   if $game_party.members[actor].hunger > MAX_HUNGER
     $game_party.members[actor].hunger = MAX_HUNGER
   elsif $game_party.members[actor].hunger < 0
     $game_party.members[actor].hunger = 0
   end
 end
 
 def change_thirst(actor, amount)
   $game_party.members[actor].thirst -= amount
   if $game_party.members[actor].thirst > MAX_THIRST
     $game_party.members[actor].thirst = MAX_THIRST
   elsif $game_party.members[actor].thirst < 0
     $game_party.members[actor].thirst = 0
   end
 end


Where it says MAX_HUNGER, change that to MAX_HUNGER[actor.id] to allow each actor to have their own unique Hunger and Thirst.  When you do this, MAX_HUNGER cant be a single Value any more.  Thus, MAX_HUNGER = 2000, then calling to MAX_HUNGER[actor.id] wont work.  The script will have to be altered so you can have MAX_HUNGER = Array or Hash, but probably MAX_HUNGER = ACTOR_MAXHUNGER_VARIABLES.  That way, MAX_HUNGER has all the needed elements.  

Now, to use Game Variables instead of the Static Values, where it says MAX_HUNGER, you may want to completely change that to replace MAX_HUNGER with $game_variables[ ACTOR_MAXHUNGER_VARIABLES[actor.id] ].  Note that there are two sets of [] inside each other.  [ [] ].

Suggestion: Use PRINT and INSPECT.  Try putting Print in for various places.  "print ACTOR_MAXHUNGER_VARIABLES[actor.id]" which should always print that Actors Maximum Hunger that you set.  Then try "print MAX_HUNGER.inspect" to show the full structure of the value.  If its an Array, it will display the Array so you can read it instead of running it all together.  If it is just a single variable, it doesnt really do anything.  But to get everything working in this script, MAX_HUNGER will have to be an Array instead of the 2000 as its value.

Last Note: If you are trying to alter the Script, you may need to START A NEW GAME depending on how the script is set up.  When you LOAD A SAVED GAME, the script may be trying to use OLD SETTINGS.  So when you load the old save game, your Max Hunger could still be set to 2000 instead of an Array which sounds like what you need.  That will cause your script to not work correctly althought the logic is correct.

Dont give up.  We can help you understand how to make ANY script do what you want with enough effort.
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on October 30, 2013, 06:27:35 pm
So, this solution looks quite promising, thanks! There are a couple (probably related things) I'm running into, though:

First, it says HungerThirst::Actor_Id is uninitialized when the game starts--I take it I shouldn't be using a Parallel Process Common Event to set the actors' maximum hunger level variables (should I initialize them all at some random number, then let the parallel process correct it once the game starts?), or is that a different issue?

Also, I noticed you used Actor_Id at some parts and actor.id at others. What's the difference?
Title: Re: Script Variable Based On Game Variable
Post by: Heretic86 on October 31, 2013, 01:45:50 am
I'll try to answer in order.

First things first.  HungerThirst::Actor_ID

Reading thru that script briefly, there isnt really an actual variable called Actor_ID.  There is a constant for ACTOR_HUNGER_VARIABLES.  That constant is a Hash.  The 'Key' is a Number.  The value is associated with $game_variables.  The 'Key' being 1, 2, 3, or 4 will correspond to which actor in which position.  That way the script and the existing game code are "linked".  The way to access the data stored there should be pretty easy.

HungerThirst::ACTOR_HUNGER_VARIABLES[1]


This is where Actor.ID comes into play.  I'll try to explain the difference.

class Game_Actor
  def initialize(arg_id, arg_name, arg_hp)
    @id = arg_id
    @name = arg_name
    @hp = arg_hp
  end
  def say_hello
    print "hello"
  end
end

class Game_Party
  def initialize
    # Actors Array
    @actors = []
  end
end

$game_party.actors[0] = Game_Actor.new(arg_id = 3, arg_name = "Bob", arg_hp = 100)

Event Script:

# Temporary Variable
actor = $game_party.actors[0]

print actor.id
print actor.name
print actor.hp

You could also do the same thing by saying

print $game_party.actors[0].id

ID is a property of the Game Actors.  Just as Name and HP are also properties.  I left a LOT of necessary stuff, but basically what happens is when you see a dot . you are looking at either a Property or a Method.  A property is a Variable
like ID.  A Method is a "def method_name" like say_hello.  Methods also use periods to go from Object to Method.  $game_party.actors[0].say_hello

Inside a Method (or a "def do_something"), you can have "Temporary Variables".  Temporary Variables don't have any extra characters in front.  So they are not preceeded by $ or @ or @@.

def everyone_say_hi
  for actor in $game_party.actors
    print actor.name, " says Hello"
  end
end

There, the word actor is a Temporary variable.  So if you try to call "actor" somewhere else, it wont be there.  Using the @ character, those variables stick around.  actor.id or actor.name  It allows you to access them later.  $ are used as Globals.  Print $game_map.inspect  Globals can be called from anywhere, and are usually used to store organized Data.  $bookshelf  Globals usually have a lot of info contained inside of them.  $bookshelf.shelf[1].book[373].page[192].line[37]

You also have what we call "Arguments".  Arguments are used to get information from outside a Method to inside of a Method.

def add_numbers(arg_number_1, arg_number_2)
  #Temporary Variables from sum of two Arguments
  sum = arg_number_1 + arg_number_2
end

Arguments are useful especially when handling Temporary Variables to do reduntant complex code.

Next you have Arrays and Hashes.  They are similar but not the same.

@some_array = []
@some_array[0] = "Mouse"
@some_array[1] = "Dog"
@some_array[2] = "Cat"

Hashes use Keys, Arrays use Indexes.  Basically.

@some_hash = { 1 => "Dog", 2 => "Cat" }

Hashes and Arrays access data similarly.

print @some_array[1] or @some_hash[1] Result: "Dog"

Getting back to the issues after that monster level of training.  As you see, youre working with a Hash, so it needs a Key to access what data is where.  If you're messing around, try this

# Temporary Variable to hold the Actor's Id
actor_id = $game_party.actors[0].id
# Get the Game Variable ID from the Settings
game_variable_id = HungerThirst::ACTOR_HUNGER_VARIABLES[actor_id]
# Set the Game Variable by its ID to the Maximum Hunger Value - 2000
$game_variables[game_variable_id] = HungerThirst::MAX_HUNGER

print $game_variables[game_variable_id]

Before I get too far into this, does any of this make a damn bit of sense?
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on October 31, 2013, 02:00:40 am
Absolutely, thanks! I can't say I'd be able to use all of those in a from-scratch code, but I'm fairly sure I can at least recognize and follow them.

Except for ::, which I see you've used a few times in that sample code, what's that do?
Title: Re: Script Variable Based On Game Variable
Post by: LiTTleDRAgo on October 31, 2013, 05:23:34 am
explaining that will be troublesome so this is an example code (look at the bolded part)

Spoiler: ShowHide
Quotemodule SOMETHING

 ACTOR_MAXHUNGER_VARIABLES = {
 1 => 10,
 2 => 20,
 }

end

class Game_Actor
  def maxhunger
     # Accessing ACTOR_MAXHUNGER_VARIABLES in module Something
     maxhunger = SOMETHING::ACTOR_MAXHUNGER_VARIABLES
     # Get the variable id based on actor id
     variable_id = maxhunger[@actor_id]
     # If the variable id doesn't exist, return 0
     return 0 if variable_id == nil
     # Return the value of variable id
     return $game_variables[variable_id]
  end
end


then after that, you could use it like this

  def change_hunger(actor, amount)
    actor = $game_party.members[actor]
    actor.hunger -= amount
    if actor.hunger > actor.maxhunger
      actor.hunger = actor.maxhunger
    elsif actor.hunger < 0
      actor.hunger = 0
    end
  end





here is useful link if you want to learn syntax ruby : _http://rubymonk.com/learning/books
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on October 31, 2013, 11:26:54 pm
Annnnd eventually...
It doesn't crash! But none of the actors' hunger levels are going above 0, by script or by common event...
Not sure which part of the code I should paste for this ^-^;
Title: Re: Script Variable Based On Game Variable
Post by: Heretic86 on November 01, 2013, 04:48:29 am
Sometimes its easiest to just post the whole thing

When you do, use [SPOILER] and [CODE tag]
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on November 01, 2013, 11:37:10 am
All righty, so here's the non-crashing-but-not-really-working combination I found:
Spoiler: ShowHide
#===============================================================================
# Hunger/Thirst Factor
# By Jet10985 (Jet)
#===============================================================================
# This script will add a hunger and/or thirst factor to every actor. These
# can effect a lot of things, such as stats in battle, disabling dashing, or
# even life or death.
# This script has: 32 customization option.
#===============================================================================
# Overwritten Methods:
# None
#-------------------------------------------------------------------------------
# Aliased methods:
# Game_Actor: initialize
# Game_Character: jump, increase_steps
# Game_Player: dash?
# Scene_Battle: execute_action_attack, execute_action_skill, execute_action_item,
# execute_action_guard, execute_action_wait, execute_action_escape
# Game_Battler: item_effect, apply_state_changes, atk, def, agi, spi
# Window_Status: refresh
# Scene_Base: update
#===============================================================================

=begin

Event commands:

change_hunger(actor, amount)
change_thirst(actor, amount)

actor = the actor you want to change the stat of
amount = how much you want to change it by
These method SUBTRACT from the score, so if you want to add hunger/thirst,
use a negative number like -100.


To make an item effect hunger/thirst, put this in the item's notebox:

<hunger ##>
<thirst ##>
## = how much it will decrease hunger or thirst by.


To check hunger/thirst, you much use slightly more scripting method such as:

Equal to:
$game_party.members[actor].hunger == amount

Greater than or equal to:
$game_party.members[actor].hunger >= amount

Less than or equal to:
$game_party.members[actor].hunger <= amount

Greater than:
$game_party.members[actor].hunger > amount

Less than:
$game_party.members[actor].hunger < amount

NOTE: Just replace hunger with thirst to check for thirst.

actor = actor id you want to check hunger/thirst of.
amount = what the amount of hunger/thirst you are checking against

=end


module HungerThirst
 
  # Do you want to use the hunger factor?
  USE_HUNGER = true
 
  # Do you want to use the thirst factor?
  USE_THIRST = false
 
  # What is the maximum thirst?
  MAX_THIRST = 1000
 
  # Will the character who has a maxed out hunger/thirst die?
  DIE_ON_MAX_HUNGER_OR_THIRST = false
 
  # If the above is set to true, when the dead character is revived,
  # how much hunger/thirst will be taken away?
  REVIVED_HUNGER_LOWER = 500
  REVIVED_THIRST_LOWER = 300
 
  # How much hunger will be added for each step?
  STEP_HUNGER_ADDED = 2
 
  # How much thirst will be added for each step?
  STEP_THIRST_ADDED = 1
 
  # Do you want the player to add hunger/thirst when jumping?
  JUMP_SYSTEM_COMPATABILITY = true
 
  # How much hunger will be added for each jump?
  JUMP_HUNGER_ADDED = 2
 
  # How much thirst will be added for each jump?
  JUMP_THIRST_ADDED = 2
 
  # How much hunger do they need until they can no longer dash?
  # Note: They will not be able to dash if EITHER this or NO_DASH_THIRST is met.
  NO_DASH_HUNGER = 1000
 
  # How much thirst do they need until they can no longer dash?
  # Note: They will not be able to dash if EITHER this or NO_DASH_HUNGER is met.
  NO_DASH_THIRST = 750
 
  # Do you want hunger to effect player's stats?
  AFFECT_STATS = true
 
  # How much hunger do they need until stats are effected?
  LOWER_STATS_HUNGER = 500
 
  # How much thirst do they need until stats are effected?
  LOWER_STATS_THIRST = 400
 
  # This is what stats will be multiplied by if the character is too hungry.
  #                       ATK  DEF  SPI  AGI
  HUNGER_LOWERED_STATS = [0.8, 0.8, 0.8, 0.8]
 
  # This is what stats will be multiplied by if the charatcer is too thirsty.
  #                       ATK  DEF  SPI  AGI
  THIRST_LOWERED_STATS = [0.9, 0.9, 0.9, 0.9]
 
  # Do you want battle actions to effect hunger/thirst?
  BATTLE_ACTIONS_AFFECT = true
 
  # How much attacking will affect hunger/thirst.
  ATTACK_HUNGER_RAISE = 10
  ATTACK_THIRST_RAISE = 7
 
  # How much using a skill will affect hunger/thirst.
  SKILL_HUNGER_RAISE = 8
  SKILL_THIRST_RAISE = 6
 
  # How much guarding will affect hunger/thirst.
  GUARD_HUNGER_RAISE = 5
  GUARD_THIRST_RAISE = 4
 
  # How much using an item will affect hunger/thirst.
  ITEM_HUNGER_RAISE = 2
  ITEM_THIRST_RAISE = 1
 
  # How much trying to escape will affect hunger/thirst.
  ESCAPE_HUNGER_RAISE = 5
  ESCAPE_THIRST_RAISE = 6
 
  # How much waiting will affect hunger/thirst.
  WAIT_HUNGER_RAISE = 2
  WAIT_THIRST_RAISE = 2
 
  # Do you want each actor's hunger to be output to a variable?
  HUNGER_TO_VARIABLE = true
 
  # If the above is true, configure the hash below following the format listed.
  ACTOR_HUNGER_VARIABLES = {
 
  1 => 90,  # ACTOR_ID => VARIABLE_ID
  2 => 91,  # ACTOR_ID => VARIABLE_ID
  3 => 92,  # ACTOR_ID => VARIABLE_ID
  4 => 93  # ACTOR_ID => VARIABLE_ID
  }
 
  # Do you want each actor's thirst to be output to a variable?
  THIRST_TO_VARIABLE = true
 
  # If the above is true, configure the hash below following the format listed.
  ACTOR_MAXHUNGER_VARIABLES = {
 
  1 => 94,  # ACTOR_ID => VARIABLE_ID
  2 => 95,  # ACTOR_ID => VARIABLE_ID
  3 => 96,  # ACTOR_ID => VARIABLE_ID
  4 => 97  # ACTOR_ID => VARIABLE_ID
  }
 
 
end
 
#===============================================================================
# DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
#===============================================================================
class Game_Actor
   def maxhunger
      # Accessing ACTOR_MAXHUNGER_VARIABLES in module Something
      maxhunger = HungerThirst::ACTOR_MAXHUNGER_VARIABLES
      # Get the variable id based on actor id
      variable_id = maxhunger[@actor_id]
      # If the variable id doesn't exist, return 0
      return 0 if variable_id == nil
      # Return the value of variable id
      return $game_variables[variable_id]
    end

  attr_accessor :hunger
  attr_accessor :thirst
 
  alias jet5482_initialize initialize unless $@
  def initialize(*args)
    jet5482_initialize(*args)
    @hunger = 0
    @thirst = 0
  end
end

class Game_Interpreter
 
  include HungerThirst
 
  def change_hunger(actor, amount)
    $game_party.members[actor].hunger -= amount
    if $game_party.members[actor].hunger > $game_party.members[actor].maxhunger
      $game_party.members[actor].hunger = $game_party.members[actor].maxhunger
    elsif $game_party.members[actor].hunger < 0
      $game_party.members[actor].hunger = 0
    end
  end
 
  def change_thirst(actor, amount)
    $game_party.members[actor].thirst -= amount
    if $game_party.members[actor].thirst > $game_variables[ACTOR_MAXHUNGER_VARIABLES[actor.id]]
      $game_party.members[actor].thirst = $game_variables[ACTOR_MAXHUNGER_VARIABLES[actor.id]]
    elsif $game_party.members[actor].thirst < 0
      $game_party.members[actor].thirst = 0
    end
  end
end

module Jet
 
    def self.check_tag_number(obj, tag)
    obj.note.split(/[\r\n]+/).each { |notetag|
    case notetag
    when tag
      @result = $1.to_i
    end }
    return @result
  end
end

module RPG
  class UsableItem
   
    def lower_hunger
      if @hunger.nil?
        txt = Jet.check_tag_number(self, /<(?:hunger)[ ]*(\d+)>/i)
        @hunger = txt.nil? ? :unhunger : txt.to_i
      end
      return @hunger
    end
   
    def lower_thirst
      if @thirst.nil?
        txt = Jet.check_tag_number(self, /<(?:thirst)[ ]*(\d+)>/i)
        @thirst = txt.nil? ? :unthirst : txt.to_i
      end
      return @thirst
    end
  end
end

class Game_Character
 
  include HungerThirst
 
  if JUMP_SYSTEM_COMPATABILITY
    alias jet5903_jump jump unless $@
    def jump(*args)
      for i in 0...$game_party.members.size
        $game_party.members[i].hunger += JUMP_HUNGER_ADDED if USE_HUNGER
        $game_party.members[i].thirst += JUMP_THIRST_ADDED if USE_THIRST
        if $game_party.members[i].hunger > MAX_HUNGER
          $game_party.members[i].hunger = MAX_HUNGER
        elsif $game_party.members[i].hunger < 0
          $game_party.members[i].hunger = 0
        end
        if $game_party.members[i].thirst > MAX_THIRST
          $game_party.members[i].thirst = MAX_THIRST
        elsif $game_party.members[i].thirst < 0
          $game_party.members[i].thirst = 0
        end
      end
      jet5903_jump(*args)
    end
  end
 
  alias jet2211_increase_steps increase_steps unless $@
  def increase_steps(*args)
    if self.is_a?(Game_Player)
      for i in 0...$game_party.members.size
        $game_party.members[i].hunger += STEP_HUNGER_ADDED if USE_HUNGER
        $game_party.members[i].thirst += STEP_THIRST_ADDED if USE_THIRST
        if $game_party.members[i].hunger > $game_party.members[i].maxhunger
          $game_party.members[i].hunger = $game_party.members[i].maxhunger
        elsif $game_party.members[i].hunger < 0
          $game_party.members[i].hunger = 0
        end
        if $game_party.members[i].thirst > MAX_THIRST
          $game_party.members[i].thirst = MAX_THIRST
        elsif $game_party.members[i].thirst < 0
          $game_party.members[i].thirst = 0
        end
      end
    end
    jet2211_increase_steps(*args)
  end
end

class Game_Player
 
  include HungerThirst
 
  alias jet6901_dash? dash? unless $@
  def dash?
    for i in 0...$game_party.members.size
      if USE_HUNGER
        if $game_party.members[i].hunger >= NO_DASH_HUNGER
          return false
        end
      end
      if USE_THIRST
        if $game_party.members[i].thirst >= NO_DASH_THIRST
          return false
        end
      end
    end   
    jet6901_dash?
  end
end

class Scene_Battle
   
  include HungerThirst
 
  if BATTLE_ACTIONS_AFFECT
    alias jet0134_execute_action_attack execute_action_attack unless $@
    def execute_action_attack
      if @active_battler.actor?
        @active_battler.hunger += ATTACK_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += ATTACK_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0134_execute_action_attack
    end

    alias jet0135_execute_action_guard execute_action_guard unless $@
    def execute_action_guard
      if @active_battler.actor?
        @active_battler.hunger += GUARD_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += GUARD_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0135_execute_action_guard
    end

    alias jet0136_execute_action_escape execute_action_escape unless $@
    def execute_action_escape
      if @active_battler.actor?
        @active_battler.hunger += ESCAPE_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += ESCAPE_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0136_execute_action_escape
    end

    alias jet0137_execute_action_wait execute_action_wait unless $@
    def execute_action_wait
      if @active_battler.actor?
        @active_battler.hunger += WAIT_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += WAIT_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0137_execute_action_wait
    end

    alias jet0138_execute_action_skill execute_action_skill unless $@
    def execute_action_skill
      if @active_battler.actor?
        @active_battler.hunger += SKILL_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += SKILL_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0138_execute_action_skill
    end
   
    alias jet0139_execute_action_item execute_action_item unless $@
    def execute_action_item
      if @active_battler.actor?
        @active_battler.hunger += ITEM_HUNGER_RAISE if USE_HUNGER
        @active_battler.thirst += ITEM_THIRST_RAISE if USE_THIRST
        if @active_battler.hunger > @active_battler.maxhunger
          @active_battler.hunger = @active_battler.maxhunger
        elsif @active_battler.hunger < 0
          @active_battler.hunger = 0
        end
        if @active_battler.thirst > MAX_THIRST
          @active_battler.thirst = MAX_THIRST
        elsif @active_battler.thirst < 0
          @active_battler.thirst = 0
        end
      end
      jet0139_execute_action_item
    end
  end
end

class Game_Battler
 
  include HungerThirst
 
  alias jet5823_item_effect item_effect unless $@
  def item_effect(user, item)
    jet5823_item_effect(user, item)
    unless @skipped
      user.hunger -= item.lower_hunger unless item.lower_hunger == :unhunger
      user.thirst -= item.lower_thirst unless item.lower_thirst == :unthirst
      if user.hunger > user.maxhunger
        user.hunger = user.maxhunger
      elsif user.hunger < 0
        user.hunger = 0
      end
      if user.thirst > MAX_THIRST
        user.thirst = MAX_THIRST
      elsif user.thirst < 0
        user.thirst = 0
      end
    end
  end
 
  alias jet9243_apply_state_changes apply_state_changes unless $@
  def apply_state_changes(obj)
    if obj.minus_state_set.include?(1) && DIE_ON_MAX_HUNGER_OR_THIRST && self.actor?
      self.hunger -= REVIVED_HUNGER_LOWER
      self.thirst -= REVIVED_THIRST_LOWER
      if self.hunger > self.maxhunger
        self.hunger = self.maxhunger
      elsif self.hunger < 0
        self.hunger = 0
      end
      if self.thirst > MAX_THIRST
        self.thirst = MAX_THIRST
      elsif self.thirst < 0
        self.thirst = 0
      end
    end
    self.jet9243_apply_state_changes(obj)
  end
 
  if AFFECT_STATS
    alias jet0132_atk atk unless $@
    def atk
      n = jet0132_atk
      if self.actor?
        if self.hunger >= LOWER_STATS_HUNGER
          n *= HUNGER_LOWERED_STATS[0]
        end
        if self.thirst >= LOWER_STATS_THIRST
          n *= THIRST_LOWERED_STATS[0]
        end
      end
      return n
    end
   
    alias jet8921_def def unless $@
    def def
      n = jet8921_def
      if self.actor?
        if self.hunger >= LOWER_STATS_HUNGER
          n *= HUNGER_LOWERED_STATS[1]
        end
        if self.thirst >= LOWER_STATS_THIRST
          n *= THIRST_LOWERED_STATS[1]
        end
      end
      return n
    end

    alias jet9021_spi spi unless $@
    def spi
      n = jet9021_spi
      if self.actor?
        if self.hunger >= LOWER_STATS_HUNGER
          n *= HUNGER_LOWERED_STATS[2]
        end
        if self.thirst >= LOWER_STATS_THIRST
          n *= THIRST_LOWERED_STATS[2]
        end
      end
      return n
    end

    alias jet0213_agi agi unless $@
    def agi
      n = jet0213_agi
      if self.actor?
        if self.hunger >= LOWER_STATS_HUNGER
          n *= HUNGER_LOWERED_STATS[3]
        end
        if self.thirst >= LOWER_STATS_THIRST
          n *= THIRST_LOWERED_STATS[3]
        end
      end
      return n
    end
  end
end

class Window_Status
 
  alias jet5840_refresh refresh unless $@
  def refresh
    jet5840_refresh
    self.contents.font.color = system_color
    self.contents.draw_text(50, 310, 100, 24, "Hunger: ")
    self.contents.font.color = normal_color
    self.contents.draw_text(150, 310, 100, 24, @actor.hunger)
    self.contents.font.color = system_color
    self.contents.draw_text(50, 334, 100, 24, "Thirst: ")
    self.contents.font.color = normal_color
    self.contents.draw_text(150, 334, 100, 24, @actor.thirst)
  end
end

class Scene_Base
   
  include HungerThirst
 
  alias jet2034_update update unless $@
  def update
    jet2034_update
    unless $scene.is_a?(Scene_Title)
      for actor in $game_party.members
        next if actor.nil?
        $game_variables[ACTOR_HUNGER_VARIABLES[actor.id]] = actor.hunger unless actor.nil? || ACTOR_HUNGER_VARIABLES[actor.id].nil? || !USE_HUNGER
        #$game_variables[ACTOR_THIRST_VARIABLES[actor.id]] = actor.thirst unless actor.nil? || ACTOR_THIRST_VARIABLES[actor.id].nil? || !USE_THIRST
        if actor.hunger == actor.maxhunger && DIE_ON_MAX_HUNGER_OR_THIRST && actor.hp != nil
          actor.hp = 0
          if $game_party.all_dead?
            @window = Window_Help.new
            @window.y = 152
            @window.set_text("Your last party member has died of hunger.", 1)
            loop do
              Graphics.update
              Input.update
              if Input.trigger?(Input::C)
                @window.dispose
                $scene = Scene_Gameover.new
                break
              end
            end
          end
        elsif actor.thirst == MAX_THIRST && DIE_ON_MAX_HUNGER_OR_THIRST && actor.hp != nil
          actor.hp = 0
          if $game_party.all_dead?
            @window = Window_Help.new
            @window.y = 152
            @window.set_text("Your last party member has died of Thirst.", 1)
            loop do
              Graphics.update
              Input.update
              if Input.trigger?(Input::C)
                @window.dispose
                $scene = Scene_Gameover.new
                break
              end
            end
          end
        end
      end
    end
  end
end

Also, I was thinking of making hunger from skill usage based on the MP needed to use the skill, but if the past is any indication, I can't just plop @actor.mp -= @actor.calc_mp_cost(@skill) under the execute_action_skill method, huh?
Title: Re: Script Variable Based On Game Variable
Post by: Heretic86 on November 02, 2013, 05:25:24 pm
I can look more extensively later, but first thing I noticed that might cause the script to not crash but to also not work appears to be Notes.

QuoteTo make an item effect hunger/thirst, put this in the item's notebox:

<hunger ##>
<thirst ##>


txt = Jet.check_tag_number(self, /<(?:hunger)[ ]*(\d+)>/i)
@hunger = txt.nil? ? :unhunger : txt.to_i

def self.check_tag_number(obj, tag)
obj.note.split(/[\r\n]+/).each { |notetag|


Is this done correctly?

Don't forget you can print a pop up window to check the value of anything from within scripts.

    def self.check_tag_number(obj, tag)
    obj.note.split(/[\r\n]+/).each { |notetag|
    case notetag
    when tag
      @result = $1.to_i
    end }

    print "Results of Check Tag Number: ", $1

    return @result
Title: Re: Script Variable Based On Game Variable
Post by: LiTTleDRAgo on November 02, 2013, 07:21:14 pm
cleaned, but untested

Spoiler: ShowHide
#===============================================================================
# Hunger/Thirst Factor
# By Jet10985 (Jet)
#===============================================================================
# This script will add a hunger and/or thirst factor to every actor. These
# can effect a lot of things, such as stats in battle, disabling dashing, or
# even life or death.
# This script has: 32 customization option.
#===============================================================================
# Overwritten Methods:
# None
#-------------------------------------------------------------------------------
# Aliased methods:
# Game_Actor: initialize
# Game_Character: jump, increase_steps
# Game_Player: dash?
# Scene_Battle: execute_action_attack, execute_action_skill, execute_action_item,
# execute_action_guard, execute_action_wait, execute_action_escape
# Game_Battler: item_effect, apply_state_changes, atk, def, agi, spi
# Window_Status: refresh
# Scene_Base: update
#===============================================================================

=begin

Event commands:

change_hunger(actor, amount)
change_thirst(actor, amount)

actor = the actor you want to change the stat of
amount = how much you want to change it by
These method SUBTRACT from the score, so if you want to add hunger/thirst,
use a negative number like -100.


To make an item effect hunger/thirst, put this in the item's notebox:

<hunger ##>
<thirst ##>
## = how much it will decrease hunger or thirst by.


To check hunger/thirst, you much use slightly more scripting method such as:

Equal to:
$game_party.members[actor].hunger == amount

Greater than or equal to:
$game_party.members[actor].hunger >= amount

Less than or equal to:
$game_party.members[actor].hunger <= amount

Greater than:
$game_party.members[actor].hunger > amount

Less than:
$game_party.members[actor].hunger < amount

NOTE: Just replace hunger with thirst to check for thirst.

actor = actor id you want to check hunger/thirst of.
amount = what the amount of hunger/thirst you are checking against

=end


module HungerThirst
 
 # Do you want to use the hunger factor?
 USE_HUNGER = true
 
 # Do you want to use the thirst factor?
 USE_THIRST = false
 
 # What is the default maximum hunger?
 MAX_HUNGER = 1000
 
 # What is the default maximum thirst?
 MAX_THIRST = 1000
 
 # What is the maximum hunger?
 ACTOR_MAXHUNGER_VARIABLES = {
 
 1 => 98,  # ACTOR_ID => VARIABLE_ID
 2 => 99,  # ACTOR_ID => VARIABLE_ID
 3 => 100,  # ACTOR_ID => VARIABLE_ID
 4 => 101  # ACTOR_ID => VARIABLE_ID
 }
 
 # What is the maximum thirst?
 ACTOR_MAXTHIRST_VARIABLES = {
 
 1 => 102,  # ACTOR_ID => VARIABLE_ID
 2 => 103,  # ACTOR_ID => VARIABLE_ID
 3 => 104,  # ACTOR_ID => VARIABLE_ID
 4 => 105  # ACTOR_ID => VARIABLE_ID
 }
 
 # Will the character who has a maxed out hunger/thirst die?
 DIE_ON_MAX_HUNGER_OR_THIRST = false
 
 # If the above is set to true, when the dead character is revived,
 # how much hunger/thirst will be taken away?
 REVIVED_HUNGER_LOWER = 500
 REVIVED_THIRST_LOWER = 300
 
 # How much hunger will be added for each step?
 STEP_HUNGER_ADDED = 2
 
 # How much thirst will be added for each step?
 STEP_THIRST_ADDED = 1
 
 # Do you want the player to add hunger/thirst when jumping?
 JUMP_SYSTEM_COMPATABILITY = true
 
 # How much hunger will be added for each jump?
 JUMP_HUNGER_ADDED = 2
 
 # How much thirst will be added for each jump?
 JUMP_THIRST_ADDED = 2
 
 # How much hunger do they need until they can no longer dash?
 # Note: They will not be able to dash if EITHER this or NO_DASH_THIRST is met.
 NO_DASH_HUNGER = 1000
 
 # How much thirst do they need until they can no longer dash?
 # Note: They will not be able to dash if EITHER this or NO_DASH_HUNGER is met.
 NO_DASH_THIRST = 750
 
 # Do you want hunger to effect player's stats?
 AFFECT_STATS = true
 
 # How much hunger do they need until stats are effected?
 LOWER_STATS_HUNGER = 500
 
 # How much thirst do they need until stats are effected?
 LOWER_STATS_THIRST = 400
 
 # This is what stats will be multiplied by if the character is too hungry.
 #                       ATK  DEF  SPI  AGI
 HUNGER_LOWERED_STATS = [0.8, 0.8, 0.8, 0.8]
 
 # This is what stats will be multiplied by if the charatcer is too thirsty.
 #                       ATK  DEF  SPI  AGI
 THIRST_LOWERED_STATS = [0.9, 0.9, 0.9, 0.9]
 
 # Do you want battle actions to effect hunger/thirst?
 BATTLE_ACTIONS_AFFECT = true
 
 # How much attacking will affect hunger/thirst.
 ATTACK_HUNGER_RAISE = 10
 ATTACK_THIRST_RAISE = 7
 
 # How much using a skill will affect hunger/thirst.
 SKILL_HUNGER_RAISE = 8
 SKILL_THIRST_RAISE = 6
 
 # How much guarding will affect hunger/thirst.
 GUARD_HUNGER_RAISE = 5
 GUARD_THIRST_RAISE = 4
 
 # How much using an item will affect hunger/thirst.
 ITEM_HUNGER_RAISE = 2
 ITEM_THIRST_RAISE = 1
 
 # How much trying to escape will affect hunger/thirst.
 ESCAPE_HUNGER_RAISE = 5
 ESCAPE_THIRST_RAISE = 6
 
 # How much waiting will affect hunger/thirst.
 WAIT_HUNGER_RAISE = 2
 WAIT_THIRST_RAISE = 2
 
 # Do you want each actor's hunger to be output to a variable?
 HUNGER_TO_VARIABLE = true
 
 # If the above is true, configure the hash below following the format listed.
 ACTOR_HUNGER_VARIABLES = {
 
 1 => 90,  # ACTOR_ID => VARIABLE_ID
 2 => 91,  # ACTOR_ID => VARIABLE_ID
 3 => 92,  # ACTOR_ID => VARIABLE_ID
 4 => 93  # ACTOR_ID => VARIABLE_ID
 }
 
 # Do you want each actor's thirst to be output to a variable?
 THIRST_TO_VARIABLE = true
 
 # If the above is true, configure the hash below following the format listed.
 ACTOR_THIRST_VARIABLES = {
 
 1 => 94,  # ACTOR_ID => VARIABLE_ID
 2 => 95,  # ACTOR_ID => VARIABLE_ID
 3 => 96,  # ACTOR_ID => VARIABLE_ID
 4 => 97  # ACTOR_ID => VARIABLE_ID
 }
 
 
 
end
 
#===============================================================================
# DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
#===============================================================================
class Game_Actor
 def maxhunger
   # Accessing ACTOR_MAXHUNGER_VARIABLES in module HungerThirst
   maxhunger = HungerThirst::ACTOR_MAXHUNGER_VARIABLES
   # Get the variable id based on actor id
   variable_id = maxhunger[@actor_id]
   # If the variable id doesn't exist, return 0
   return HungerThirst::MAX_HUNGER if variable_id == nil
   # Return the value of variable id
   return $game_variables[variable_id]
 end
   
 def maxthirst
   # Accessing ACTOR_MAXHUNGER_VARIABLES in module HungerThirst
   maxthirst = HungerThirst::ACTOR_MAXTHIRST_VARIABLES
   # Get the variable id based on actor id
   variable_id = maxthirst[@actor_id]
   # If the variable id doesn't exist, return 0
   return HungerThirst::MAX_THIRST if variable_id == nil
   # Return the value of variable id
   return $game_variables[variable_id]
 end

 define_method(:hunger) { @hunger ||= 0 }
 define_method(:thirst) { @thirst ||= 0 }
 define_method(:hunger=) {|value| @hunger = [[value,0].max,maxhunger].min }
 define_method(:thirst=) {|value| @thirst = [[value,0].max,maxthirst].min }
 
end

class Game_Interpreter
 
 include HungerThirst
 
 def change_hunger(actor, amount)
   $game_party.members[actor].hunger -= amount
   #if $game_party.members[actor].hunger > $game_party.members[actor].maxhunger
   #  $game_party.members[actor].hunger = $game_party.members[actor].maxhunger
   #elsif $game_party.members[actor].hunger < 0
   #  $game_party.members[actor].hunger = 0
   #end
 end
 
 def change_thirst(actor, amount)
   $game_party.members[actor].thirst -= amount
   #if $game_party.members[actor].thirst > $game_party.members[actor].maxthirst
   #  $game_party.members[actor].thirst = $game_party.members[actor].maxthirst
   #elsif $game_party.members[actor].thirst < 0
   #  $game_party.members[actor].thirst = 0
   #end
 end
end

module Jet
 
 def self.check_tag_number(obj, tag)
   obj.note.split(/[\r\n]+/).each { |notetag|
   case notetag
   when tag
     @result = $1.to_i
   end }
   return @result
 end
end

module RPG
 class UsableItem
   
   def lower_hunger
     if @hunger.nil?
       txt = Jet.check_tag_number(self, /<(?:hunger)[ ]*(\d+)>/i)
       @hunger = txt.nil? ? :unhunger : txt.to_i
     end
     return @hunger
   end
   
   def lower_thirst
     if @thirst.nil?
       txt = Jet.check_tag_number(self, /<(?:thirst)[ ]*(\d+)>/i)
       @thirst = txt.nil? ? :unthirst : txt.to_i
     end
     return @thirst
   end
 end
end

class Game_Character
 
 include HungerThirst
 
 if JUMP_SYSTEM_COMPATABILITY
   alias jet5903_jump jump unless $@
   def jump(*args)
     for i in 0...$game_party.members.size
       $game_party.members[i].hunger += JUMP_HUNGER_ADDED if USE_HUNGER
       $game_party.members[i].thirst += JUMP_THIRST_ADDED if USE_THIRST
       #if $game_party.members[i].hunger >  $game_party.members[i].maxhunger
       #  $game_party.members[i].hunger =  $game_party.members[i].maxhunger
       #elsif $game_party.members[i].hunger < 0
       #  $game_party.members[i].hunger = 0
       #end
       #if $game_party.members[i].thirst >  $game_party.members[i].maxthirst
       #  $game_party.members[i].thirst = $game_party.members[i].maxthirst
       #elsif $game_party.members[i].thirst < 0
       #  $game_party.members[i].thirst = 0
       #end
     end
     jet5903_jump(*args)
   end
 end
 
 alias jet2211_increase_steps increase_steps unless $@
 def increase_steps(*args)
   if self.is_a?(Game_Player)
     for i in 0...$game_party.members.size
       $game_party.members[i].hunger += STEP_HUNGER_ADDED if USE_HUNGER
       $game_party.members[i].thirst += STEP_THIRST_ADDED if USE_THIRST
       #if $game_party.members[i].hunger > $game_party.members[i].maxhunger
       #  $game_party.members[i].hunger = $game_party.members[i].maxhunger
       #elsif $game_party.members[i].hunger < 0
       #  $game_party.members[i].hunger = 0
       #end
       #if $game_party.members[i].thirst > $game_party.members[i].maxthirst
       #  $game_party.members[i].thirst = $game_party.members[i].maxthirst
       #elsif $game_party.members[i].thirst < 0
       #  $game_party.members[i].thirst = 0
       #end
     end
   end
   jet2211_increase_steps(*args)
 end
end

class Game_Player
 
 include HungerThirst
 
 alias jet6901_dash? dash? unless $@
 def dash?
   for i in 0...$game_party.members.size
     if USE_HUNGER && $game_party.members[i].hunger >= NO_DASH_HUNGER
       return false
     end
     if USE_THIRST && $game_party.members[i].thirst >= NO_DASH_THIRST
       return false
     end
   end    
   jet6901_dash?
 end
end

class Scene_Battle
 
 include HungerThirst
 
 if BATTLE_ACTIONS_AFFECT
   alias jet0134_execute_action_attack execute_action_attack unless $@
   def execute_action_attack
     if @active_battler.actor?
       @active_battler.hunger += ATTACK_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += ATTACK_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0134_execute_action_attack
   end

   alias jet0135_execute_action_guard execute_action_guard unless $@
   def execute_action_guard
     if @active_battler.actor?
       @active_battler.hunger += GUARD_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += GUARD_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0135_execute_action_guard
   end

   alias jet0136_execute_action_escape execute_action_escape unless $@
   def execute_action_escape
     if @active_battler.actor?
       @active_battler.hunger += ESCAPE_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += ESCAPE_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0136_execute_action_escape
   end

   alias jet0137_execute_action_wait execute_action_wait unless $@
   def execute_action_wait
     if @active_battler.actor?
       @active_battler.hunger += WAIT_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += WAIT_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0137_execute_action_wait
   end

   alias jet0138_execute_action_skill execute_action_skill unless $@
   def execute_action_skill
     if @active_battler.actor?
       @active_battler.hunger += SKILL_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += SKILL_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0138_execute_action_skill
   end
   
   alias jet0139_execute_action_item execute_action_item unless $@
   def execute_action_item
     if @active_battler.actor?
       @active_battler.hunger += ITEM_HUNGER_RAISE if USE_HUNGER
       @active_battler.thirst += ITEM_THIRST_RAISE if USE_THIRST
       #if @active_battler.hunger > @active_battler.maxhunger
       #  @active_battler.hunger = @active_battler.maxhunger
       #elsif @active_battler.hunger < 0
       #  @active_battler.hunger = 0
       #end
       #if @active_battler.thirst > @active_battler.maxthirst
       #  @active_battler.thirst = @active_battler.maxthirst
       #elsif @active_battler.thirst < 0
       #  @active_battler.thirst = 0
       #end
     end
     jet0139_execute_action_item
   end
 end
end

class Game_Battler
 
 include HungerThirst
 
 alias jet5823_item_effect item_effect unless $@
 def item_effect(user, item)
   jet5823_item_effect(user, item)
   unless @skipped
     user.hunger -= item.lower_hunger unless item.lower_hunger == :unhunger
     user.thirst -= item.lower_thirst unless item.lower_thirst == :unthirst
     #if user.hunger > user.maxhunger
     #  user.hunger = user.maxhunger
     #elsif user.hunger < 0
     #  user.hunger = 0
     #end
     #if user.thirst > user.maxthirst
     #  user.thirst = user.maxthirst
     #elsif user.thirst < 0
     #  user.thirst = 0
     #end
   end
 end
 
 alias jet9243_apply_state_changes apply_state_changes unless $@
 def apply_state_changes(obj)
   if obj.minus_state_set.include?(1) && DIE_ON_MAX_HUNGER_OR_THIRST && self.actor?
     self.hunger -= REVIVED_HUNGER_LOWER
     self.thirst -= REVIVED_THIRST_LOWER
     #if self.hunger > self.maxhunger
     #  self.hunger = self.maxhunger
     #elsif self.hunger < 0
     #  self.hunger = 0
     #end
     #if self.thirst > self.maxthirst
     #  self.thirst = self.maxthirst
     #elsif self.thirst < 0
     #  self.thirst = 0
     #end
   end
   self.jet9243_apply_state_changes(obj)
 end
 
 if AFFECT_STATS
   alias jet0132_atk atk unless $@
   def atk
     n = jet0132_atk
     if self.actor?
       if self.hunger >= LOWER_STATS_HUNGER
         n *= HUNGER_LOWERED_STATS[0]
       end
       if self.thirst >= LOWER_STATS_THIRST
         n *= THIRST_LOWERED_STATS[0]
       end
     end
     return n
   end
   
   alias jet8921_def def unless $@
   def def
     n = jet8921_def
     if self.actor?
       if self.hunger >= LOWER_STATS_HUNGER
         n *= HUNGER_LOWERED_STATS[1]
       end
       if self.thirst >= LOWER_STATS_THIRST
         n *= THIRST_LOWERED_STATS[1]
       end
     end
     return n
   end

   alias jet9021_spi spi unless $@
   def spi
     n = jet9021_spi
     if self.actor?
       if self.hunger >= LOWER_STATS_HUNGER
         n *= HUNGER_LOWERED_STATS[2]
       end
       if self.thirst >= LOWER_STATS_THIRST
         n *= THIRST_LOWERED_STATS[2]
       end
     end
     return n
   end

   alias jet0213_agi agi unless $@
   def agi
     n = jet0213_agi
     if self.actor?
       if self.hunger >= LOWER_STATS_HUNGER
         n *= HUNGER_LOWERED_STATS[3]
       end
       if self.thirst >= LOWER_STATS_THIRST
         n *= THIRST_LOWERED_STATS[3]
       end
     end
     return n
   end
 end
end

class Window_Status
 
 alias jet5840_refresh refresh unless $@
 def refresh
   jet5840_refresh
   text = []
   HungerThirst::USE_HUNGER && (text += ["Hunger: ", @actor.hunger.to_s])
   HungerThirst::USE_THIRST && (text += ["Thirst: " , @actor.thirst.to_s])
   self.contents.font.color = system_color
   self.contents.draw_text(50, 310, 100, 24, "#{text[0]}")
   self.contents.draw_text(50, 334, 100, 24, "#{text[2]}")
   self.contents.font.color = normal_color
   self.contents.draw_text(150, 310, 100, 24, "#{text[1]}")
   self.contents.draw_text(150, 334, 100, 24, "#{text[3]}")
 end
end

class Scene_Base
   
 include HungerThirst
 
 alias jet2034_update update unless $@
 def update
   jet2034_update
   unless $scene.is_a?(Scene_Title)
     for actor in $game_party.members
       next if actor.nil?
       USE_HUNGER && HUNGER_TO_VARIABLE && (id = ACTOR_HUNGER_VARIABLES[actor.id]) &&
       ($game_variables[id] = actor.hunger)
       USE_THIRST && THIRST_TO_VARIABLE && (id = ACTOR_THIRST_VARIABLES[actor.id]) &&
       ($game_variables[id] = actor.thirst)
       if USE_HUNGER && actor.hunger == actor.maxhunger && DIE_ON_MAX_HUNGER_OR_THIRST
         actor.hp = 0
         if $game_party.all_dead?
           @window = Window_Help.new
           @window.y = 152
           @window.set_text("Your last party member has died of hunger.", 1)
           loop do
             Graphics.update
             Input.update
             if Input.trigger?(Input::C)
               @window.dispose
               $scene = Scene_Gameover.new
               break
             end
           end
         end
       elsif USE_THIRST && actor.thirst == actor.maxthirst && DIE_ON_MAX_HUNGER_OR_THIRST
         actor.hp = 0
         if $game_party.all_dead?
           @window = Window_Help.new
           @window.y = 152
           @window.set_text("Your last party member has died of Thirst.", 1)
           loop do
             Graphics.update
             Input.update
             if Input.trigger?(Input::C)
               @window.dispose
               $scene = Scene_Gameover.new
               break
             end
           end
         end
       end
     end
   end
 end
end


you can delete the comments if the script is tested and work perfectly

Quote from: Untitled on October 30, 2013, 03:51:14 pm.....but instead of having a Thirst system, I want each actor's maximum hunger to be different. I have these set to variables that I want to refer to with this modified little thing


you probably forget to change each maxhunger variable to something greater than 0
Title: Re: Script Variable Based On Game Variable
Post by: Untitled on November 03, 2013, 10:37:48 pm
Oh hey, I totally forgot VX had Notes. I was actually testing hunger by running around, which didn't increase hunger levels, but I just tried attaching <Hunger 10> to a potion, and it didn't do anything, either.

So it could be an issue of the actors' maxhungers being stuck at zero, if this doesn't work?
(http://gyazo.com/005d8fa87ff86a53338765d480a5ee16.png)
I can only assume the switch is on, because I flipped it in an autorun event that also gives you potions, and you still get the potions.