Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

On ER now is possible to have more than 1 frame for attacks


Giukko
 Share

Recommended Posts

Hello, I worked to add inside the source code the way to have more then 1 frame during attacks for character and npc.
This study I think is terminated with good results, no more bugs found. All this post is edited again for this final version.

Follow this tutorial step by step to improve your grafical battle system.

`THIRD UPDATE:`

- there was an error on attack timer, now fixed and spells work (see update at point -->4)

`SECOND UPDATE:`

- fixed the speed for attacks based on agility and weapon type (you can see this both inside game mechanics when character fights and by the variable speed of frames during fight)
- fixed the attack damage from the character, so now when you hold down ctrl key, character starts his attack and continuously tryes to give damage at his enemies
Note: from this point is important to better calibrate on which factors is attack speed regulated.

`FIRST UPDATE:` work completed with full code and examples. Simplified instructions, all tested, bugs have been found (I hope ehe) and fixed. The attack animation now works properly.
*Note for developers: the `Sub DrawPlayer` had some process related to AttackSpeed which do not have to stay there, so everything was moved in `Sub ProcessAttacks` and `Public Sub CheckAttack()`
Fixed bugs:
- animation did not work properly - fixed
- if character attacks now he cannot moves until ctrl is pressed.
- attack animations and process are separated from movements.

Here the final result (and below this image you will find the full code):

