Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Ryex on December 30, 2008, 12:48:17 pm

Title: [Resolved]Writing status effects and elements for armor
Post by: Ryex on December 30, 2008, 12:48:17 pm
I'm doing an Equip menu for my new CMS and I can't figure out how to create a text string that contain all the elements, or status effects that a piece of armor protects from. I got it to work for Weapons as you can see below but every time I try to create it for armor it returns a empty string. any Idea what I'm doing wrong?


#-------------------------------------------------------------------------
  # * Makes the text for the elements
  #-------------------------------------------------------------------------
  def make_elem_text_equip(item)
    text = ''
    flag = false
    if item.is_a?(RPG::Weapon)
      for i in item.element_set
        if flag
          text += ', '
        end
        text += $data_system.elements[i]
        flag = true
      end
    end
    if item.is_a?(RPG::Armor)
      item.guard_element_set.each_index {|i|
        if flag
          text += ', '
        end
        text += $data_system.elements[item.guard_element_set[i]]
        flag = true
      }
    end
    return text
  end
  #-------------------------------------------------------------------------
  # * Makes the text for the status effects
  #-------------------------------------------------------------------------
  def make_stat_text_equip(item)
    text = ''
    flag = false
    if item.is_a?(RPG::Weapon)
      for i in item.plus_state_set
        if flag
          text += ', '
        end
        text += $data_states[i].name
        flag = true
      end
    end
    if item.is_a?(RPG::Armor)
      item.guard_state_set.each_index {|i|
        if flag
          text += ', '
        end
        text += $data_states[item.guard_state_set[i]].name
        flag = true
      }
    end
    return text
  end


Title: Re: Writing status effects and elements for armor
Post by: Fantasist on December 31, 2008, 04:25:53 am
Why don't you use the same iterator for armors just as weapons? Like
item.guard_element_set.each {|element_id| <code>}

Instead of what you're using:
item.guard_element_set.each_index {|index| <code>}
Title: Re: Writing status effects and elements for armor
Post by: Blizzard on December 31, 2008, 07:04:35 am
Basically like this:


string = ''
if x.element_set_array.size > 0
  string += $data_system.elements[x.element_set_array[0]]
  (1..x.element_set_array.size).each {|i|
    string += ', ' + $data_system.elements[x.element_set_array[i]]
  }
end


I would actually suggest that you make a method that does that. You simply pass on the element ID array and the elements array.

class Array
 
  def split(delimiter, elements)
    string = ''
    if self.size > 0
      begin
        string += elements[self[0]].name
        (1..self.size).each {|i|
          string += delimiter + elements[self[i]].name
        }
      rescue
        string += elements[self[0]].to_s
        (1..self.size).each {|i|
          string += delimiter + elements[self[i]].to_s
        }
      end
    end
    return string
  end

end


i.e. A call for weapon elements would be: "string = weapon.element_set.split(', ', $data_system.elements)".
Or a call for armor guard states would be: "string = armor.guard_state_set.split(', ', $data_states)".
You could use this method for others things as well. I just remembered that this method is called "explode" in PHP. xD
Title: Re: Writing status effects and elements for armor
Post by: Ryex on December 31, 2008, 11:40:53 am
Thanks people!

Edit: @Blizz I tried you method. but when I call it I still get a "no implicit conversion from nil to integer"
error this is the same problem I was getting before.

EDIT:
Ok fixed that problem but I still get an empty string if I trying to draw an armor's stuff witch is really weird because there is no difference in the two arrays

EDIT: Ok this is just stupid the whole problem is that I for got to add the lines that PRINTED the text if it was an armor *Slaps Face* I'm an IDIOT!! I sorry for wasting your time guys