First, you will need a sprite of the character attacking with a sword, along with the Hendrix Animation Solution and Hendrix Keyboard Gamepad plugins. You just need to enable them. The Animation Solution is used to break the animation limits of RPG Maker, and the Keyboard Gamepad allows you to map any key on both the keyboard and the gamepad.
We will create a conditional branch Input.isTriggered('a'). If the player presses A, we will change the graphic of the player and run the slashing animation by using Movement Route playFrames(1, 6, 3). This means I'll play from the first frame to the last frame with a speed of waiting 3 frames between changing to the next frame.
So, we've completed the animation part for the character. Now, we need to make the sword capable of dealing damage to enemies. We will use Create Dynamic Events plugin command to create an event that lasts for 3 frames with the notetag <weaponAttack>. Why don't I use <dmg> here? You could use it as well, but there's a way to make the system automatically use weapon damage from the database. After that, don't forget to change the player graphic back to idle one.
In the common event for enemy collision from previous tutorials, let's add a conditional branch to check for collision with the notetag <weaponAttack> and leave the HP Change field blank; instead, we select "Use Weapon DMG slot1", and that's it.
This method is very quick, but not overly accurate, because we create the hitbox before/after the animation runs. We don't want monsters to take damage before the player has swung their weapon, nor do we want the damage to be applied only after the player has completed the slashing animation. If your game doesn't require high precision, this method is quite convenient.