![](https://i.imgur.com/DfAayxY.gif[/img])

Premise: this code is an approach to give battle animations inside ER and because I needed more bigger space for frames I changed also that part of code, so if you would like to remain at the default frame-cell size of ER, during this tutorial I'll explain and highlight to you what is optional.

* added this optional: if you would like to use 96x96 cell-frame size for your spritesheets, you need to change position at the name of your characters, so you have to go in `modText` and search for sub `DrawPlayerName`, then search for `TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).yOffset ` and put the number `- 55`
than search this one: `TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).yOffset - (Tex_Character(GetPlayerSprite(Index)).Height / 4) ` and put the number `+ 55`

1- optional: first of all download this images, one is a sword paperdoll, and the other one is a character spritesheet:
![alt text](https://i.imgur.com/IllpGLn.png[/img]) ___ ![alt text](https://i.imgur.com/LLu6Vbf.png[/img])

As you can see, cell size is big (96x96 pixel)

2- Install Visual Basic 6 and open ER Client.vpb (Visual Basic Project)

3- `*UPDATED:` Go to `modGameLogic` and after an `end sub` at your choice paste this code:
*Note at this step: inside the code posted below, you need to choice which is the number of the frames that you want for battle (named `.step ` inside the code). Columns into spritesheet are counted from 0 (zero). For example, if you have 6 columns (from 0 to 5) into your spritesheet and you would like to use frame 4 and frame 5 for battle, just use that column numbers. Also, if you would like to have more than two frames for battle, before all edit your png spritesheet, then go inside the code below where are the `.step` and write an `elseif` with the number of the new frame that you need to use.
```
Sub ProcessAttacks(ByVal Index As Long)
Dim AttackSpeed As Long

' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo ErrorHandler

If Player(Index).Attacking = 1 Then

' qui fa cambiare il tipo di frame

Select Case GetPlayerDir(Index)
Case DIR_UP
If Player(Index).yOffset < 0 Then Player(Index).yOffset = 0
Case DIR_DOWN
If Player(Index).yOffset > 0 Then Player(Index).yOffset = 0
Case DIR_LEFT
If Player(Index).xOffset < 0 Then Player(Index).xOffset = 0
Case DIR_RIGHT
If Player(Index).xOffset > 0 Then Player(Index).xOffset = 0
End Select

Player(Index).Moving = 0

If Player(Index).Step = 4 Then
Player(Index).Step = 5
Else
Player(Index).Step = 4
End If

Else
Exit Sub

End If

' Error handler
Exit Sub
ErrorHandler:
HandleError "ProcessAttacks", "modGameLogic", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
```
4- `*UPDATED` Now, again inside `modGameLogic`, search the sub `GameLoop`. You have to find this line: `Dim WalkTimer As Long` after this one put: `Dim AttackSpeed As Long` and `Dim Atimer As Long`.

Then, you have to find this:
`If frmMain.picEventChat.Visible Then
frmMain.picEventChat.Visible = False
End If
End If
End If`
After this, paste this code:
```
' Processa l'input degli attacchi
If ATimer < tick Then

' Process all player attacks on the map
For i = 1 To Player_HighIndex
If IsPlaying(i) Then
Call ProcessAttacks(i)
End If
Next i
' speed from weapon and agility
If GetPlayerEquipment(MyIndex, Weapon) > 0 Then
AttackSpeed = Item(GetPlayerEquipment(MyIndex, Weapon)).speed * 0.5
Else
AttackSpeed = 250 - GetPlayerStat(MyIndex, Agility)
End If

ATimer = tick + AttackSpeed
End If
```
5- `*UPDATED:` Stay into `modGameLogic` and search for sub `CheckAttack()`, so, delete all and paste this code:
```
Public Sub CheckAttack()
Dim Buffer As clsBuffer
Dim AttackSpeed As Long, X As Long, Y As Long, i As Long

' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo ErrorHandler

If Player(MyIndex).Moving > 0 Then Exit Sub

If ControlDown Then

If SpellBuffer > 0 Then Exit Sub ' currently casting a spell, can't attack
If StunDuration > 0 Then Exit Sub ' stunned, can't attack

If Player(MyIndex).Step = 1 Or Player(MyIndex).Step = 3 Then Player(MyIndex).Step = 0

If Player(MyIndex).AttackTimer + (AttackSpeed * 0.5) < GetTick Then
'Now continue to send the attack at server and the attack works
'If Player(MyIndex).Attacking = 0 Then
With Player(MyIndex)
.Attacking = 1
.AttackTimer = GetTick
End With

Set Buffer = New clsBuffer
Buffer.WriteLong CAttack
SendData Buffer.ToArray()
Set Buffer = Nothing
'End If
End If

Select Case Player(MyIndex).Dir
Case DIR_UP
X = GetPlayerX(MyIndex)
Y = GetPlayerY(MyIndex) - 1
Case DIR_DOWN
X = GetPlayerX(MyIndex)
Y = GetPlayerY(MyIndex) + 1
Case DIR_LEFT
X = GetPlayerX(MyIndex) - 1
Y = GetPlayerY(MyIndex)
Case DIR_RIGHT
X = GetPlayerX(MyIndex) + 1
Y = GetPlayerY(MyIndex)
End Select

If GetTick > Player(MyIndex).EventTimer Then
For i = 1 To Map.CurrentEvents
If Map.MapEvents(i).Visible = 1 Then
If Map.MapEvents(i).X = X And Map.MapEvents(i).Y = Y Then
Set Buffer = New clsBuffer
Buffer.WriteLong CEvent
Buffer.WriteLong i
SendData Buffer.ToArray()
Set Buffer = Nothing
Player(MyIndex).EventTimer = GetTick + 200
End If
End If
Next
End If

Else
With Player(MyIndex)
.Attacking = 0
.AttackTimer = 0
End With

If Player(MyIndex).Step >= 4 Then Player(MyIndex).Step = 0

Exit Sub

End If

' Error handler
Exit Sub
ErrorHandler:
HandleError "CheckAttack", "modGameLogic", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
```
6- Again, in `modGameLogic` search for sub `ProcessMovement`, then delete all and paste this code:
```
Sub ProcessMovement(ByVal Index As Long)
Dim MovementSpeed As Long

' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo ErrorHandler

If Player(Index).Attacking = 1 Then Exit Sub

' Check if player is walking, and if so process moving them over
Select Case Player(Index).Moving
Case MOVING_WALKING
PlayerMovement(Index) = 1
MovementSpeed = ((ElapsedTime / 800) * (WALK_SPEED * SIZE_X))
Case MOVING_RUNNING
PlayerMovement(Index) = 2
MovementSpeed = ((ElapsedTime / 800) * ((WALK_SPEED + ((GetPlayerStat(Index, Agility) + (Player(Index).Level / 25)) ^ 0.4)) * SIZE_X))
Case Else
PlayerMovement(Index) = 0
Exit Sub
End Select

If GetPlayerVital(MyIndex, Vitals.Sprint) = 0 Then
Player(Index).Moving = MOVING_WALKING
End If


' qui da la velocità di movimento dell'immagine su schermo, non dei frames
Select Case GetPlayerDir(Index)
Case DIR_UP
Player(Index).yOffset = Player(Index).yOffset - MovementSpeed
If Player(Index).yOffset < 0 Then Player(Index).yOffset = 0
Case DIR_DOWN
Player(Index).yOffset = Player(Index).yOffset + MovementSpeed
If Player(Index).yOffset > 0 Then Player(Index).yOffset = 0
Case DIR_LEFT
Player(Index).xOffset = Player(Index).xOffset - MovementSpeed
If Player(Index).xOffset < 0 Then Player(Index).xOffset = 0
Case DIR_RIGHT
Player(Index).xOffset = Player(Index).xOffset + MovementSpeed
If Player(Index).xOffset > 0 Then Player(Index).xOffset = 0
End Select


' Check if completed walking over to the next tile
If Player(Index).Moving > 0 Then
If GetPlayerDir(Index) = DIR_RIGHT Or GetPlayerDir(Index) = DIR_DOWN Then
If (Player(Index).xOffset >= 0) And (Player(Index).yOffset >= 0) Then
Player(Index).Moving = 0
If Player(Index).Step = 1 Then
Player(Index).Step = 3
Else
Player(Index).Step = 1
End If
End If
Else
If (Player(Index).xOffset <= 0) And (Player(Index).yOffset <= 0) Then
Player(Index).Moving = 0
If Player(Index).Step = 1 Then
Player(Index).Step = 3
Else
Player(Index).Step = 1
End If
End If
End If
End If

' Error handler
Exit Sub
ErrorHandler:
HandleError "ProcessMovement", "modGameLogic", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
```

7- `UPDATED:` Now go to `modGraphics` and search for `DrawPlayer`. Delete all the sub and paste this code:
```
Public Sub DrawPlayer(ByVal Index As Long)
Dim Anim As Byte, i As Long, X As Long, Y As Long
Dim Sprite As Long, spritetop As Long
Dim rec As RECT


' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo ErrorHandler

Sprite = GetPlayerSprite(Index)

If Sprite < 1 Or Sprite > NumCharacters Then Exit Sub


' Reset frame
If Player(Index).Step = 3 Then
Anim = 0
ElseIf Player(Index).Step = 1 Then
Anim = 2
ElseIf Player(Index).Step = 4 Then
Anim = 0
ElseIf Player(Index).Step = 5 Then
Anim = 0
End If


' Check for attacking animation

If Player(Index).Attacking = 1 Then

Anim = Player(Index).Step

Else
' If not attacking, walk normally
Select Case GetPlayerDir(Index)
Case DIR_UP
If (Player(Index).yOffset > 8) Then Anim = Player(Index).Step
'AddText "Step = " & Player(Index).Step, Yellow
Case DIR_DOWN
If (Player(Index).yOffset < -8) Then Anim = Player(Index).Step
'AddText "Step = " & Player(Index).Step, Yellow
Case DIR_LEFT
If (Player(Index).xOffset > 8) Then Anim = Player(Index).Step
'AddText "Step = " & Player(Index).Step, Yellow
Case DIR_RIGHT
If (Player(Index).xOffset < -8) Then Anim = Player(Index).Step
'AddText "Step = " & Player(Index).Step, Yellow
End Select
End If

' Set the left
Select Case GetPlayerDir(Index)
Case DIR_UP
spritetop = 3
Case DIR_RIGHT
spritetop = 2
Case DIR_DOWN
spritetop = 0
Case DIR_LEFT
spritetop = 1
End Select

With rec
.Top = spritetop * (Tex_Character(Sprite).Height / 4)
.Bottom = .Top + (Tex_Character(Sprite).Height / 4)
.Left = Anim * (Tex_Character(Sprite).Width / 6) 'divide il file png nel numero di colonne indicate
.Right = .Left + (Tex_Character(Sprite).Width / 6) 'divide il file png nel numero di colonne indicate
End With


' Calculate the X (centratura dell'immagine e larghezza massima dell'immagine
' per centrare è necessario inserire quante colonne frames per x e quante righe frames per y
X = GetPlayerX(Index) * PIC_X + Player(Index).xOffset - ((Tex_Character(Sprite).Width / 6 - 32) * 0.5)

' Is the player's height more than 32..?
If (Tex_Character(Sprite).Height) > 32 Then
' Create a 32 pixel offset for larger sprites
Y = GetPlayerY(Index) * PIC_Y + Player(Index).yOffset - ((Tex_Character(Sprite).Height / 4) - 32)
Else
' Proceed as normal
Y = GetPlayerY(Index) * PIC_Y + Player(Index).yOffset
End If

' render the actual sprite
Call DrawSprite(Sprite, X, Y, rec)

' Set player's location
playerLocX(Index) = X
playerLocY(Index) = Y

' check for paperdolling
For i = 1 To UBound(PaperdollOrder)
If GetPlayerEquipment(Index, PaperdollOrder(i)) > 0 Then
If Item(GetPlayerEquipment(Index, PaperdollOrder(i))).Paperdoll > 0 Then
Call DrawPaperdoll(Index, X, Y, Item(GetPlayerEquipment(Index, PaperdollOrder(i))).Paperdoll, Anim, spritetop)
End If
End If
Next

' Error handler
Exit Sub
ErrorHandler:
HandleError "DrawPlayer", "modGraphics", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
```
Pay attention inside this code (which is `Public Sub DrawPlayer `) for this two lines:
`.Left = Anim * (Tex_Character(Sprite).Width / 6)`
`.Right = .Left + (Tex_Character(Sprite).Width / 6)`

I changed the original number 4 with (whatever is) the number of columns inside character spritesheet. In this tutorial I used 6 columns, so I putted 6 instead of the original 4 columns.


8- Go to `modGraphics` and search for sub `DrawPaperdoll`. Search inside this sub for those two lines:
` .Left = Anim * (Tex_Paperdoll(Sprite).Width / 4)`
`.Right = .Left + (Tex_Paperdoll(Sprite).Width / 4)`

and change the number 4 with whatever is the number of columns inside your paperdoll spritesheet. In this tutorial I used 6 columns (both for character and paperdoll), so put 6 instead of 4.

9- that's it, have fun ;)
Link to comment
Share on other sites

@kouga Eheh thanks, the new battle frames are added on the right of the spritesheet (png file). Actually I'm checking for possible bugs and I need to fix better the graphic result about the final animation.

Anyway with this method is possible to use as many frames as you would like ;)) And this is also valid for walking animation. Also I will improve (with the same method) animations during spell casting. I also improved the cell-space of every frame, in order also to use more long weapons. As written before, when I'll finish the tests, I'll publish the source code with an explanation ;)
Link to comment
Share on other sites

