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.

a little help needed...

Hello all, I recently have come up with a system that I think would be interesting in a game, but need a little help getting it to work right...

The concept: I want to have a character who has the ability to magically summon energy-based weapons. She will basically replace her current physical weapon with a magical one and do damage with the magical weapon based off her int at the time (so as she levels, the magical weapon becomes increasingly better). It should also cost MP to sustain that weapon, so every round she acts, she would lose some (whether she attacks that round or not)

My Approach: I figured in order to accomplish this, I would need to do two things... one I pegged as being simple and the other, I wasn't sure I could pull off. Let's start with the simple part.

1. I created a dummy weapon in weapon slot 2 called "Magic Weapon". It has no stats and is just a placeholder for the system.
2. I created a skill of the same name that also has no stats and consumes no SP. It is set to trigger Common Event 1.
3. I also named Common Event 1 the same as the weapon and skill and did two things in the code to start:
3a. I tried the following code to store her currently equipped physical weapon into a variable so that it would not be lost:
Code:
$game_variables[1] = $game_actors[1].weapon_id
now I haven't actually tested to see if that actually works yet, it's just some BS I made up... but that's not important yet.
3b. After storing the weapon, I used the Change Equipment command to force the magical weapon as her equipped weapon.
4. Now here comes the tough part... I had to alter the script to make just that weapon work off int instead of atk...

Well, after I put it all together, I tested it through battle test. I had no other weapons yet, so I equipped her with nothing. Obviously an attack like does 0 damage, as expected. I then used the Magic Weapon skill and used the Attack command again. It still did 0 damage. My first thought was that my script was bad and did not tell the weapon how to calculate damage. So let's look back at my script for a second...

To make my script changes, I went to Game_Battler 3 and found something that looked like an area that calculated damage:
Code:
        atk = [attacker.atk - self.pdef / 2, 0].max
        self.damage = atk * (20 + attacker.str) / 20

To do what I wanted, I BSed the following code in front of this:

Code:
      if $game_actors[1].weapon_id == 2
        atk = [attacker.int - self.mdef / 2, 0].max

my philosophy was to try to make a case searching for weapon #2 (which as I said is the Magic Weapon's dummy slot) and in that case change this portion of the algorithm to run on int. I then though in an else statement after it so that in all cases of actual physical weapons, it would run the default calculation.

Well, before saying for certain that I did this all wrong, I decided to test one more thing... I did a battle test and made her equipment the Magic Weapon to start (instead of relying on the skill to force it in). When I attacked this time, it did damage as expected. Amazingly, my scripting actually did what I wanted it to do, but the Common event was effectless? That just made me scratch my head...

I knew that I did stuff like this before in pre-XP RPG Makers... but then I realized something. Prior to this edition, if you wanted a skill to use a Common Event, you set the skill to turn on a switch. That switch could then be used to trigger the Common Event. Now that sounds like a more effective method of doing things all of a sudden... what's the secret with the change now? You would think that it's as simple as telling the skill to use that Common Event, but it doesn't look like it is. It just does nothing. Can anybody figure out what I'm doing wrong here?

Also, I didn't even begin to do the SP drain... I'm not sure how to approach that. Going back to Game_Battler 3, I can make it at least deduct upon attack... but that's not what I really want. I could probably make code in every single Troop instance that checks for the weapon being equipped and then deduct every round there... but that sounds painfully troublesome and ineffecient. Anyone have any suggestions on the easiest route to make SP deduct every battle round while the weapon is equipped?
 
I didn't really read all of your post, but if you want to trigger a switch using a skill, trigger a common event the uses the Control Switches command. Sorry if it doesn't help, I just red that section.
 
The full damage formula goes from line 48 to 77 of Game_Battle 3, and goes as follows:
Code:
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = [attacker.atk - self.pdef / 2, 0].max
      self.damage = atk * (20 + attacker.str) / 20
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
You might wanna edit this code to suit your needs. But if you only want to edit the actual attack formula, as you did in your post, you did that perfectly well. Though I suggest making a status element called 'Int Based Weapon'. Find the ID of this element (1 through 999), then to simplify your code for every single weapon in your database, use this code to change your attack as you did in your first post ONLY for weapon with the Int Based Weapon element checked(not that when using actors[1], it's the second party member, not the first):
Code:
if @name.nil? # checks if the battler is NOT an actor
  if $data_weapons[$game_party.actors[0]].element_set.include?(9) # where 9 should be replaced with your element ID.
    atk = [attacker.int - self.mdef / 2, 0].max
  else
    atk = [attacker.atk - self.pdef / 2, 0].max
  end
end

About skills using common events, basically just choose the common event you want for that skill under the skill tab for the specified skill. There is a drop down box for common events. Just set the common event condition to None (under the Common Event tab) to make it independant from switches, yet still able to run when called.

Hope this gets you any closer.
 
thanks for the replies.

I get what you're saying about the element method and it makes perfect sense. If I was planning to use a lot of different magical weapons, this would be the better way to do things, so I will keep that in mind if I ever have that need. Right now, I'm just testing with the 1, so what I have in place is fine for the time being. But yah... thanks for giving me a way to easily do things if I need more than 1 weapon.

Now on to the common events... I believe I did just as you said, but the skill failed to do anything. Here is exactly what I did step-by-step and let's see if anyone can see why it doesn't work...

1. Created a skill called "Magic Sword"
2. In the Common Event dropdown of the Skill's properties, I selected Common Event #1
3. In Common Event #1, I made certain the Trigger was set to "None"
4. In the code for this Common Event, I placed the script: $game_variables[1] = $game_actors[1].weapon_id
5. Under that, I also selected the Change Weapon command and set the currently-equipped weapon of the main character to Weapon id 2 (which is the weapon slot for the int-based weapon)

When I use the skill in a battle test, it fails to switch the weapon. I'll also give you a screenshot of the Common Event screen in a bit.

http://www.zgqccircle.com/ZG/rmxpscreens.png[/img]

Also on top of this, I still have a question of how to make SP automatically drain by some amount that I specify every round as long as this specific Magic Weapon is equipped.
 
Okay, so the common event should work fine, though, I have experienced problems with event commands right after a call script. Meaning, if you add a Wait 4 (or something of the like) right after the script, it might make it work. Also, please note that the script event command has an error.

If it comes to two lines, as in your script, it will execute them apart from each other. Meaning Variable 0001 didn't get assigned at all.
 
I think the break in the script is just the text wrapping because it doesn't fit on one line. If that causes it not to work, I'm not sure what to do because I can't really make it shorter...

As for the Wait command seperating the script, it didn't seem to work. I also tried taking the script out entirely and making the common event ONLY set the weapon, and it still failed to do so.

The common event never seems to execute for some reason.

EDIT:

I finally figured out my problem. The game wasn't equipping the weapon because the weapon wasn't present! How silly of me. I need to start my Common Event by forcing the Magic Sword into the inventory first and THEN force equipping it. Now I just need to think of a way to make the magical weapon unequip and remove itself from the inventory if either there's no SP left or the battle simply ends. The character's not supposed to possess it out of battle or be able to use it without the required SP.

Also, I need to figure out still how to make the character lose SP for every round she posesses the weapon.
 

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