Help - Search - Members - Calendar
Full Version: Yet another newbie query
RPG RPG Revolution Forums > Game Engines > RPG Maker VX Ace Discussion
Crazy Rob
I hope I'm not going over old ground that's been walked to death, but is there a way to make it so that when a skill is used, it adds 1 to a variable?

I could do it with a common event for each one I need to function that way, but that seems wasteful. Any scripts or tips?
Tsukihime
Game_Battler#item_apply is when you actually use a skill/item, which gives you the skill/item.

You can extend it to increment a variable by checking if it's a skill and then grabbing the skill ID.
Crazy Rob
Here's what I have for coding.

def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
return $game_variables[7] + 1 if attack_skill_id = 56
return $game_variables[7] + 2 if attack_skill_id = 57
return $game_variables[7] + 4 if attack_skill_id = 58
return $game_variables[7] + 10 if attack_skill_id = 59
end

I've tried it with and without the return at the beginning. The system doesn't crash, it just doesn't add the values of 1, 2, 4, or 10 to variable 7 when those skills are used.

I'm a newbie coder. What am I doing wrong?
Tsukihime
QUOTE
What am I doing wrong?


Well, can you explain what you did and what you were hoping to achieve by writing your code that way?

Figuring out what went wrong is something you should also be thinking about as a coder.
Most coders probably spend more time tossing keyboards across the room than actually typing because things don't work the way they expected.
diamondandplatinum3
QUOTE
CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
return $game_variables[7] + 1 if attack_skill_id = 56
return $game_variables[7] + 2 if attack_skill_id = 57
return $game_variables[7] + 4 if attack_skill_id = 58
return $game_variables[7] + 10 if attack_skill_id = 59
end


You need to use the ' += ' operator.

All you're doing there is telling the CPU to do a math equation without giving a result to anything.


CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
$game_variables[7] += 1 if attack_skill_id = 56
$game_variables[7] += 2 if attack_skill_id = 57
$game_variables[7] += 4 if attack_skill_id = 58
$game_variables[7] += 10 if attack_skill_id = 59
end


Using += you're telling the computer to add on the the first equation.

EDIT: Also I didn't notice this earlier, but you're also trying to assign a number to your skill ID's


CODE
def attack_apply(attacker)
item_apply(attacker, $data_skills[attacker.attack_skill_id])
$game_variables[7] += 1 if attack_skill_id == 56
$game_variables[7] += 2 if attack_skill_id == 57
$game_variables[7] += 4 if attack_skill_id == 58
$game_variables[7] += 10 if attack_skill_id == 59
end


You need to use ' == ' when checking if something is equal to something.


Using the equals symbol on its own will always assign (or attempt to) something .

if attack_skill_id = 56 # <- This is not good, don't do it when checking it.
if attack_skill_id == 56 # <- That's what you want.

Merging your posts. Please do not double post ~ Ratty524
Crazy Rob
what I was trying to achieve was that whenever a certain set of skills were used, a variable (variable 7 in this case) would be increased.

Use the weakest fire spell, 1 is added, use the strongest, and 10 is added.

Trying the recent method posted by diamondandplatinum isn't working, though. This is in the game_battler section as noted above.
Tsukihime
If you do a find-all search for "attack_apply" you might notice that nothing is actually calling that method (lol EB must've thought of doing something but then changed their mind)

Just add your changes to `item_apply`
Crazy Rob
This is the revised code under the second "item_apply" in the game_battler script...

#--------------------------------------------------------------------------
# * Apply Effect of Skill/Item
#--------------------------------------------------------------------------
def item_apply(user, item)
@result.clear
@result.used = item_test(user, item)
@result.missed = (@result.used && rand >= item_hit(user, item))
@result.evaded = (!@result.missed && rand < item_eva(user, item))
$game_variables[7] += 1 if attack_skill_id == 56
$game_variables[7] += 2 if attack_skill_id == 57
$game_variables[7] += 4 if attack_skill_id == 58
$game_variables[7] += 10 if attack_skill_id == 59
if @result.hit?
unless item.damage.none?
@result.critical = (rand < item_cri(user, item))
make_damage_value(user, item)
execute_damage(user)
end
item.effects.each {|effect| item_effect_apply(user, item, effect) }
item_user_effect(user, item)
end
end

Still nothing. Not even a crash. Am I just stupid?
Tsukihime
attack_skill_id is always 1.
Crazy Rob
...are you saying that the way I wrote it the skill id will always be 1, or that no matter how I write the script it will be 1?
udivision
replace "attack_skill_id"

with

user.attack_skill_id

or

item.id
Crazy Rob
Halle-effing-lujiah.

Item.id worked. Thank you, udivision.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.