@mohenjo-daro Hi Mohenjo, it is possible to prepare a png spritesheet with more columns in order to have as many frames you need to use. For exaple you could create two new frames for battle, and two new frames for casting spells. Than, when you have a character model, you can use it in order to create via Photoshop as many npc you need, or just using for example arms of your first character model to make a new spritesheet with battle animation also for npc. Anyway, I'll show you everything, also with images, when I finish to fix some stuffs. Actually, I do not find a way to fix the target-image, which appears when mouse pointer is a little too far from the character or npc target. I'll update you soon, any suggestion is welcome and also any help ;)
Link to comment
Share on other sites


Hello,

Oh great the system! If I understand correctly, that means that we can put Sprites like this:
![alt text](http://nsa39.casimages.com/img/2018/03/17/180317073436415323.png) ?

As you can see here, there are the frames of steps, those for the attack and last ones for the magic ;)
PS: Sorry for my english if he is bad, I speak french x)
Link to comment
Share on other sites

@alexoune001 Hi alexoune001, no problem for your english, I'm italian and also my english is very bad eheh ;) About your question: yes, is possible. I finished to check everything, in few minutes I'll publish the all code and explanations. My code right now works and I made many test, so seem that there are no bugs for now eheh. Anyway I hope that Mohenjo, which is a more good programmer, will help us to perfectioning the code if needed ;) Now I prepare the tutorial and I post everything, step by step :)
Link to comment
Share on other sites

