PVP Zones

From VbGORE Visual Basic Online RPG Engine

So, it occurred to me that there should be PVP zones, rather than the whole world being one big battle zone. After all, what player wants to be attacked while accessing their bank or a store?

Map Editor

Go to the TileEngine.bas

Find "Public Type MapInfo" and add to it this:

<vb>PVPzone As Byte</vb>


Go to FrmMapInfo.fm and add a checkbox called IsPVPzone with the caption "PVP Zone". then add a button called "cmdApply" with the caption "Apply" next to it. See the screen shot for example.

Double click Apply button and add this code:

<vb>MapInfo.PVPzone = IsPVPzone.Value</vb>


For those of you using my Player Property script, can copy and paste the apply button used in that tutorial and make it so that the apply button for the property and the apply button for the PVP zone are part of a control array. Ok, sounds sophisticated, but it's simple. Copy the Apply button from the Property tutorial, then right click on the frmMapInfo and hit paste. VB will ask you if you want to make it a control array. Then you hit yes. Then you can use the following code for both apply buttons:

<vb>Private Sub cmdApply_Click(Index As Integer)

   If (Index = 0) Then
       MapInfo.Property = IsProperty.Value
   Else
       MapInfo.PVPzone = IsPVPzone.Value
   End If

End Sub</vb>

Don't worry, that previous step is optional and is meant to keep the code clean, no worries! But there's a screen shot included of my frmMapInfo for your convenience.


ok, back to the PVP Zone tutorial. In the frmMapInfo code, go to "SizeCmd_Click". Find:

<vb> MapInfo.Width = Val(WidthTxt.Text)

   MapInfo.Height = Val(HeightTxt.Text)</vb>

and below it add this:

<vb>MapInfo.PVPzone = IsPVPzone.Value</vb>


Go to General.bas and find:

<vb> frmMapInfo.WidthTxt.Text = MapInfo.Width

   frmMapInfo.HeightTxt.Text = MapInfo.Height</vb>

and below it add this:

<vb>frmMapInfo.IsPVPzone.Value = MapInfo.PVPzone</vb>

Now find this:

<vb>'Get info

   MapInfo.Name = Var_Get(MapEXPath & Map & ".dat", "1", "Name")
   MapInfo.Weather = Val(Var_Get(MapEXPath & Map & ".dat", "1", "Weather"))
   MapInfo.Music = Val(Var_Get(MapEXPath & Map & ".dat", "1", "Music"))</vb>

and below it add this:

<vb>MapInfo.PVPzone = Val(Var_Get(MapEXPath & Map & ".dat", "1", "PVPzone"))</vb>

Then not far below there you will find this "With frmMapInfo". In that section of code, add this:

<vb>.IsPVPzone.Value = MapInfo.PVPzone</vb>

Now go to Game_SaveMapData. Find "'Write .dat file" and change that section of code to this:

<vb>'Write .dat file

   If IsBackup Then
       Var_Write MapEXPath & MapNum & ".dat.bak", "1", "Name", MapInfo.Name
       Var_Write MapEXPath & MapNum & ".dat.bak", "1", "Weather", Str$(MapInfo.Weather)
       Var_Write MapEXPath & MapNum & ".dat.bak", "1", "Music", Str$(MapInfo.Music)
       Var_Write MapEXPath & MapNum & ".dat.bak", "1", "Property", Str$(MapInfo.Property)
       Var_Write MapEXPath & MapNum & ".dat.bak", "1", "PVPzone", Str$(MapInfo.PVPzone)
   Else
       Var_Write MapEXPath & MapNum & ".dat", "1", "Name", MapInfo.Name
       Var_Write MapEXPath & MapNum & ".dat", "1", "Weather", Str$(MapInfo.Weather)
       Var_Write MapEXPath & MapNum & ".dat", "1", "Music", Str$(MapInfo.Music)
       Var_Write MapEXPath & MapNum & ".dat", "1", "Property", Str$(MapInfo.Property)
       Var_Write MapEXPath & MapNum & ".dat", "1", "PVPzone", Str$(MapInfo.PVPzone)
   End If

</vb>

Note, the lines that contain MapInfo.Property are from my Player Property tutorial. Remove those lines if you are not using that tutorial.

Server

Go to FileIO.bas

Go to Load_Maps. Then find "With MapInfo(Map)" and in that section of code add this:

<vb>.PVPzone = Val(Var_Get(MapEXPath & Map & ".dat", "1", "PVPzone"))</vb>


Go to Declares.bas

Find "Type MapInfo" and in that section of code add this:

<vb>PVPzone As Byte 'Can players attack each other on this map?</vb>


Now go to Users.bas. Find this:

<vb>If MapInfo(AttackPos.Map).Data(AttackPos.X, AttackPos.Y).UserIndex > 0 Then</vb>

and replace it with this:

<vb>If MapInfo(AttackPos.Map).Data(AttackPos.X, AttackPos.Y).UserIndex > 0 And MapInfo(AttackPos.Map).PVPzone = 1 Then</vb>



Now locate the sub User_Attack and replace <vb>

   If UserList(UserIndex).WeaponEqpObjIndex > 0 Then
       If ObjData.WeaponRange(UserList(UserIndex).WeaponEqpObjIndex) > 1 Then
           If UserList(UserIndex).Flags.TargetIndex = 0 Then Exit Sub
           User_Attack_Ranged UserIndex
           Exit Sub
       End If
   End If

</vb>

With this <vb>

   'Check for ranged attack
   If UserList(UserIndex).WeaponEqpObjIndex > 0 Then
       If ObjData.WeaponRange(UserList(UserIndex).WeaponEqpObjIndex) > 1 Then
           If UserList(UserIndex).Flags.TargetIndex = 0 Then Exit Sub
           If MapInfo(UserList(UserIndex).Pos.Map).PVPzone = 0 Then Exit Sub
           User_Attack_Ranged UserIndex
           Exit Sub
       End If
   End If

</vb>


That's it! Now players can attack each other only on maps you specify as PVP zones.


A screenshot of the final result:

PVP MapInfo.JPG

This tutorial is made by: GoreMania

Personal tools