- 20
- Posts
- 6
- Years
- Seen Sep 4, 2024
Sorry if this is a silly question, I'm still really new to all this and don't really understand the language ruby yet, so I was wondering if it's possible to implement features from another toolkit into Pokemon Essentials?
I want to add a relationship system from a Harvest Moon Toolkit I found, but just straight up copying it only returns an error when I try to use it in game. I'd ask the creator of the toolkit if this is possible, but from what I can tell they're not around anymore. If anyone could help me I'd be very grateful!
This is the code from the HM Toolkit I want to use, this first one is under Object Classes above Main:
And this next one is in Data Modules above Main:
I want to add a relationship system from a Harvest Moon Toolkit I found, but just straight up copying it only returns an error when I try to use it in game. I'd ask the creator of the toolkit if this is possible, but from what I can tell they're not around anymore. If anyone could help me I'd be very grateful!
This is the code from the HM Toolkit I want to use, this first one is under Object Classes above Main:
Code:
class Villager
attr_reader :id
attr_reader :name
attr_reader :affection
attr_reader :age
attr_accessor :talk_count
def initialize(id)
@id=id
@name=Villagers::Names[0][id][0]
@affection=0
@age=0#temporary
@talk_count=0
@first_encounter=true
@engaged=false
@married=false
@item_given=false
end
def interact
begin
affection_level=get_affection_level
if !$game_player.held_item || Kernel.is_tool?($game_player.held_item)
#if meeting the villager for the first time
if @first_encounter
message=Villagers::Messages[0][@id][0].clone
else
#clone target text so nothing mistakenly happens to it
message=Villagers::Messages[0][@id][affection_level][$world.season][@talk_count].clone
end
$game_temp.face_graphic=@name
#only displays a heart when speaking to an eligible bachelor/bachelorette
if $game_player.is_male?
if Villagers::Bachelorettes.include?(id)
$game_temp.message_heart=affection_level
end
else
if Villagers::Bachelors.include?(id)
$game_temp.message_heart=affection_level
end
end
Kernel.show_text(message)
#if player just met this NPC, set first encounter flag to false
if @first_encounter
@first_encounter=false
@affection+=Villagers::Affection_Rates[0][@id]
#count up # of times player talked to this NPC
else
#only gain affection from talking once
if @talk_count < 1
#if current affection is less than maximum affection for this villager
if @affection < Villagers::Affection_Levels[0][@id].last.last
@affection += Villagers::Affection_Rates[0][@id]
end
end
if @talk_count < Villagers::Messages[0][@id][affection_level][$world.season].length - 1
@talk_count+=1
end
end
else
give($game_player.held_item.id)
end
rescue
Kernel.show_text("Message data missing.\nAdd some to Villagers::Messages.")
end
end
def get_affection_level
Villagers::Affection_Levels[0][@id].each do |level|
if @affection.between?(level.first, level.last)
return Villagers::Affection_Levels[0][@id].index(level) + 1
end
end
end
def give(item_id)
preference=-1
for i in 0...Villagers::Preferences[0][@id].length
for k in 0...Villagers::Preferences[0][@id][i].length
if Villagers::Preferences[0][@id][i][k]==item_id
preference=i
break
end
end
end
if !@item_given
case preference
when 0
@affection-=5
when 1
@affection-=2
when 2
@affection+=2
when 3
@affection+=5
end
@item_given=true
end
#enforce value range of affection (prevents text bug)
if @affection<0
@affection=0
elsif @affection > Villagers::Affection_Levels[0][@id].last.last
@affection=Villagers::Affection_Levels[0][@id].last.last
end
$game_player.held_item=nil
$game_temp.face_graphic=@name#change this based on reaction
Kernel.show_text(Villagers::Reactions[0][@id][preference+1].clone)
$game_player.restore_graphic
$game_player.update_held_item
end
def propose
end
def reset
@talk_count=0
@item_given=false
end
#note: might make villager age
#def mature
# #might use this to simulate aging of the villagers as time goes by.
#end
end
And this next one is in Data Modules above Main:
Code:
module Villagers
Names=
[
0 => ["Ann"],
1 => ["Ellen"],
2 => ["Eve"],
3 => ["Maria"],
4 => ["Nina"],
5 => ["Mayor"]
]
#Ids of female marriage candidates (must match up with Names array above)
Bachelorettes=[0, 1, 2, 3, 4]
#Ids of male marriage candidates
Bachelors=[]
#specifies the affection points for each affection level per villager
#for bachelors/bachelorettes, this corresponds to hearts.
Affection_Levels=
[
0 => [0..51, 52..103, 104..155, 156..207, 208..255],
1 => [0..51, 52..103, 104..155, 156..207, 208..255],
2 => [0..51, 52..103, 104..155, 156..207, 208..255],
3 => [0..51, 52..103, 104..155, 156..207, 208..255],
4 => [0..51, 52..103, 104..155, 156..207, 208..255],
5 => [0..51, 52..103, 104..155, 156..207, 208..255]
]
#specifies how much affection a villager gains when you interact with them.
#bachelors/bachelorettes are typically slower to gain affection. This provides
#enough flexibility to give any and every villager a different rate if desired.
#This can make some bachelors/bachelorettes "easier" or "harder."
Affection_Rates=
[
0 => 1,
1 => 1,
2 => 1,
3 => 1,
4 => 1,
5 => 3
]
#messages should be cycled through until the last one is reached. when
#reached, display the corresponding ending only
Messages=
[
#villager 0
0 => [
"First acquaintance message",
[
[
"lvl 1 affection message spring",
"lvl 1 affection message 2 spring",
"lvl 1 affection ending spring"
],
[
"lvl 1 affection message summer",
"lvl 1 affection message 2 summer",
"lvl 1 affection ending summer"
],
[
"lvl 1 affection message fall",
"lvl 1 affection message 2 fall",
"lvl 1 affection ending fall"
],
[
"lvl 1 affection message winter",
"lvl 1 affection message 2 winter",
"lvl 1 affection ending winter"
]
],
[
[
"lvl 2 affection message spring",
"lvl 2 affection message 2 spring",
"lvl 2 affection ending spring"
],
[
"lvl 2 affection message summer",
"lvl 2 affection message 2 summer",
"lvl 2 affection ending summer"
]
]
],
#villager 1
1 => [
"First acquaintance message",
[
[
"lvl 1 affection message spring",
"lvl 1 affection message 2 spring",
"lvl 1 affection ending spring"
],
[
"lvl 1 affection message summer",
"lvl 1 affection message 2 summer",
"lvl 1 affection ending summer"
],
[
"lvl 1 affection message fall",
"lvl 1 affection message 2 fall",
"lvl 1 affection ending fall"
],
[
"lvl 1 affection message winter",
"lvl 1 affection message 2 winter",
"lvl 1 affection ending winter"
]
],
[
[
"lvl 2 affection message spring",
"lvl 2 affection message 2 spring",
"lvl 2 affection ending spring"
],
[
"lvl 2 affection message summer",
"lvl 2 affection message 2 summer",
"lvl 2 affection ending summer"
]
]
],
]
Reactions=
[
0 => [
"neutral",
"hates item",
"dislikes item",
"likes item",
"loves item"
],
1 => [
"neutral",
"hates item",
"dislikes item",
"likes item",
"loves item"
]
]
Preferences=
[
#entries match the entres in Reactions. stores arrays of item ids in this
#order: hated items, disliked items, liked items, loved items
0 => [
[1],
[],
[0],
[]
],
1 => [
[],
[0],
[],
[1]
]
]
end
Last edited by a moderator: