Ayene - Sob 07 Sty, 2012 16:25 Temat postu: Okno końca walki [VX]
~ Okno końca walki [VX] - Battle Result Window [VX] ~
Krótki opis:
Skrypt wyświetla okno z wynikami po zakończeniu walki (patrz screen), czyli informacje o:
- zdobytych przedmiotach, złocie, doświadczeniu (animowany pasek),
- poznanych umiejętnościach.
Może nie być kompatybilny z innym niż domyślny systemem walki.
Autor:
Ayene [yurika@o2.pl]
Kompatybilność:
RPG Maker VX
Skrypt:
Spoiler:
Kod:
#===================================================================
# Okno końca walki [VX] - Battle Result Window [VX]
# by Ayene
# 07.01.2012 ver 1.2
# www.ultimateam.pl
#===================================================================
# Opis:
# Skrypt wyświetla okno z wynikami po zakończeniu walki.
# Może nie być kompatybilny z innym niż domyślny systemem walki.
#===================================================================
module Ayene
#==============================================================================
# ** [Część do edycji] - Konfiguracja skryptu
#------------------------------------------------------------------------------
DROP_TEXT = "Drużyna zdobyła:" # Tekst
GOLD_ICON = 205 # Ikona złota (jej indeks w Iconset)
EXP_ICON = 204 # Ikona punktów doświadczenia
LEVEL_UP_ICON = 142 # Ikona awansu na poziom
LEVEL_UP_SE = "Decision2" # Dźwięk awansu, "" by wyłaczyć
# Gdy bar inny niż domyślny, parametry ułatwiają ustawienie paska
# doświadczenia w odpowiednim miejscu.
BAR_X = 8 # Przesunięcie paska poziomo
BAR_Y = 3 # Przesunięcie paska pionowo
WIDTH = 104 # Szerokość paska doświadczenia
#==============================================================================
# Koniec konfiguracji
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# * Display Gained Experience and Gold
#--------------------------------------------------------------------------
def display_exp_and_gold
@message_window.visible = false
skills = []
level_up = {}
exp = $game_troop.exp_total
for actor in $game_party.members
unless actor.dead?
last_level = actor.level
last_skills = actor.skills
actor.gain_exp(exp, true)
(actor.skills - last_skills).each {|skill|
skills.push([skill, actor])
}
if last_level < actor.level
level_up[actor] = actor.level - last_level
else
level_up[actor] = 0
end
else
level_up[actor] = 0
end
end
gold = $game_troop.gold_total
$game_party.gain_gold(gold)
drop_items = []
for item in $game_troop.make_drop_items
$game_party.gain_item(item, 1)
drop_items.push(item)
end
create_result_windows(exp, gold, drop_items, skills, level_up)
wait_for_result
@battle_result.dispose
@item_result.dispose
$game_message.texts.clear
end
#--------------------------------------------------------------------------
# * Display Gained Drop Items
#--------------------------------------------------------------------------
def display_drop_items
end
#--------------------------------------------------------------------------
# * Display Level Up
#--------------------------------------------------------------------------
def display_level_up
end
#--------------------------------------------------------------------------
# * Create Battle Result Window
#--------------------------------------------------------------------------
def create_result_windows(exp, gold, items, skills, level_up)
@battle_result = Window_Battle_Result.new(exp, level_up)
@item_result = Window_Result_Item.new(gold, items, exp, skills)
end
#--------------------------------------------------------------------------
# * Wait Until Result Window Display has Finished
#--------------------------------------------------------------------------
def wait_for_result
close = false
loop do
update_basic
@battle_result.update
break if @battle_result.stop
end
loop do
update_basic
if Input.trigger?(Input::C)
close = true
end
if close
@battle_result.opacity -= 10
@battle_result.contents_opacity -= 10
@item_result.opacity -= 10
@item_result.contents_opacity -= 10
end
break if @battle_result.opacity == 0
end
end
end
#==============================================================================
# ** Window_Battle_Result
#==============================================================================
class Window_Battle_Result < Window_Base
include Ayene
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :stop
#--------------------------------------------------------------------------
# * Object Initialization
# exp : gained exp
# level_up : level up hash
#--------------------------------------------------------------------------
def initialize(exp, level_up)
super(0, 0, 544, 224 + WLH)
@exp = exp
@level_up = level_up
@rate = {}
@max = []
for actor in $game_party.members
lv = actor.level - @level_up[actor]
s1 = actor.gained_exp(lv, actor.exp - @exp)
s2 = actor.needed_exp(lv)
gw = [s1 * WIDTH / s2, WIDTH].min
@rate[actor] = gw
end
@stop = false
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for actor in $game_party.members
draw_actor_face(actor, actor.index % 2 * 260, actor.index / 2 * 96 + WLH / 2, 92)
x = 114 + actor.index % 2 * 260
y = 10 + actor.index / 2 * 96 + WLH / 2
draw_actor_name(actor, x, y)
draw_actor_level(actor, x, y + WLH * 1)
draw_actor_graphic_exp(actor, x, 10 + y + WLH * 2) unless actor.dead?
end
end
#--------------------------------------------------------------------------
# * Update Bars
#--------------------------------------------------------------------------
def update_bars
for actor in $game_party.members
x = 114 + actor.index % 2 * 260
y = 10 + actor.index / 2 * 96 + WLH / 2
draw_actor_graphic_exp(actor, x, 10 + y + WLH * 2)
end
end
#--------------------------------------------------------------------------
# * Draw Actor Exp Bars
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
# width : draw spot width
#--------------------------------------------------------------------------
def draw_actor_graphic_exp(actor, x, y, width = WIDTH)
unless IMG_BAR == ''
bitmap = Cache.picture(IMG_BAR)
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
bitmap.dispose
else
self.contents.fill_rect(x+BAR_X-1, y+BAR_Y-1, width+2, 8, Color.new(0,0,0))
end
s1 = actor.gained_exp(actor.level, actor.exp)
s2 = actor.needed_exp(actor.level)
gw = [s1 * WIDTH / s2, WIDTH].min
gc1 = Color.new(38,101,131)
gc2 = Color.new(45,121,157)
@max.push(gw)
if @level_up[actor] > 0
w = [@rate[actor], width].min
if @rate[actor] == width
@level_up[actor] -= 1
@rate[actor] = 0
draw_icon(LEVEL_UP_ICON, 100 + x, y - WLH * 2)
self.contents.clear_rect(x, y - WLH * 1 - 10, 64, WLH)
draw_actor_level(actor, x, y - WLH * 1 - 10)
RPG::SE.new(LEVEL_UP_SE, 100, 100).play if LEVEL_UP_SE != ''
end
else
w = [@rate[actor], gw].min
if @rate[actor] >= @max.max
@stop = true
end
end
self.contents.gradient_fill_rect(x+BAR_X, y+BAR_Y, w, 6, gc1, gc2)
end
#--------------------------------------------------------------------------
# * Draw Level
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_actor_level(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
self.contents.font.color = normal_color
self.contents.draw_text(x + 32, y, 24, WLH, actor.level - @level_up[actor], 2)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
for actor in $game_party.members
@rate[actor] += 1
end
update_bars
end
end
#==============================================================================
# ** Window_Result_Item
#==============================================================================
class Window_Result_Item < Window_Base
include Ayene
#--------------------------------------------------------------------------
# * Object Initialization
# gold : gained gold
# items : gained items
# exp : gained exp
# skills : learned skills
#--------------------------------------------------------------------------
def initialize(gold, items, exp, skills)
super(0, 248, 544, 144 + WLH)
@items = items
@gold = gold
@exp = exp
@skills = skills
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@skills.each_with_index {|tab, i|
actor = tab[1]
skill = tab[0]
text = sprintf("%s poznał - %s", actor.name, skill.name)
self.contents.draw_text(230, i * WLH, self.width, WLH, text)
break if i == 4
}
self.contents.draw_text(0, 0, self.width, WLH, DROP_TEXT)
draw_icon(EXP_ICON, 26, WLH)
self.contents.draw_text(50, WLH, self.width, WLH, @exp.to_s)
draw_icon(GOLD_ICON, 26, WLH * 2)
self.contents.draw_text(50, WLH * 2, self.width, WLH, @gold.to_s)
for i in 0...@items.size
draw_item_name(@items[i], 26, WLH * 3 + i * WLH)
end
end
end
#==============================================================================
# ** Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Gained Experience
#--------------------------------------------------------------------------
def gained_exp(current_level, current_exp)
return (current_exp - @exp_list[current_level])
end
#--------------------------------------------------------------------------
# * Needed Experience
#--------------------------------------------------------------------------
def needed_exp(current_level)
return (@exp_list[current_level + 1] - @exp_list[current_level])
end
end
Wymagana grafika:
Graphics/Pictures (jako 'hp_mp_bar').
Screeny:
Spoiler:
Dodatkowe informacje:
1. Wklej skrypt nad "Main" w Edytorze Skryptu.
2. Reszta instrukcji znajduje się w treści skryptu.MrBoomGood - Sob 07 Sty, 2012 17:07 Fajny skrypcik, gryzie się z ABS...bluemike - Pon 09 Sty, 2012 16:29
Spoiler:
lv = actor.level - @level_up[actor]
Mi wyskakuje błąd z ta linijką
Edit:
Zapomniałem dodać ,że to się tylko pokazuje po walce nie od razu po włączeniu gry testowej i używam na razie podstawowego systemu walki z dodatkiem HP przeciwników i avatary podczas
walki.
Edit 2:
Już obczaiłem że tak się dzieje jak jedna postać z naszej drużyny zostanie pokonana.aron155 - Pon 27 Lut, 2012 23:07 Mam ten sam problem :/ Wie ktoś jak to naprawić?onimush3 - Wto 28 Lut, 2012 14:09 Mi wszystko działa jak należy!!! Bardzo fajny skrypcik!!!
Upewnijcie się czy dobrze zapisaliście graficzkę do skryptu?
Upewnijcie się czy w dobrym miejscu znalazła się grafika!?
Upewnijcie się czy dokładnie skopiowaliście skrypt do programu?
Czasami wystarczy że podczas wklejania skryptu gdzieś daliśmy niechcący spację albo coś się skasowało i dupcia!!!aron155 - Wto 28 Lut, 2012 17:49 Grafika jest dobrze zapisana (inaczej skrypt by wcale nie działał). Skrypt wrzuciłem ponownie i ten sam problem. Za każdym razem, gdy któryś z członków drużyny zginie wyskakuje taki błąd:
Script 'wynik' line 137: TypeError Occurred.
nil can't be coerced into FixnumAyene - Wto 28 Lut, 2012 23:12 Faktycznie, przeoczyłam warunek, czy bohater przeżył starcie. Poprawiłam skrypt w pierwszym poście. Mam nadzieję, że teraz będzie OK.aron155 - Sro 29 Lut, 2012 17:44 Dzięki za poprawkę, skrypt działa ;)SirLex - Sob 24 Mar, 2012 12:35 Nie dziala :( Finwe - Sob 24 Mar, 2012 14:13 Jak nie działa, opisz problem, jaki error wyskakuje itp.
Bo tak to mogę z tą ilością informacji Ci powiedzieć że
może to przez syrop klonowy na płycie głównej