New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance items and checking for equipped items in event conditional branches #118

Open
HimeWorks opened this Issue Feb 3, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@HimeWorks
Member

HimeWorks commented Feb 3, 2014

The way the event editor checks whether you have a particular weapon or armor equipped or not is defined as follows

result = (actor.weapons.include?($data_weapons[x]))

result = (actor.armors.include?($data_armors[x]))

A quick solution to this would be to simply change what it means for two weapons to be equal. That is, we re-define == to say that two instances are equal if they have the same template.

I am not sure if that would make sense though: two hand axes are definitely not the same thing.

A more proper way to check this would be to define a new method that explicitly compares the template ID's of two objects.

@HimeWorks

This comment has been minimized.

Show comment
Hide comment
@HimeWorks

HimeWorks Feb 3, 2014

Member

For example, adding something like this to your scripts

class Game_Actor
  def template_include?(arr, id)
    arr.any? {|obj| obj.template_id == id }
  end
end

And then using scripted conditional branches as follows

a = $game_actors[1]; a.template_include?(a.weapons, 1)

If you want to know whether actor 1 is using an instance of weapon 1.

Alternatively, if that seems too general, maybe something like

class Game_Actor
  def weapons_include?(id)
    weapons.any? {|obj| obj.template_id == id } 
  end

  def armors_include?(id)
    armors.any? {|obj| obj.template_id == id } 
  end
end

Then the above condition would be written as

$game_actors[1].weapons_include?(1)
Member

HimeWorks commented Feb 3, 2014

For example, adding something like this to your scripts

class Game_Actor
  def template_include?(arr, id)
    arr.any? {|obj| obj.template_id == id }
  end
end

And then using scripted conditional branches as follows

a = $game_actors[1]; a.template_include?(a.weapons, 1)

If you want to know whether actor 1 is using an instance of weapon 1.

Alternatively, if that seems too general, maybe something like

class Game_Actor
  def weapons_include?(id)
    weapons.any? {|obj| obj.template_id == id } 
  end

  def armors_include?(id)
    armors.any? {|obj| obj.template_id == id } 
  end
end

Then the above condition would be written as

$game_actors[1].weapons_include?(1)
@Roguedeus

This comment has been minimized.

Show comment
Hide comment
@Roguedeus

Roguedeus Feb 3, 2014

Ruby syntax still amazes me. If/When I ever get back into C#, I may feel spoiled.

Just to make sure...

This:

    weapons.any? {|obj| obj.template_id == id } 

Is equivilant to:

if !weapons.empty?
    weapons.each do |obj|
        return true if obj.template_id == id
    end
end

Roguedeus commented Feb 3, 2014

Ruby syntax still amazes me. If/When I ever get back into C#, I may feel spoiled.

Just to make sure...

This:

    weapons.any? {|obj| obj.template_id == id } 

Is equivilant to:

if !weapons.empty?
    weapons.each do |obj|
        return true if obj.template_id == id
    end
end
@HimeWorks

This comment has been minimized.

Show comment
Hide comment
@HimeWorks

HimeWorks Feb 3, 2014

Member

If you mean equivalent in logic then yes, excluding that initial check for non-empty since looping over an empty array will not do anything with the block.

weapons.each do |obj|
    return true if obj.template_id == id
end
return false
Member

HimeWorks commented Feb 3, 2014

If you mean equivalent in logic then yes, excluding that initial check for non-empty since looping over an empty array will not do anything with the block.

weapons.each do |obj|
    return true if obj.template_id == id
end
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment