Skrypt głodu - tylko jeden bohater - aron155 - 27-08-13 05:24
Witam.
Przerobiłem skrypt głodu i pragnienia tak, że jest tylko opcja pragnienia (póki co działa więc zmiana wyszła pozytywnie :D ). Problem w tym, że w drużynie jest 4 bohaterów a skrypt ma dotyczyć tylko jednego bohatera. Jak to zrobić? Czym zastąpić ,,actor" w skrypcie? Przepraszam za brak tabulatur, ale kod miałem zapisany w notatniku.
Kod:
#===============================================================================
# Hunger/Thirst Factor
# By Jet10985 (Jet)
#===============================================================================
# This script will add a hunger and/or thirst factor to every actor. These
# can effect a lot of things, such as stats in battle, disabling dashing, or
# even life or death.
# This script has: 32 customization option.
#===============================================================================
# Overwritten Methods:
# None
#-------------------------------------------------------------------------------
# Aliased methods:
# Game_actor: initialize
# Game_Character: jump, increase_steps
# Game_Player: dash?
# Scene_Battle: execute_action_attack, execute_action_skill, execute_action_item,
# execute_action_guard, execute_action_wait, execute_action_escape
# Game_Battler: item_effect, apply_state_changes, atk, def, agi, spi
# Window_Status: refresh
# Scene_Base: update
#===============================================================================
=begin
Komendy do wstawienia w zdarzeniach:
change_hunger(actor, amount)
change_thirst(actor, amount)
actor = członek drużyny, któremu chcecie zmienić daną wartość
amount = o ile chcecie ją zmienić
Ta metoda ODEJMUJE od paska głodu/pragnienia. Jeśli chcecie DODAĆ wprowadźcie wartość ujemną (np. -100)
Aby sprawić, że dany przedmiot redukuje głód/pragnienie wprowadźcie w notatkach co następuje:
<hunger ##>
<thirst ##>
## = o ile chcecie zmniajszyć głód/pragnienie.
To check hunger/thirst, you much use slightly more scripting method such as:
(Aby sprawdzić głód/pragnienie musisz użyć nieco więcej skryptów takich jak:)
Równe:
$game_party.members[actor].hunger == amount
Większe lub równe:
$game_party.members[actor].hunger >= amount
Mniejsze lub równe:
$game_party.members[actor].hunger <= amount
Większe:
$game_party.members[actor].hunger > amount
Mniejsze:
$game_party.members[actor].hunger < amount
UWAGA: Aby sprawdzić pragnienie po prostu zamień "hunger" na "thirst".
actor = ID aktora, któremu chcece sprawdzić głód/pragnienie.
amount = z jaką ilością głodu/pragnienia chcesz porównywać
=end
module HungerThirst
# Chcesz używać współczynnika głodu?
USE_HUNGER = false
# Chcesz używać współczynnika pragnienia?
USE_THIRST = true
# Jaki jest maksymalny głód?
MAX_HUNGER = 200
# Jakie jest maksymalne pragnienie?
MAX_THIRST = 1000
# Czy postać, której głód/pragnienie przekroczy maksa umiera?
DIE_ON_MAX_HUNGER_OR_THIRST = false
# If the above is set to true, when the dead character is revived
# (jeśli powyższe jest true, to kiedy martwa postać zmartwychwstanie,)
# how much hunger/thirst will be taken away?
# (Ile głodu/pragnienia będzie ujęte?)
REVIVED_HUNGER_LOWER = 500
REVIVED_THIRST_LOWER = 300
# Ile głodu będzie dodawane co krok?
STEP_HUNGER_ADDED = 50
# Ile pragnienia będzie dodawane co krok?
STEP_THIRST_ADDED = 1
# Czy dodawać graczowi pragnienie/głód gdy skacze?
JUMP_SYSTEM_COMPATABILITY = true
# Ile głodu dodawać co skok?
JUMP_HUNGER_ADDED = 2
# Ile pragnienia dodawać co skok?
JUMP_THIRST_ADDED = 2
# Ile musi wynosić głód, by postać nie mogła biegać?
# Uwaga: I tak nie będą w stanie biegać, jeśli wyłączyłeś tę opcję.
NO_DASH_HUNGER = 1000
# Jak wyżej, tyle, ze dla pragnienia.
NO_DASH_THIRST = 500
# Czy chcesz, by pragnienie/głód zmniejszał statystyki?
AFFECT_STATS = true
# Ile musi wynosić głód, by spadały statystyki?
LOWER_STATS_HUNGER = 500
# Ile musi wynosić pragnienie, by spadały statystyki?
LOWER_STATS_THIRST = 30
# Mnożnik statystyk, jeśli postać jest zbyt głodna.
# ATK DEF SPI AGI
HUNGER_LOWERED_STATS = [0.8, 0.8, 0.8, 0.8]
# Mnożnik statystyk, jeśli jest zbyt spragniona.
# ATK DEF SPI AGI
THIRST_LOWERED_STATS = [0.7, 0.7, 0.7, 0.7]
# Czy chcesz by walka podnosiła poziom głodu/pragnienia?
BATTLE_ACTIONS_AFFECT = false
# O ile wzrasta głód/pragnienie podczas ataku.
ATTACK_HUNGER_RAISE = 10
ATTACK_THIRST_RAISE = 7
# O ile wzrasta głód/pragnienie przy użyciu umiejętności.
SKILL_HUNGER_RAISE = 8
SKILL_THIRST_RAISE = 6
# O ile wzrasta przy obronie.
GUARD_HUNGER_RAISE = 5
GUARD_THIRST_RAISE = 4
# How much using an item will affect hunger/thirst.
ITEM_HUNGER_RAISE = 2
ITEM_THIRST_RAISE = 1
# I o ile wzrasta przy próbie ucieczki.
ESCAPE_HUNGER_RAISE = 5
ESCAPE_THIRST_RAISE = 6
# A także o ile wzrasta przy czekaniu.
WAIT_HUNGER_RAISE = 2
WAIT_THIRST_RAISE = 2
end
#===============================================================================
# NIE EDYTUJ PONIŻEJ, CHYBA, ZE WIESZ, CO ROBISZ.
#===============================================================================
class Game_actor
attr_accessor :thirst
alias jet5482_initialize initialize unless $@
def initialize(*args)
jet5482_initialize(*args)
@thirst = 0
end
end
class Game_Interpreter
include HungerThirst
def change_thirst(actor, amount)
$game_party.members[actor].thirst -= amount
if $game_party.members[actor].thirst > MAX_THIRST
$game_party.members[actor].thirst = MAX_THIRST
elsif $game_party.members[actor].thirst < 0
$game_party.members[actor].thirst = 0
end
end
end
module Jet
def self.check_tag_number(obj, tag)
obj.note.split(/[\r\n]+/).each { |notetag|
case notetag
when tag
@result = $1.to_i
end }
return @result
end
end
module RPG
class UsableItem
def lower_thirst
if @thirst.nil?
txt = Jet.check_tag_number(self, /<(?:thirst)[ ]*(\d+)>/i)
@thirst = txt.nil? ? :unthirst : txt.to_i
end
return @thirst
end
end
end
class Game_Character
include HungerThirst
if JUMP_SYSTEM_COMPATABILITY
alias jet5903_jump jump unless $@
def jump(*args)
for i in 0...$game_party.members.size
$game_party.members[i].thirst += JUMP_THIRST_ADDED if USE_THIRST
if $game_party.members[i].thirst > MAX_THIRST
$game_party.members[i].thirst = MAX_THIRST
elsif $game_party.members[i].thirst < 0
$game_party.members[i].thirst = 0
end
end
jet5903_jump(*args)
end
end
alias jet2211_increase_steps increase_steps unless $@
def increase_steps(*args)
for i in 0...$game_party.members.size
$game_party.members[i].thirst += STEP_THIRST_ADDED if USE_THIRST
if $game_party.members[i].thirst > MAX_THIRST
$game_party.members[i].thirst = MAX_THIRST
elsif $game_party.members[i].thirst < 0
$game_party.members[i].thirst = 0
end
end
jet2211_increase_steps(*args)
end
end
class Game_Player
include HungerThirst
alias jet6901_dash? dash? unless $@
def dash?
for i in 0...$game_party.members.size
if USE_THIRST
if $game_party.members[i].thirst >= NO_DASH_THIRST
return false
end
end
end
jet6901_dash?
end
end
class Scene_Battle
include HungerThirst
if BATTLE_ACTIONS_AFFECT
alias jet0134_execute_action_attack execute_action_attack unless $@
def execute_action_attack
if @active_battler.actor?
@active_battler.thirst += ATTACK_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0134_execute_action_attack
end
alias jet0135_execute_action_guard execute_action_guard unless $@
def execute_action_guard
if @active_battler.actor?
@active_battler.thirst += GUARD_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0135_execute_action_guard
end
alias jet0136_execute_action_escape execute_action_escape unless $@
def execute_action_escape
if @active_battler.actor?
@active_battler.thirst += ESCAPE_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0136_execute_action_escape
end
alias jet0137_execute_action_wait execute_action_wait unless $@
def execute_action_wait
if @active_battler.actor?
@active_battler.thirst += WAIT_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0137_execute_action_wait
end
alias jet0138_execute_action_skill execute_action_skill unless $@
def execute_action_skill
if @active_battler.actor?
@active_battler.thirst += SKILL_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0138_execute_action_skill
end
alias jet0139_execute_action_item execute_action_item unless $@
def execute_action_item
if @active_battler.actor?
@active_battler.thirst += ITEM_THIRST_RAISE if USE_THIRST
if @active_battler.thirst > MAX_THIRST
@active_battler.thirst = MAX_THIRST
elsif @active_battler.thirst < 0
@active_battler.thirst = 0
end
end
jet0139_execute_action_item
end
end
end
class Game_Battler
include HungerThirst
alias jet5823_item_effect item_effect unless $@
def item_effect(user, item)
jet5823_item_effect(user, item)
unless @skipped
user.thirst -= item.lower_thirst unless item.lower_thirst == :unthirst
if user.thirst > MAX_THIRST
user.thirst = MAX_THIRST
elsif user.thirst < 0
user.thirst = 0
end
end
end
alias jet9243_apply_state_changes apply_state_changes unless $@
def apply_state_changes(obj)
if obj.minus_state_set.include?(1) && DIE_ON_MAX_HUNGER_OR_THIRST && self.actor?
self.thirst -= REVIVED_THIRST_LOWER
if self.thirst > MAX_THIRST
self.thirst = MAX_THIRST
elsif self.thirst < 0
self.thirst = 0
end
end
self.jet9243_apply_state_changes(obj)
end
if AFFECT_STATS
alias jet0132_atk atk unless $@
def atk
n = jet0132_atk
if self.actor?
if self.thirst >= LOWER_STATS_THIRST
n *= THIRST_LOWERED_STATS[0]
end
end
return n
end
alias jet8921_def def unless $@
def def
n = jet8921_def
if self.actor?
if self.thirst >= LOWER_STATS_THIRST
n *= THIRST_LOWERED_STATS[1]
end
end
return n
end
alias jet9021_spi spi unless $@
def spi
n = jet9021_spi
if self.actor?
if self.thirst >= LOWER_STATS_THIRST
n *= THIRST_LOWERED_STATS[2]
end
end
return n
end
alias jet0213_agi agi unless $@
def agi
n = jet0213_agi
if self.actor?
if self.thirst >= LOWER_STATS_THIRST
n *= THIRST_LOWERED_STATS[3]
end
end
return n
end
end
end
class Window_Status
alias jet5840_refresh refresh unless $@
def refresh
jet5840_refresh
self.contents.font.color = system_color
self.contents.draw_text(50, 334, 100, 24, "Thirst: ")
self.contents.font.color = normal_color
self.contents.draw_text(150, 334, 100, 24, @actor.thirst)
end
end
class Scene_Base
include HungerThirst
alias jet2034_update update unless $@
def update
jet2034_update
unless $scene.is_a?(Scene_Title)
for actor in $game_party.members
if $game_party.all_dead?
@window = Window_Help.new
@window.y = 152
@window.set_text("Your last party member has died of hunger.", 1)
loop do
if Input.trigger?(Input::C)
@window.dispose
$scene = Scene_Gameover.new
break
end
end
end
if $game_party.all_dead?
@window = Window_Help.new
@window.y = 152
@window.set_text("Your last party member has died of Thirst.", 1)
loop do
if Input.trigger?(Input::C)
@window.dispose
$scene = Scene_Gameover.new
break
end
end
end
end
end
end
end
unless $engine_scripts.nil?
JetEngine.active("Hunger/Thirst", 1.2)
end
RE: Skrypt głodu - tylko jeden bohater - Ayene - 27-08-13 07:27
Za actor trzeba podstawić cyfrę, która odpowiada indeksowi bohatera w drużynie. Czyli pierwszy bohater ma indeks 0, drugi - 1, trzeci - 2, itd.
Dlatego w komendzie
Kod:
change_hunger(actor, amount)
jeśli chcesz zmienić poziom głodu pierwszej postaci w drużynie, wpisz:
Kod:
change_hunger(0, 200)
RE: Skrypt głodu - tylko jeden bohater - aron155 - 29-08-13 02:25
Problem w tym, że w skrypcie nie ma tego polecenia. Mogę sam aktywować tą komendę w zdarzeniu. Podczas poruszania zmienia się głód i to jest w skrypcie zawarte. Znalazłem jednak, że jest pełno pętli for zależnych od rozmiaru drużyny. Wyrzucę je i zamiast parametru i dam konkretnego bohatera. Wpadłem właśnie na lepszy pomysł (ah to podwójne espresso o 4 nad ranem :D ). Jak zrobić, aby naliczanie głodu było zależne od zmiany klasy bohatera bądź zmiennej? Na zasadzie, że gra się normalnie, jakieś zdarzenie zmienia klasę bohatera/zmienia zmienną i wtedy włącza się system głodu dla danego bohatera? Tutaj jest link do pełnego skryptu jak coś: SKRYPT
RE: Skrypt głodu - tylko jeden bohater - Ayene - 29-08-13 20:47
Czyli chcesz, aby głód bohatera wzrastał przy chodzeniu, ale dopiero po zmianie jego klasy?
RE: Skrypt głodu - tylko jeden bohater - aron155 - 29-08-13 22:17
Dokładnie. Konkretnie chodzi o przypisanie tego skryptu do konkretnej klasy (jak bohater będzie tej klasy, to skrypt będzie działał dla niego). Może być przy zmianie klasy bądź zmiennej/przełącznika. Zapewne najwygodniej będzie ze zmienną - if zmienna = 1 ... Wtedy skrypt będzie przygotowany pod konkretnego bohatera ale aktywny, gdy zmienna będzie miała konkretną wartość. Tylko nie wiem jak sprawdzać w skrypcie wartość zmiennej :/
RE: Skrypt głodu - tylko jeden bohater - Ayene - 29-08-13 22:46
W cale nie będzie łatwiej ze zmienną. Znajdź w skrypcie linijkę:
Kod:
$game_party.members[i].hunger += STEP_HUNGER_ADDED if USE_HUNGER
przed nią dodaj:
Kod:
if [1, 2, 3].include?($game_party.members[i].class_id)
następnie znajdź poniżej:
Kod:
jet2211_increase_steps(*args)
przed nią dodaj:
tablica [1, 2, 3] zawiera po przecinku ID klas, które mają aktywować głód i pragnienie.
RE: Skrypt głodu - tylko jeden bohater - aron155 - 29-08-13 23:01
Dzięki, poszło ;) Myślałem, że porównanie zmiennej będzie prostsze ;) Pojawił mi się jeszcze jeden problem. Po linii if AFFECT_STATS odpowiadającej za modyfikację atrybutów dodałem fragment odpowiadający za obniżenie życia i many:
Kod:
alias zmiana_hp hp unless $@
def hp
n = zmiana_hp
if self.actor?
if self.hunger >= LOWER_STATS_HUNGER
n *= HUNGER_LOWERED_STATS[4]
end
end
return n
end
alias zmiana_mp mp unless $@
def mp
n = zmiana_mp
if self.actor?
if self.hunger >= LOWER_STATS_HUNGER
n *= HUNGER_LOWERED_STATS[4]
end
end
return n
end
Jeśli osiągnięty zostanie określony prób, to poziom życia i many spada o zadany współczynnik. Przy leczeniu miksturką życie nie wraca do pełna (tak ma być).
Pierwszy problem: gdy dam bohaterowi miksturę życia, to spada mana. Analogicznie gdy dam manę spada życie. Jak to zniwelować?
Drugi problem: Załóżmy, że max hp wynosi 400 a obecne hp 300. Gdy współczynnik wynosi 0.9 max hp będzie 360. Problem w tym, że hp też spada a chciałbym żeby zostało bez zmian.
Dodatkowym problemem jest zaokrąglenie. Przy drugim problemie hp ma kilka miejsc po przecinku. W jaki sposób mogę je zaokrąglić do 1 miejsca po przecinku?
|