Project1
标题: 自定义了一个属性,怎么把它在脚本里读出来 [打印本页]
作者: 双叶GL 时间: 2013-6-20 17:11
标题: 自定义了一个属性,怎么把它在脚本里读出来 本帖最后由 双叶GL 于 2013-6-22 02:21 编辑
Undo
貌似只能在
里
脚本,变量里读,
怎么在脚本里读取这个属性=begin
#===============================================================================
# N.A.S.T.Y. Extra Stats
# Nelderson's Awesome Scripts To You
# By: Nelderson
# Made On: 12/19/2011
# Last Updated : 3/27/2012
该脚本来源于
http://forums.rpgmakerweb.com/index.php?/topic/998-nasty-extra-stats/
发布者/作者?:Member+
#===============================================================================
# Update History:
# - Version 1.1 - Cleaned up some shit, and added enemies xstats for Enemies!
# - Version 1.0 - Initial release, made for the shit of it <img src='http://forums.rpgmakerweb.com/public/style_emoticons/<#EMO_DIR#>/tongue.png' class='bbc_emoticon' alt=':P' />
在人物备注填写,属性成长
<xstat>
:str => '(level/3.5) + 16',
:con => '(level/5.6) + 12',
:dex => '(level/5.25) + 15 + agi',
:int => '(level/10.5) + 10',
:wis => '(level/10.5) + 10',
:cha => '(level/10.5) + 10',
<xstat_end>
也可以直接在备注填写固定属性
<xstat>
:str => 15,
:con => 14,
:dex => 13,
:int => 12,
:wis => 11,
:cha => 0,
<xstat_end>
在武器或护甲的备注里按照如下格式填写可以让该装备增加对应属性
<weapon_xstat: STAT x>
范例,让装备增加5点‘str’ <weapon_xstat: str 5>
调用属性:$game_actors[1].xstat.X 例:$game_actors[1].xstat.str
伤害公式范例: a.xstat.str * 5
#===============================================================================
=end
module Z26
STATS = [:力量,:耐力,:灵巧,:敏捷,:魔力,:智力]
#Default xstat formulas for ACTORS
#玩家基础属性
DEFAULT_LEVEL_FORMULA =
{
:力量 => 1,
:耐力 => 1,
:灵巧 => 1,
:敏捷 => 1,
:魔力 => 1,
:智力 => 1,
}
#Default xstat formulas for ENEMIES\
#敌对基础属性
DEFAULT_FOR_ENEMIES =
{
:力量 => 1,
:耐力 => 1,
:灵巧 => 1,
:敏捷 => 1,
:魔力 => 1,
:智力 => 1,
}
def self.actor_level_formulas(actor_id)
jhh = ""
strin = $data_actors[actor_id].get_start_end_cache
strin.each do |i|
jhh += i
end
return DEFAULT_LEVEL_FORMULA if strin == "" or strin == []
return eval("{#{jhh}}")
end
def self.enemy_stats(enemy_id)
jhh = ""
strin = $data_enemies[enemy_id].get_start_end_cache
strin.each do |i|
jhh += i
end
return DEFAULT_FOR_ENEMIES if strin == "" or strin == []
return eval("{#{jhh}}")
end
#=============================================================================
SYMBOLS = []
for stat in STATS
SYMBOLS.push(stat)
end
Xstats = Struct.new(*SYMBOLS)
end
class Game_Enemy < Game_Battler
attr_accessor :xstat
alias z26_enemy_set initialize unless $@
def initialize(*args)
z26_enemy_set(*args)
@xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
for stat in Z26::STATS
z26variate_stats(stat)
end
end
def z26variate_stats(stat)
return if Z26.enemy_stats(@enemy_id)[stat].nil?
if Z26.enemy_stats(@enemy_id)[stat].is_a?(String)
set_in = eval(Z26.enemy_stats(@enemy_id)[stat]).to_i
eval("@xstat.#{stat} += #{set_in}")
else
set_in = Z26.enemy_stats(@enemy_id)[stat]
@xstat[stat] += set_in
end
end
end
class Game_Actor < Game_Battler
attr_accessor :xstat
alias z26_s setup unless $@
def setup(actor_id)
z26_s(actor_id)
@xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
for item in equips.compact
z26variate_equip(item)
end
for stat in Z26::STATS
z26variate_stats(stat, @level)
end
end
alias z26_change_equip change_equip
def change_equip(equip_type, item, test = false)
last_item = equips[equip_type]
z26_change_equip(equip_type, item)
z26variate_equip(item)
z26variate_equip(last_item, false)
end
#=====================#
##EDITED BY NELDERSON##
#=====================#
def z26variate_equip(item, adding = true)
return if item.nil?
for line in item.note.split(/[\r\n]+/).each{ |a|
case a
when /<weapon_xstat:[ ](.*)[ ](\d+)>/i
if Z26::STATS.include?(eval(":" + $1))
if adding
eval("@xstat.#{$1} += #{$2}")
else
eval("@xstat.#{$1} -= #{$2}")
end
end
end
}
end
end
def z26variate_stats(stat, level, adding = true)
return if Z26.actor_level_formulas(@actor_id)[stat].nil?
if Z26.actor_level_formulas(@actor_id)[stat].is_a?(String)
amount = eval(Z26.actor_level_formulas(@actor_id)[stat]).to_i
else
amount = Z26.actor_level_formulas(@actor_id)[stat]
end
if adding
eval("@xstat.#{stat} += #{amount}")
else
eval("@xstat.#{stat} -= #{amount}")
end
end
alias z26level_up level_up unless $@
def level_up
for stat in Z26::STATS
z26variate_stats(stat, @level, false)
end
z26level_up
for stat in Z26::STATS
z26variate_stats(stat, @level)
end
end
end
class Window_Status < Window_Selectable
def draw_block3(y)
draw_parameters(0, y)
draw_equipments(344, y)#288
draw_xstat_parameters(172, y)
end
def draw_xstat_parameters(x, y)
@actor.xstat.size.times {|i|
draw_actor_xstat_param(@actor, x, y + line_height * i, i) }
end
end
class Window_Base < Window
def draw_actor_xstat_param(actor, x, y, param_id)
id = Z26::STATS[param_id]
change_color(system_color)
draw_text(x, y, 120, line_height, id.capitalize)
change_color(normal_color)
draw_text(x + 120, y, 36, line_height, actor.xstat[id], 2)
end
end
class RPG::BaseItem
def get_start_end_cache
record = false
temp = []
self.note.split(/[\r\n]+/).each do |line|
if line =~ /<xstat>/i
record = true
elsif line =~ /<xstat_end>/i
record = false
end
if record
temp << line
end
end
return nil if temp == ""
temp.delete_at(0)
temp
end
end 复制代码
作者: Sion 时间: 2013-6-20 21:22
不就是$game_actors[x].xstat.力量 吗
作者: tyq4590 时间: 2013-6-20 21:35
描画指定范围内的自定义属性,比如7-12号(具体坐标可以自行调整):
for i in 7 ..12
draw_actor_xstat_param( @actor, x, y + line_height * ( i-7 ) , i)
end
for i in 7 ..12
draw_actor_xstat_param( @actor, x, y + line_height * ( i-7 ) , i)
end
作者: 双叶GL 时间: 2013-6-21 17:08
tyq4590 发表于 2013-6-20 21:35
描画指定范围内的自定义属性,比如7-12号(具体坐标可以自行调整):
for i in 7..12
= =很抱歉我只是脚本新人,没一个范例的话,你给我,我只知道,这是一个循环定义
但是我不知道怎么开始使用,
回复2L:应该我需要的是在脚本里调用这段属性,直接这样调用没办法显示啊
作者: tyq4590 时间: 2013-6-21 18:18
双叶GL 发表于 2013-6-21 21:08
= =很抱歉我只是脚本新人,没一个范例的话,你给我,我只知道,这是一个循环定义
但是我不知道怎么开始使用, ...
def draw_xstat_parameters( x, y)
@actor .xstat .size .times { |i|
draw_actor_xstat_param( @actor, x, y + line_height * i, i) }
end
def draw_xstat_parameters( x, y)
@actor .xstat .size .times { |i|
draw_actor_xstat_param( @actor, x, y + line_height * i, i) }
end
这段脚本的意思就是描绘所有的xstat属性,也就是有多少个就显示多少个出来。如果你设置了一个属性但是无法显示的话,那么要么是属性设置有误,要么就是属性添加的过多,超过窗体可以显示的范围了。如果你把工程传上来我可以帮你仔细检查一下看看是什么问题。
作者: 双叶GL 时间: 2013-6-21 20:55
本帖最后由 双叶GL 于 2013-6-22 11:42 编辑
tyq4590 发表于 2013-6-21 18:18
def draw_xstat_parameters(x, y)
@actor.xstat.size.times {|i|
draw_actor_xstat_param(@actor, x, ...
= =3Q,大概知道怎么显示了,
=======原来一开始就是说
def draw_xstat_parameters(x, y)
for i in 0..3
draw_actor_xstat_param(@actor, 32, y + line_height * 0, 0)
draw_actor_xstat_param(@actor, 64, y + line_height * 1, 1)
end
显示其中第一个~4个属性,然后在重新定即可
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1