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

[EO] CanPlayerBlock Shield Algorithm


The New World
 Share

Recommended Posts

In this tutorial we'll be replacing the current "commented" system for CanPlayerBlock, by making a new algorithm using the players shields statistics.

This modification will take place **Server-Side**, only.

In modCombat, find the sub _CanPlayerBlock_.

By default (EO 2b) It should look similar to this in a clean download.
```
Public Function CanPlayerBlock(ByVal index As Long) As Boolean
Dim rate As Long
Dim rndNum As Long

    CanPlayerBlock = False

    rate = 0
    ' TODO : make it based on shield lol

End Function

```
We're modifying the enter sub to look like this:

```
Public Function CanPlayerBlock(ByVal index As Long) As Boolean
Dim rate As Long
Dim rndNum As Long
Dim shieldNum as long

    CanPlayerBlock = False

    rate = 0

    If GetPlayerEquipment(index, Shield) > 0 Then
        shieldNum = GetPlayerEquipment(index, Shield)
        rate = Item(shieldNum).Data2 / 43.3
        rndNum = RAND(1, 100)
        If rndNum <= rate Then
            CanPlayerBlock = True
        Else
            CanPlayerBlock = False
        End If
    Else
        rate = 0.5
        rndNum = RAND(1, 100)
        If rndNum <= rate Then
            CanPlayerBlock = True
        Else
            CanPlayerBlock = False
        End If
    End If
End Function

```
Now, to break it down for you. :) (Note: We're only covering the modifications!)

```
If GetPlayerEquipment(index, Shield) > 0 Then
```
Here we check IF the player attempting to block is in possession of a shield type item, and if so move on!

```
shieldNum = GetPlayerEquipment(index, Shield)
```
At the beginning of the sub, we defined a new variable "shieldNum" as a long data type, and here we give it a numeric value. We're giving the variable "shieldNum" the "Item ID" of the shield the player has equipped at this moment, so we can process that certain items statistical data.

```
rate = Item(shieldNum).Data2 / 43.3
```
At the beginning of the sub, the variable rate was defined, here we are giving this variable a value as well. To attain the value we're using the item function to get the Data2, or "damage" statistic of the shield the player has equipped currently, and we're dividing that value by 43.3, then the final value is assigned to the variable "rate".

```
rndNum = RAND(1, 100)
```
Here we just assign the variable rndNum a random value between 1 and 100.

```
If rndNum <= rate Then
```
Here we check if the random number value is less than or equal to that of the rate value, and if it is, continue!

```
CanPlayerBlock = True
```
Here we tell the server, yes, the Player CAN block, by assigning the  Boolean variable, as true.

```
Else
              CanPlayerBlock = False

```
This is just to make damned sure that the variable gets set to false because they algorithm did not come out with the value we wanted for a successful block. :)

The next few statements do the same process, for a player whom is not equipped with a shield at that moment to find out if they can block or not. :P
Link to comment
Share on other sites

  • 1 year later...
```
Public Function CanPlayerBlock(ByVal index As Long) As Boolean
Dim rate As Long
Dim rndNum As Long
Dim shieldNum as long

    CanPlayerBlock = False

    rate = 0

    If GetPlayerEquipment(index, Shield) > 0 Then
        shieldNum = GetPlayerEquipment(index, Shield)
        rate = Item(shieldNum).Data2 / 43.3
        rndNum = RAND(1, 100)
        If rndNum <= rate Then
            CanPlayerBlock = True
        Else
            CanPlayerBlock = False
        End If
    Else
        rate = 0.5
        rndNum = RAND(1, 100)
        If rndNum <= rate Then
            CanPlayerBlock = True
        Else
            CanPlayerBlock = False
        End If
    End If
End Function

```Look in here.
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...