@giukko said in [On ER now is possible to have more than 1 frame for attacks](/post/701478):
> @alexoune001 Hi alexoune001, no problem for your english, I'm italian and also my english is very bad eheh ;) About your question: yes, is possible. I finished to check everything, in few minutes I'll publish the all code and explanations. My code right now works and I made many test, so seem that there are no bugs for now eheh. Anyway I hope that Mohenjo, which is a more good programmer, will help us to perfectioning the code if needed ;) Now I prepare the tutorial and I post everything, step by step :)

Ok, super anyway thank you for your code! Since the time I tried to do but hey I'm not too stalled in vb6 ^^
Link to comment
Share on other sites

Ok, no, right now all the png files must have a space for battle frames, but I think that with a little code improvement and variables it is possible to say at the software if that character or npc as 6 or more, or less columns inside png file. Anyway this is a start point, now I post everything, I'm preparing all the stuffs in order to post them
Link to comment
Share on other sites

Updated (see my first post) and finished all the code and informations on how to use more then one frames in battle for ER. With this instructions is possible to modify also battle frames for npc by adding a line of code. Check, and if you have questions or if you would like, let me know ;)
Link to comment
Share on other sites

Updated full code to the final version :) Now everything is fixed and work well. First post totally edited.

Fixed bugs:

- animation did not work properly - fixed
- if character attacks now he cannot moves until ctrl is pressed.
- attack animations and process are separated from movements.
Link to comment
Share on other sites


ANOTHER UPDATE: see first post (I hope this is the last one ;) )


- fixed the speed for attacks based on agility and weapon type (you can see this both inside game mechanics when character fights and by the variable speed of frames during fight)
- fixed the attack damage from the character, so now when you hold down ctrl key, character starts his attack and continuously tryes to give damage at his enemies
Note: from this point is important to better calibrate on which factors is attack speed regulated.
Link to comment
Share on other sites

  • 1 year later...
beside the last parameter, try putting a ``` , ``` and see if you have to insert anything else on there.

Or try inserting
```
DrawPaperdoll index, x, y, item(GetPlayerEquipment(index, PaperdollOrder(i))).paperdoll, anim, spritetop
```
sometimes removing ```call``` and the brackets work for me
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...