Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Equipped Weapon

Can someone show me how I can check if a certain weapon is equipped. I need to do it in 'Game_Battler'.

Thanks in Advance

Syvkal
 
You can use these lines to check if someone has a certain weapon equipped:
Code:
$game_party.actors[id].weapon_id == number
id = the position of the character in the party. 0-3.
number = the id of the weapon in the database.

OR:
Code:
$game_actors[id].weapon_id == number
id = the id of the character in the database.
number = the id of the weapon in the database.


Now, lets say that you wanted to make something happen whenever someone attacks, and has a special weapon equipped you can go to "def attack_effect(attacker)"  in Game_Battler and use this to check if the attacker has that certain weapon:

Code:
    if attacker.weapon_id == number
      #do what you want to happen
    else
      #do something else
    end

But that's just an example. I don't know what you're planning on doing ^^
I hope that helps. :thumb:

Over and out - Gando
 
Hmmm... right I guess I could of worked that out myself, but the problem is how do I get the actor number (or define 'attacker').

Basically I'm using this in 'def skill_can_use?(skill)' so I'm a bit confused on how to get the actor data...


Thanks for the first part though, that was me just being an idiot ^_^


:EDIT:

Something new too....

For some reason the command
.slice!
is messing up my game.

Just by putting it in 'def skill_can_use?(skill)' it makes the skills look disabled, but you can click them, and if you go back and then back on it they're not disabled anymore.

And yes there is a reason for using .slice!
But I don't get why it's doing this....
Any ideas?
 

khmp

Sponsor

.slice! From where what line? The error is being caused because the string is nil most likely. Try printing the string before you actually try to slice it.

Code:
slicer = '-'
p string
string.slice!(slicer) unless string.nil?
 
That's not what's wrong. When I print it before the slice! it returns 'STATE12' (which it should), and after the slice! it returns '12'
But for some reason the slice! is messing it up, and I don't have any clue why...

Just it being there messes it up....
 

khmp

Sponsor

Well slice! permanently alters the string. If just want the number and want to leave the string intact use slice without the exclamation point and just save the slice data to a temporary string if you want.

Code:
if 1 == 'Test1'.slice('1').to_i
  # string contained the number one.
else
  # toast
end
 
Right thanks for the help, but I acually figured out the problem myself.
The problem was that when I altered the string it acutally altered the original string in the database which my original IF statement was checking...

Anywho that's not important now....

I really need help with my other problem:

How do I get the actor number (or define 'attacker') to use in 'def skill_can_use?(skill)' ?
 
Sorry about that, it doesn't actually matter now, I found it out.

You can actually use 'self' or just leave it off completely seeing as Game_Battler and Game_Actor seem to be the same (or similar).


Thanks anyways ^_^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top