Advertiser Content
Male
Seen 15 Hours Ago
Posted 1 Day Ago
134 posts
150 Days
Hey guys,

I've been working on Marin's easy quest script and added some nice modifications. I think the weakness of his systemeven though it is amazing) is that each quest doesn't have an intern progression system. So, I transformed the descriptions in goals and added a variable linked to these goals, so that when one of the goals is accomplished it changes color in the in game description of the quest. Also I added that when all goals are achieved the quest is completed without the need to call the usual function to switch complete to true.

I want to improve this more but first I would like to change the variables goal1, goal2... into one array goal and do the same for goal1done, goal2done variables. What would it take to do so?

here is how it looks now after my changes
class Quest
  attr_accessor :id
  attr_accessor :name
  attr_accessor :goal1
  
  attr_accessor :goal1done
  attr_accessor :goal2
  attr_accessor :goal2done
  attr_accessor :goal3
  attr_accessor :goal3done
  attr_accessor :goal4
  attr_accessor :goal4done
  attr_accessor :npc
  attr_accessor :sprite
  attr_accessor :location
  attr_accessor :color
  attr_accessor :time
  attr_accessor :completed
  def initialize(id, name,goal1,goal1done,goal2,goal2done,goal3,goal3done,goal4,goal4done, npc, sprite, location, color = :WHITE, time = Time.now, completed = false)
    self.id = id
    self.name = name
    self.goal1 = goal1
    self.goal1done = goal1done
    self.goal2 = goal2
    self.goal2done = goal2done
    self.goal3 = goal3
    self.goal3done = goal3done
    self.goal4 = goal4
    self.goal4done = goal4done
    self.npc = npc
    self.sprite = sprite
    self.location = location
    self.color = pbColor(color)
    self.time = time
    self.completed = completed
  end
end
and this what I added

def pbSetGoal(id,goalnum,value)
   $Trainer.quests = [] if $Trainer.quests.class == NilClass
  for q in $Trainer.quests
    q.goal1done = value if goalnum ==1 && q.id == id
    q.goal2done = value if goalnum ==2 && q.id == id
    q.goal3done = value if goalnum ==3 && q.id == id
    q.goal4done = value if goalnum ==4 && q.id == id
  end
  for q in $Trainer.quests
    q.completed = true if q.id == id && q.goal1done==true&&q.goal2done==true&&q.goal3done==true&&q.goal4done==true
  end
 end

mgriffin

Seen 1 Hour Ago
Posted 14 Hours Ago
700 posts
5.5 Years
I imagine you'd end up with something roughly like:
# TODO: What *is* the thing in goal1, goal2, etc? I've called it id here, but it's just a guess.
Goal = Struct.new :id, :done

class Quest
  attr_accessor :id
  attr_accessor :name
  attr_accessor :goals
  attr_accessor :npc
  attr_accessor :sprite
  attr_accessor :location
  attr_accessor :color
  attr_accessor :time
  attr_accessor :completed
  def initialize(id, name,goal1,goal1done,goal2,goal2done,goal3,goal3done,goal4,goal4done, npc, sprite, location, color = :WHITE, time = Time.now, completed = false)
    self.id = id
    self.name = name
    # TODO: Make this more sensible. You'd probably want to pass a list of Goal objects in.
    self.goals = [
      Goal.new(goal1, goal1done),
      Goal.new(goal2, goal2done),
      Goal.new(goal3, goal3done),
      Goal.new(goal4, goal4done)
    ]
    self.npc = npc
    self.sprite = sprite
    self.location = location
    self.color = pbColor(color)
    self.time = time
    self.completed = completed
  end
end

def pbSetGoal(id,goalnum,value)
  $Trainer.quests = [] if $Trainer.quests.class == NilClass
  for q in $Trainer.quests
    q.goals[goalnum].done = value if q.id == id
  end
  for q in $Trainer.quests
    q.completed = true if q.id == id && q.goals.all? {|g| g.done}
  end
 end
Advertiser Content