Main Menu
  • Welcome to The RPG Maker Resource Kit.

[RMXP] Trying to show item in status window for player only.

Started by SmileyFaceOfRom, December 02, 2011, 05:31:49 PM

0 Members and 1 Guest are viewing this topic.

SmileyFaceOfRom

I'm using RMXP 1.02a
What i'm TRYING to do is have the player's race show beneath his sprite when he checks his status in the menu.


if $game_variables [1] == 0
          self.contents.draw_text (0, 124, 100, 32, "Human")
else $game_variables [1] == 1
          self.contents.draw_text (0, 124, 100, 32, "Dwarf")
end


The code I made above shows up. The problem is, it shows the same variable for ALL party members. I attempted to change the code like so:


if $actor_id == 1
        if $game_variables [1] == 0
          self.contents.draw_text (0, 124, 100, 32, "Human")
        else $game_variables [1] == 1
          self.contents.draw_text (0, 124, 100, 32, "Dwarf")
        end
else
end


However, now none of it shows! Any help or advice is GREATLY appreciated, as while i'm quite good at Eventing... I suck at scripting.

LoganF

#1
The second code will likely fail (it will enter 'else')because $actor_id doesn't exist as a variable so it's value is nil by default (any variable yet to be assigned a value assumes the nil value when it is first referenced).

Try changing it to @actor_id instead.

Although, it depends entirely on where this code lives.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

SmileyFaceOfRom

By 'live' I assume you mean where and in which script it is. It's at the very bottom of 'def refresh' in the
Window_Status < Window_Base
class. I tried what you said, and it still didn't work. I'm wondering if it's not working because if @actor_id == 1 wasn't assigned. Basically, like you said, it isn't there for actor_id to find. I guess what I need to do it figure out some way to determine whether actor 1 is currently active... any suggestions?

modern algebra

@actor.id then.


      if @actor.id == 1
        if $game_variables[1] == 0
          self.contents.draw_text (0, 124, 100, 32, "Human")
        else $game_variables[1] == 1
          self.contents.draw_text (0, 124, 100, 32, "Dwarf")
        end
      else
      end


Mind you, a better way to do this would be case branches and simply assigning the text to a variable, then drawing that. Also, it is not good practice to directly modify the default scripts, so it would be better to put it in a new slot and simply use aliasing. But the above should do that for which you are asking.

SmileyFaceOfRom

My issue isn't showing the variable, I can do that easily enough. My problem is showing it for specifically one character when I have others in my party.

Say Bob here is human.  :D

And Joe here is a dwarf. >:(

I want their status to say human for Bob, and dwarf for Joe.

@modern algebra
actor_id would work, except its always nil because its not set to anything else when the player is selected. I'm not really sure how to do this.
Again, any help is greatly appreciated! Thank you!

modern algebra


LoganF

I probably should have noted I was writing my post blind.

Because I had no idea where this code was being written, it's was impossible for me to know if I was inside the Game_Actor class - in which case @actor_id would work - or somewhere else - in which case I need to access the right property from the right object; where @actor.id is what would work.


module LFQF
 
  ACTORRACE = { #Do Not Remove
  #Actor ID => Race of this actor in quotes
    0 => "Human", #default in cases where actor is not specified
   1 => "Human",
    2 => "Fairy",
    3 => "Elf",
    4 => "Dwarf",
  } #Do Not Remove
   
end
 

class Window_Status < Window_Base

  alias :lfqf_refresh_af3k :refresh
  def refresh(*args)
    #run original
    lfqf_refresh_af3k(*args)
    #do extra
    race = LFQF::ACTORRACE[0] #set variable as default race
    if LFQF::ACTORRACE.include?(@actor.id)
      #change race only if actor id is included in LFQF::ACTORRACE
      race = LFQF::ACTORRACE[@actor.id]
    end
    self.contents.draw_text (0, 124, 100, 32, race)
  end
 
end


Just copy/paste this into an empty slot above Main (and below Scene_Debug) where other custom scripts live.

That little bit of code will do the trick, as well as use a default value should an actor not be given a specific race. You may want to change this line:


self.contents.draw_text (0, 124, 100, 32, race) #line 27 in the editor


to draw the text in the correct place. You may also want to add a draw_text line to write "Race" as a label too. Do feel free to make those changes, or whatever changes you see fit.

It also gets rid of the need to use $game_variables which I think is part, if not all, of the reasons why you got problems in the first place.

I could have made it less repetitive (not having to set Human more than once) but considering it'll only take a minute to set up for all your actors - unless you have a lot of actors where it might take 5 minutes - I didn't figure it too much of a hassle. It can be done though if preferred.

Also, if there's a possibility of an actor changing their race, I will have to make changes to the code - having race actually part of the actor class would make this easier to do.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

SmileyFaceOfRom

Genius! I tried what you suggested Logan and it worked! Displayed for each character differently, however I do need to change race in the game, hence my earlier approach with a variable.

@modern algebra: My apologies, I must've forgotten the @ symbol  :)

SmileyFaceOfRom

Doe's anyone have any ideas on how to make the race change? Can i simply add a variable (defined before the class) that changes what is displayed? And how would I go about doing so?