[Script] [RPGXP] Serene Simple Skill Cooldown
Không biết forum còn ai dùng RPG Maker XP như em không nhỉ :-/ , sau 1 thời gian tìm tòi vọc về Ruby, nay ra lò thử 1 script xem như là thực hành, code có lỗi gì mong các senpai chỉ dẫn
[size=large]Giới Thiệu[/size]Thêm cooldown cho skill (skill tạm thời không sử dụng được trong vài turn sau khi sử dụng, good for turn-based battle system)
[size=large]Script:[/size][php]#==============================================================================
# [XP] Simple Skill Cooldown
#
# Allows you to add Cooldown to skills
# Author: Serene (just a simple script, no require credit)
#
# Works fine for both actor and enemy
#
# Script call:
# $game_party.actors[Actor ID].get_cooldown(Skill ID)
# $game_party.actors[Actor ID].set_cooldown(Skill ID, Value)
# $game_party.actors[Actor ID].increase_cooldown(Skill ID, Value)
# $game_party.actors[Actor ID].decrease_cooldown(Skill ID, Value)
#
# This script is just a simple idea when I realized we can rely on existing
# methods to make your project more differences
# Feel free to develop/customize/add more features to it
#==============================================================================
class Game_Battler
alias skill_cooldown_init initialize
alias skill_cooldown_use? skill_can_use?
alias skill_cooldown_reset remove_states_battle
alias skill_cooldown_auto remove_states_auto
alias skill_cooldown_effect skill_effect
end
# List of Skill IDs that will reset the Cooldown after the end of battle
COOLDOWN_BATTLE_END = [1, 2, 3]
#
# * Initialize
#
def initialize
skill_cooldown_init
@skills_turn = {}
@skills_turn.default = -1
end
#
# * Set Cooldown
#
def set_cooldown(skill_id, value)
value = -1 if (value < -1)
@skills_turn[skill_id] = value
end
#
# * Get Cooldown
#
def get_cooldown(skill_id)
return @skills_turn[skill_id]
end
#
# * Increase Cooldown
#
def increase_cooldown(skill_id, value=1)
cooldown = @skills_turn[skill_id]
@skills_turn[skill_id] = [cooldown + value, -1].max
end
#
# * Decrease Cooldown
#
def decrease_cooldown(skill_id, value=1)
cooldown = @skills_turn[skill_id]
@skills_turn[skill_id] = [cooldown - value, -1].max
end
#
# * Preventing using a skill if it has Cooldown
#
def skill_can_use?(skill_id)
return false if @skills_turn[skill_id] > -1
return skill_cooldown_use?(skill_id)
end
#
# * Reset Skill's Cooldown at the end of battle
#
def remove_states_battle
skill_cooldown_reset
for i in @skills_turn.keys.clone
if COOLDOWN_BATTLE_END.include?(i)
@skills_turn = -1
end
end
end
#
# * Decrease Cooldown each turn
#
def remove_states_auto
skill_cooldown_auto
for i in @skills_turn.keys.clone
self.decrease_cooldown(i)
end
end
#
# * Apply Cooldown for Skill
#
def skill_effect(user, skill)
effective = skill_cooldown_effect(user, skill)
skill_id = skill.id
# config Cooldown for Skills here
case skill_id
when 1 # Skill ID
user.set_cooldown(1, 3) # (Skill ID, number of turns in battle)
# or can use user.increase_cooldown(1, 3)
# (when Skill 1 is used, Skill 2 also cooldowns)
user.set_cooldown(2, 3) if @skills_turn[2] == -1
# Also can use "else statement" to set default Cooldown for other Skills
# else
# user.set_cooldown(skill_id, 1) # every skills have Cooldown 1 turn by default
end
#
return effective
end
end[/php]
[size=large]Hướng Dẫn:[/size]Đặt script này dưới tất cả, nhưng trên main.
Hướng dẫn trong script.
[size=large]Điều Khoản[/size]Thoải mái
[size=large]Tác Giả Script[/size]Serene
[size=large]Nguồn[/size]taotrochoi.com
[size=large]Giới Thiệu[/size]Thêm cooldown cho skill (skill tạm thời không sử dụng được trong vài turn sau khi sử dụng, good for turn-based battle system)
[size=large]Script:[/size][php]#==============================================================================
# [XP] Simple Skill Cooldown
#
# Allows you to add Cooldown to skills
# Author: Serene (just a simple script, no require credit)
#
# Works fine for both actor and enemy
#
# Script call:
# $game_party.actors[Actor ID].get_cooldown(Skill ID)
# $game_party.actors[Actor ID].set_cooldown(Skill ID, Value)
# $game_party.actors[Actor ID].increase_cooldown(Skill ID, Value)
# $game_party.actors[Actor ID].decrease_cooldown(Skill ID, Value)
#
# This script is just a simple idea when I realized we can rely on existing
# methods to make your project more differences
# Feel free to develop/customize/add more features to it
#==============================================================================
class Game_Battler
alias skill_cooldown_init initialize
alias skill_cooldown_use? skill_can_use?
alias skill_cooldown_reset remove_states_battle
alias skill_cooldown_auto remove_states_auto
alias skill_cooldown_effect skill_effect
end
# List of Skill IDs that will reset the Cooldown after the end of battle
COOLDOWN_BATTLE_END = [1, 2, 3]
#
# * Initialize
#
def initialize
skill_cooldown_init
@skills_turn = {}
@skills_turn.default = -1
end
#
# * Set Cooldown
#
def set_cooldown(skill_id, value)
value = -1 if (value < -1)
@skills_turn[skill_id] = value
end
#
# * Get Cooldown
#
def get_cooldown(skill_id)
return @skills_turn[skill_id]
end
#
# * Increase Cooldown
#
def increase_cooldown(skill_id, value=1)
cooldown = @skills_turn[skill_id]
@skills_turn[skill_id] = [cooldown + value, -1].max
end
#
# * Decrease Cooldown
#
def decrease_cooldown(skill_id, value=1)
cooldown = @skills_turn[skill_id]
@skills_turn[skill_id] = [cooldown - value, -1].max
end
#
# * Preventing using a skill if it has Cooldown
#
def skill_can_use?(skill_id)
return false if @skills_turn[skill_id] > -1
return skill_cooldown_use?(skill_id)
end
#
# * Reset Skill's Cooldown at the end of battle
#
def remove_states_battle
skill_cooldown_reset
for i in @skills_turn.keys.clone
if COOLDOWN_BATTLE_END.include?(i)
@skills_turn = -1
end
end
end
#
# * Decrease Cooldown each turn
#
def remove_states_auto
skill_cooldown_auto
for i in @skills_turn.keys.clone
self.decrease_cooldown(i)
end
end
#
# * Apply Cooldown for Skill
#
def skill_effect(user, skill)
effective = skill_cooldown_effect(user, skill)
skill_id = skill.id
# config Cooldown for Skills here
case skill_id
when 1 # Skill ID
user.set_cooldown(1, 3) # (Skill ID, number of turns in battle)
# or can use user.increase_cooldown(1, 3)
# (when Skill 1 is used, Skill 2 also cooldowns)
user.set_cooldown(2, 3) if @skills_turn[2] == -1
# Also can use "else statement" to set default Cooldown for other Skills
# else
# user.set_cooldown(skill_id, 1) # every skills have Cooldown 1 turn by default
end
#
return effective
end
end[/php]
[size=large]Hướng Dẫn:[/size]Đặt script này dưới tất cả, nhưng trên main.
Hướng dẫn trong script.
[size=large]Điều Khoản[/size]Thoải mái
[size=large]Tác Giả Script[/size]Serene
[size=large]Nguồn[/size]taotrochoi.com
Comments
Script của bạn rất hay, cố gắng phát huy nhé !!!
Bắt tay vào thực hành+lý thuyết cùng lúc luôn, chỉ cần 30p là có thể biết hết những thứ căn bản, đã đủ để tự tay edit script
:D :D :D
THAM GIA GROUP CỦA TTC TRÊN FACEBOOK