So I have this script I'm trying to get working. Everything is working except 2 things. I've add a new bar to make you wait 1 to 3 turns before you can cast spells depending on the charge points associated with the skill_id. I got the bar added its going up each turn but after I cast the spell its not reducing the charge point system by the charge point cost.
the other problem isn't a big deal but I'd still like to get it working if possible. might be a user error on my part. I'm trying to add a tag to the name to show the charge point cost if it applies. haven't messed with it to much. I may figure this one out soon but if anyone could point me in the right direction I'd appreciate it.
the other problem isn't a big deal but I'd still like to get it working if possible. might be a user error on my part. I'm trying to add a tag to the name to show the charge point cost if it applies. haven't messed with it to much. I may figure this one out soon but if anyone could point me in the right direction I'd appreciate it.
Code:
module CP
MAX_CP = 3 # maximum CP any battler can hold
GAIN_PER_TURN = 1 # CP gained per turn end (per battler)
# CP cost per skill id. If a skill id isn't here, it costs 0 CP.
COST = {87 => 3
# skill_id => cp_cost
# Example entries: change to match your database
# 1 => 1,
# 17 => 2,
# 28 => 3,
}
# Color for the CP gauge bar (left to right; two passes like HP/SP do)
GAUGE_COLOR1 = Color.new( 80, 200, 255, 255)
GAUGE_COLOR2 = Color.new( 20, 120, 200, 255)
# Text color for CP number
TEXT_COLOR = Color.new( 80, 200, 255, 255)
end
#------------------------------------------------------------------------------
# Game_Battler: add CP resource to actors & enemies
#------------------------------------------------------------------------------
class Game_Battler
attr_accessor :cp
alias cp_init_initialize initialize
def initialize
cp_init_initialize
@cp = 0
end
def cp_max
return CP::MAX_CP
end
def cp_gain(value)
@cp = [[@cp + value, 0].max, cp_max].min
end
def cp_cost_for(skill_id)
return CP::COST[skill_id] || 0
end
# Extra requirement check for CP on top of stock SP checks
alias cp_skill_can_use? skill_can_use?
def skill_can_use?(skill_id)
return false unless cp_skill_can_use?(skill_id)
return @cp >= cp_cost_for(skill_id)
end
end
#------------------------------------------------------------------------------
# Game_Actor / Game_Enemy: (inherits @cp from Game_Battler)
# Nothing else needed here, but kept for clarity/extension.
#------------------------------------------------------------------------------
class Game_Actor < Game_Battler; end
class Game_Enemy < Game_Battler; end
#------------------------------------------------------------------------------
# Scene_Battle: turn tick, battle start reset, and CP consumption on skill use
#------------------------------------------------------------------------------
class Scene_Battle
# Reset all party actors' CP to 0 at battle start
alias cp_start_phase1 start_phase1
def start_phase1
$game_party.actors.each { |a| a.cp = 0 if a }
cp_start_phase1
end
# At turn end (phase 4), everyone gains CP
alias cp_start_phase4 start_phase4
def start_phase4
# All living battlers (actors + enemies) gain CP
for actor in $game_party.actors
next if actor.nil?
actor.cp_gain(CP::GAIN_PER_TURN)
end
for enemy in $game_troop.enemies
next if enemy.nil?
enemy.cp_gain(CP::GAIN_PER_TURN)
end
cp_start_phase4
end
# When executing a skill action, also deduct CP cost
alias cp_make_skill_action_result make_skill_action_result
def make_skill_action_result
cp_make_skill_action_result
# If a skill was actually executed, deduct CP (matching SP deduction timing)
if @skill != nil && @active_battler != nil
cost = @active_battler.cp_cost_for(@skill)
@active_battler.cp = [@active_battler.cp - cost, 0].max
end
end
end
#------------------------------------------------------------------------------
# Window_Base: helper to draw CP gauge & number
#------------------------------------------------------------------------------
class Window_Base < Window
# Simple gauge drawer similar to HP/SP bar (integer steps, 0..MAX_CP)
def draw_actor_cp_gauge(actor, x, y, width = 150)
# Background gauge box
self.contents.fill_rect(x, y + 12, width, 6, Color.new(0,0,0,64))
# Fill proportional to CP
rate = (actor.cp_max == 0) ? 0.0 : actor.cp.to_f / actor.cp_max
w = (width * rate).to_i
# Two-pass fill for a subtle gradient
self.contents.fill_rect(x, y + 12, w, 6, CP::GAUGE_COLOR2)
self.contents.fill_rect(x, y + 12, w, 3, CP::GAUGE_COLOR1)
# Label + value (e.g., "CP 2/3")
self.contents.font.color = system_color
self.contents.draw_text(x - 16, y - 10, 28, 24, "Charge")
self.contents.font.color = CP::TEXT_COLOR
text = "#{actor.cp}/#{actor.cp_max}"
self.contents.draw_text(x + width - 48, y - 10, 48, 24, text, 2)
self.contents.font.color = normal_color
end
end
#------------------------------------------------------------------------------
# Window_BattleStatus: add CP line under HP/SP
# (Keeps layout tight for RMXP default window width)
#------------------------------------------------------------------------------
class Window_BattleStatus < Window_Base
alias cp_refresh refresh
def refresh
cp_refresh
# Draw CP for each actor in their block
@item_max = $game_party.actors.size
for i in 0...@item_max
actor = $game_party.actors[i]
next if actor.nil?
x = i * 160 + 280 # default RMXP layout width per battler block
y = 6 # place CP below HP/SP lines
draw_actor_cp_gauge(actor, x, y, 120)
end
end
end
#------------------------------------------------------------------------------
# Window_Skill: gray out skills you can't afford in CP (as well as SP)
#------------------------------------------------------------------------------
class Window_Skill < Window_Selectable
alias cp_draw_item draw_item
def draw_item(index)
skill = @data[index]
if skill == nil
return
end
actor = @actor
enabled = actor.skill_can_use?(skill)
# Temporarily dim text if not usable due to CP/SP
self.contents.font.color = enabled ? normal_color : disabled_color
cp_draw_item(index)
self.contents.font.color = normal_color
end
end
#------------------------------------------------------------------------------
# UI hint: show CP cost on skill list (optional). Uncomment to append [CPx].
#------------------------------------------------------------------------------
class Window_Skill < Window_Selectable
alias cp_draw_item_text draw_item
def draw_item(index)
skill = @data[index]
return if skill.nil?
# Build name with CP tag
cost = @actor.cp_cost_for(skill)
name = skill.name.dup
name += " [CP#{cost}]" if cost > 0
# Draw with augmented name (temporarily swap)
original = skill.name
skill.name = name
cp_draw_item_text(index)
skill.name = original
end
end