Adding stats
From VbGORE Visual Basic Online RPG Engine
Contents |
This tutorial explains how to add and remove your own stats. How you use these stats is completely up to you - this only displays how to add them in. This example uses the following stats: Int, Wis, Con, Cha and Lck - the 5 stats found in the MMORPG Ragnarok Online. Though, you can of course replace this with any other stat you wish to use, it is all the same.
Adding stats to the server
In the users field in the vbGORE MySQL database, add the following fields by either writing a SQL query or using a MySQL GUI and altering the table manually:
<sql> stat_int - int(10) - unsigned - Default 0 stat_wis - int(10) - unsigned - Default 0 stat_con - int(10) - unsigned - Default 0 stat_cha - int(10) - unsigned - Default 0 stat_lck - int(10) - unsigned - Default 0 </sql>
Now open up GameServer.vbp, go to the DataIDs module and search for:
<vb>
Str As Byte Agi As Byte 'For NPCs, this is the hit rate Mag As Byte Speed As Byte 'Speed works as + (Speed / 2) on the client since just + Speed would be too drastic (8 would double the normal speed)
</vb>
After this line, add the following:
<vb>
Int As Byte Wis As Byte Con As Byte Cha As Byte Lck As Byte
</vb>
This now allows the server and client to reference the stat. This is so you can reference stats by, for example, BaseStat(SID.Int) instead of typing in a number. Not only is this easier to remember, but easier to change and less prone to mistypes. Next, search for:
<vb> Public Const NumStats As Byte = 18 </vb>
And modify the value to the number of stats you have. In this case, we added 5, so we now have 23.
<vb> Public Const NumStats As Byte = 23 </vb>
Next, we have to assign values to the stats. Each stat needs a unique byte value assigned to it, and preferably done in chronological order (don't skip numbers). Search for:
<vb>
.Speed = 18
</vb>
After, add:
<vb>
.Int = 19
.Wis = 20
.Con = 21
.Cha = 22
.Lck = 23
</vb>
Next, we need to load and save the values. First, go to the FileIO module and search for the following, which should be found in sub Load_User:
<vb>
UserList(UserIndex).Stats.ModStat(SID.MaxSTA) = UserList(UserIndex).Stats.BaseStat(SID.MaxSTA)
UserList(UserIndex).Stats.BaseStat(SID.MinHP) = Val(!stat_hp_min)
UserList(UserIndex).Stats.BaseStat(SID.MinMAN) = Val(!stat_mp_min)
UserList(UserIndex).Stats.BaseStat(SID.MinSTA) = Val(!stat_sp_min)
</vb>
After, add:
<vb>
UserList(UserIndex).Stats.BaseStat(SID.Int) = Val(!stat_int)
UserList(UserIndex).Stats.BaseStat(SID.Wis) = Val(!stat_wis)
UserList(UserIndex).Stats.BaseStat(SID.Con) = Val(!stat_con)
UserList(UserIndex).Stats.BaseStat(SID.Cha) = Val(!stat_cha)
UserList(UserIndex).Stats.BaseStat(SID.Lck) = Val(!stat_lck)
</vb>
This will make the values load from the database. Next, search for:
<vb>
DB_RS!stat_mp_min = .Stats.BaseStat(SID.MinMAN)
DB_RS!stat_mp_max = .Stats.BaseStat(SID.MaxMAN)
DB_RS!stat_sp_min = .Stats.BaseStat(SID.MinSTA)
DB_RS!stat_sp_max = .Stats.BaseStat(SID.MaxSTA)
</vb>
After, add:
<vb>
DB_RS!stat_int = .Stats.BaseStat(SID.Int)
DB_RS!stat_wis = .Stats.BaseStat(SID.Wis)
DB_RS!stat_con = .Stats.BaseStat(SID.Con)
DB_RS!stat_cha = .Stats.BaseStat(SID.Cha)
DB_RS!stat_luk = .Stats.BaseStat(SID.Lck)
</vb>
You will now need to make default starting stats for new characters. Search for:
<vb> 'Set the user's starting stats </vb>
It should bring you to this:
<vb>
UserList(UserIndex).Stats.BaseStat(SID.ELU) = 10 UserList(UserIndex).Stats.BaseStat(SID.ELV) = 1 UserList(UserIndex).Stats.BaseStat(SID.Str) = 1 UserList(UserIndex).Stats.BaseStat(SID.Agi) = 1 UserList(UserIndex).Stats.BaseStat(SID.Mag) = 1 UserList(UserIndex).Stats.BaseStat(SID.Speed) = 5 UserList(UserIndex).Stats.BaseStat(SID.Gold) = 100 UserList(UserIndex).Stats.BaseStat(SID.DEF) = 1 UserList(UserIndex).Stats.BaseStat(SID.MinHIT) = 1 UserList(UserIndex).Stats.BaseStat(SID.MaxHIT) = 1 UserList(UserIndex).Stats.BaseStat(SID.MaxHP) = 50 UserList(UserIndex).Stats.BaseStat(SID.MaxMAN) = 50 UserList(UserIndex).Stats.BaseStat(SID.MaxSTA) = 50 UserList(UserIndex).Stats.ModStat(SID.MaxHP) = UserList(UserIndex).Stats.BaseStat(SID.MaxHP) UserList(UserIndex).Stats.ModStat(SID.MaxMAN) = UserList(UserIndex).Stats.BaseStat(SID.MaxMAN) UserList(UserIndex).Stats.ModStat(SID.MaxSTA) = UserList(UserIndex).Stats.BaseStat(SID.MaxSTA) UserList(UserIndex).Stats.BaseStat(SID.MinHP) = 50 UserList(UserIndex).Stats.BaseStat(SID.MinMAN) = 50 UserList(UserIndex).Stats.BaseStat(SID.MinSTA) = 50
</vb>
After those lines, add the following:
<vb> UserList(UserIndex).Stats.BaseStat(SID.Int) = 1 UserList(UserIndex).Stats.BaseStat(SID.Wis) = 1 UserList(UserIndex).Stats.BaseStat(SID.Con) = 1 UserList(UserIndex).Stats.BaseStat(SID.Cha) = 1 UserList(UserIndex).Stats.BaseStat(SID.Lck) = 1 </vb>
This will set the starting value of these stats to 1 for new characters. You can set these stats to whatever value you want the character to start with.
Adding stats to the client
Once your stats are supported on the server, the next step is to display the stats on the client. Thanks to the UserStats class module, this is done very efficiently and automatically. The DataIDs module we edited above is shared between both the client and server, so changes made to one will appear in the other. Just make sure you save the server's code before loading the client for the changes to appear.
Basically, for this section, the stats are already added on the client, so theres nothing to do. All the user's stats can be found in the public arrays BaseStats() and ModStats()
Modding the stats
First, it is important to know what BaseStat and ModStat are. BaseStat is the base value of the user's stat, often how much they have raised it. ModStat, on the other hand, is BaseStat + Modifications. The modifications can come from a variety of things - spells, other stats, equipment, etc. For example, if you had armor that added 5 defence, your ModStat would be BaseStat + 5.
If you want your stats to be affected by status effects and ailments, search for:
<vb> Public Sub User_UpdateModStats(ByVal UserIndex As Integer) </vb>
In this routine, you will see the modifications in the format of If This_Effect Then Modify_These_Stats. For example, if you wanted your luk to be lowered when warcursed, search for:
<vb>
.ModStat(SID.MinHIT) = .ModStat(SID.MinHIT) - (UserList(UserIndex).Skills.WarCurse \ 4)
.ModStat(SID.MaxHIT) = .ModStat(SID.MaxHIT) - (UserList(UserIndex).Skills.WarCurse \ 4)
</vb>
After, add:
<vb>
.ModStat(SID.Luk) = .ModStat(SID.Luk) - (UserList(UserIndex).Skills.WarCurse \ 4)
</vb>
Now, when you get hit by Warcry, your luk will be lowered by 1/4th of the warcry's power.
Keep in mind this is only for users. For NPCs, the equivalent routine can be found by searching for Public Sub NPC_UpdateModStats(ByRef NPCIndex As Integer).