Justn Posted January 11, 2015 Author Share Posted January 11, 2015  Hello this is a tutorial requested by [Strik3R](http://www.eclipseorigins.com/community/index.php?/user/42684-strik3r/) . We will be adding a new player vital (hunger) that will decrease over time and a player can die if they don't eat. We are also adding to the consumable items so you can eat and get full. Basically this only for hunger. To add thirst just do the tutorial again changing Hunger to Thirst.This tutorial was made with EVB. If you are using EO you just need to change all the TimeGetTime's to "gettickcount" (without the quotes). If you cant get this to work let me know.**Client and Server****ModTypes**In PlayerRec before End Type add this :```'Player Vitals New    HungerTimer As Long```In ItemRec before End Type add this:```addHunger As Long    effectHunger As Long```**ModEnumerations**Add this to the bottom of the server packet list```SPlayerHunger```Next find this:```' Vitals used by Players, Npcs and Classes Public Enum Vitals    HP = 1    MP```Under it add this:```Hunger```The above steps must be done both in the client and the server!**Client****ModGameEditors**Find this :```If frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_CONSUME Then            frmEditor_Item.fraVitals.visible = True            frmEditor_Item.scrlAddHp.value = .AddHP            frmEditor_Item.scrlAddMP.value = .AddMP            frmEditor_Item.scrlAddExp.value = .AddEXP            frmEditor_Item.scrlCastSpell.value = .CastSpell            frmEditor_Item.chkInstant.value = .instaCast```Under it add this:``` frmEditor_Item.scrlAddHunger.value = .addHunger  frmEditor_Item.scrleffecthunger.value = .effectHunger```**ModHandleData**In InitMessages add this to the bottom of the rest:```HandleDataSub(SPlayerHunger) = GetAddress(AddressOf HandlePlayerHunger)```At the bottom of ModHandleData add this:```Private Sub HandlePlayerHunger(ByVal index As Long, ByRef data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long) Dim buffer As clsBuffer    ' If debug mode, handle error then exit out    If Options.Debug = 1 Then On Error GoTo errorhandler       Set buffer = New clsBuffer    buffer.WriteBytes data()    Player(MyIndex).MaxVital(Vitals.Hunger) = buffer.ReadLong    Call SetPlayerVital(MyIndex, Vitals.Hunger, buffer.ReadLong) Select Case Player(MyIndex).Vital(Vitals.Hunger)           Case 0            frmMain.lblHunger.Caption = "Dead"        Case 1 To 20            frmMain.lblHunger.Caption = "Starving"        Case 21 To 40            frmMain.lblHunger.Caption = "Very Hungry"        Case 41 To 60            frmMain.lblHunger.Caption = "Hungry"        Case 61 To 80            frmMain.lblHunger.Caption = "Slightly Hungry"        Case 81 To 100            frmMain.lblHunger.Caption = "Full"    End Select    ' Error handler    Exit Sub errorhandler:    HandleError "HandlePlayerHunger", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext    Err.Clear    Exit Sub End Sub```**Server****modDatabase**In Sub AddChar find these lines:```Player(index).Dir = DIR_DOWN         Player(index).Map = Class(Player(index).Class).StartMap        Player(index).x = Class(Player(index).Class).StartMapX        Player(index).y = Class(Player(index).Class).StartMapY        Player(index).Dir = DIR_DOWN        Player(index).Vital(Vitals.HP) = GetPlayerMaxVital(index, Vitals.HP)        Player(index).Vital(Vitals.MP) = GetPlayerMaxVital(index, Vitals.MP)```Under it add this:```Player(index).Vital(Vitals.Hunger) = GetPlayerMaxVital(index, Vitals.Hunger)```**modServerTCP**find this:```Select Case Vital        Case HP            Buffer.WriteLong SPlayerHp            Buffer.WriteLong GetPlayerMaxVital(index, Vitals.HP)            Buffer.WriteLong GetPlayerVital(index, Vitals.HP)        Case MP            Buffer.WriteLong SPlayerMp            Buffer.WriteLong GetPlayerMaxVital(index, Vitals.MP)            Buffer.WriteLong GetPlayerVital(index, Vitals.MP)```Under it add this:```Case Hunger            Buffer.WriteLong SPlayerHunger            Buffer.WriteLong GetPlayerMaxVital(index, Vitals.Hunger)            Buffer.WriteLong GetPlayerVital(index, Vitals.Hunger)```**modServerLoop**Find this:```For i = 1 To Player_HighIndex            If IsPlaying(i) Then                If Tick > tmr25 Then```Under it add this:```' hunger timer                    If Tick > Player(i).HungerTimer Then                    If Player(i).Vital(Vitals.Hunger) > 0 Then                        ' remove 1 hunger point                        Player(i).Vital(Vitals.Hunger) = Player(i).Vital(Vitals.Hunger) - 1                            If Player(i).Vital(Vitals.Hunger) < 0 Then Player(i).Vital(Vitals.Hunger) = 0                            If Player(i).Vital(Vitals.Hunger) = 0 Then                            KillPlayer i                            End If                        Call SendVital(i, Vitals.Hunger) ' for every 30,000 in tick                        Player(i).HungerTimer = timeGetTime + 30000                    End If                    End If```**modPlayer**Find this in sub OnDeath:```' Restore vitals    Call SetPlayerVital(index, Vitals.HP, GetPlayerMaxVital(index, Vitals.HP))    Call SetPlayerVital(index, Vitals.MP, GetPlayerMaxVital(index, Vitals.MP))```Under it add this:```Call SetPlayerVital(index, Vitals.Hunger, GetPlayerMaxVital(index, Vitals.Hunger))```Right under that you should see:```Call SendVital(index, Vitals.HP)    Call SendVital(index, Vitals.MP)```Under those two lines add this:```Call SendVital(index, Vitals.Hunger)```In sub UseItem in the consumeable case find this:```' add exp                If Item(ItemNum).AddEXP > 0 Then                    SetPlayerExp index, GetPlayerExp(index) + Item(ItemNum).AddEXP                    CheckPlayerLevelUp index                    SendActionMsg GetPlayerMap(index), "+" & Item(ItemNum).AddEXP & " EXP", White, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32                    SendEXP index                End If```Under it add this:```' add hunger             If Item(ItemNum).addHunger > 0 Then              Player(index).Vital(Vitals.Hunger) = Player(index).Vital(Vitals.Hunger) + Item(ItemNum).addHunger              If Player(index).Vital(Vitals.Hunger) > GetPlayerMaxVital(index, Vitals.Hunger) Then Player(index).Vital(Vitals.Hunger) = GetPlayerMaxVital(index,Vitals.Hunger)                    SendActionMsg GetPlayerMap(index), "mmmm", BrightGreen, ACTIONMSG_SCROLL, GetPlayerX(index) * 32, GetPlayerY(index) * 32                    SendVital index, Hunger                End If                ' effect hunger                If Item(ItemNum).effectHunger > 0 Then                    Player(index).Vital(Vitals.Hunger) = Player(index).Vital(Vitals.Hunger) - Item(ItemNum).effectHunger                   If Player(index).Vital(Vitals.Hunger) < 0 Then Player(index).Vital(Vitals.Hunger) = 0                   ' SendActionMsg GetPlayerMap(Index), "mmmm", BrightGreen, ACTIONMSG_SCROLL, GetPlayerX(Index) * 32, GetPlayerY(Index) * 32                    SendVital index, Hunger                End If```**modCombat**In GetPlayerMaxVital you will see this:```Case HP            Select Case GetPlayerClass(index)                Case 1 ' Warrior                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Endurance) / 2)) * 15 + 150                Case 2 ' Magician                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Endurance) / 2)) * 5 + 65                Case Else ' Anything else - Warrior by default                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Endurance) / 2)) * 15 + 150            End Select        Case MP            Select Case GetPlayerClass(index)                Case 1 ' Warrior                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Intelligence) / 2)) * 5 + 25                Case 2 ' Magician                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Intelligence) / 2)) * 30 + 85                Case Else ' Anything else - Warrior by default                    GetPlayerMaxVital = ((GetPlayerLevel(index) / 2) + (GetPlayerStat(index, Intelligence) / 2)) * 5 + 25            End Select```Under it add this:(please note you can add whatever formula to get the max hunger like they do for mp and hp I just used a set amount at the current time)```Case Hunger            Select Case GetPlayerClass(index)            Case 1 ' Warrior                    GetPlayerMaxVital = 100                Case Else ' Anything else - Warrior by default                    GetPlayerMaxVital = 100            End Select```**Client Form Work**Now the way I currently have this base the player's hunger level is displayed as a text on frmMain. I did this for myself as I plan to add moodles for displaying hunger levels when i finish the graphics. But you can use bars such as the hp/mp/xp bars its very simple if you look at how they are handled if you need any help ask me and i will add it.**frmMain**Add a new Label anywhere on frmMain, name it: lblHunger**frmEditor_Item**Find the frame : **fraVitals**Add two new scrollbars and two labels above them in the frame.Name one scrollbar : scrlAddHungerDouble click this scrollbar and add this code:```' If debug mode, handle error then exit out    If Options.Debug = 1 Then On Error GoTo errorhandler       lblAddHunger.Caption = "+Hunger: " & scrlAddHunger.value    Item(EditorIndex).addHunger = scrlAddHunger.value       ' Error handler    Exit Sub errorhandler:    HandleError "scrlAddHunger_Change", "frmEditor_Item", Err.Number, Err.Description, Err.Source, Err.HelpContext    Err.Clear    Exit Sub```Name the label above this scroll bar: lblAddHungerSet the caption to this: +Hunger: 0Name the next scroll bar this: scrleffecthungerDouble click the scrollbar and add the following code:```' If debug mode, handle error then exit out    If Options.Debug = 1 Then On Error GoTo errorhandler       lbleffecthunger.Caption = "-Hunger: " & scrleffecthunger.value    Item(EditorIndex).effectHunger = scrleffecthunger.value       ' Error handler    Exit Sub errorhandler:    HandleError "scrleffecthunger_Change", "frmEditor_Item", Err.Number, Err.Description, Err.Source, Err.HelpContext    Err.Clear    Exit Sub```Name the label above this one : lbleffecthungerSet the caption to this: -Hunger: 0And that should be it. If I missed anything please let me know and do know you can customize this anyway you want to fit your game =) Link to comment Share on other sites More sharing options...
SkywardRiver Posted January 11, 2015 Share Posted January 11, 2015 Looks good. Nice work :D Link to comment Share on other sites More sharing options...
Officer Johnson Posted January 11, 2015 Share Posted January 11, 2015 Nice work justn :) Link to comment Share on other sites More sharing options...
Mohenjo Daro Posted January 11, 2015 Share Posted January 11, 2015 Dang, I might think about using this! Thanks! Link to comment Share on other sites More sharing options...
hammer Posted January 11, 2015 Share Posted January 11, 2015 good job man! am on this let me try to implement on my source Link to comment Share on other sites More sharing options...
My Brave Shine Posted January 30, 2015 Share Posted January 30, 2015 ow, Nice Work, really. U can add in Graphic one Display to Hunger Bar. Is really good this! Link to comment Share on other sites More sharing options...
Pablo Dolce Posted February 14, 2015 Share Posted February 14, 2015 I have a problem, I get the following error:Â "Compile error, method or data member not found". And mark me wrong thereCan you help me?. Sorry for my english, i speak spanish, lol :3Picture: [http://oi58.tinypic.com/mug1o8.jpg](http://oi58.tinypic.com/mug1o8.jpg) Link to comment Share on other sites More sharing options...
Helladen Posted February 14, 2015 Share Posted February 14, 2015 > Picture: [http://oi58.tinypic.com/mug1o8.jpg](http://oi58.tinypic.com/mug1o8.jpg)You need to add the control to the actual form. Link to comment Share on other sites More sharing options...
Pablo Dolce Posted February 14, 2015 Share Posted February 14, 2015 And how I do that? I'm new to vb6\. Can you explain step by step? Link to comment Share on other sites More sharing options...
Helladen Posted February 14, 2015 Share Posted February 14, 2015 > And how I do that? I'm new to vb6\. Can you explain step by step?You add a control to the form visually, it is a basic part of working with **VIsual Basic 6**. You have to rename the control to the right name, right click it and go to **Properties**.![](http://i.imgur.com/H6EIlNz.gif) Link to comment Share on other sites More sharing options...
Tic Tac 2 Posted April 28, 2015 Share Posted April 28, 2015 I have a problem. Sometimes, Hunger will stop draining for people. I'm not sure when this happens, but if somebody could look at the code to see what's wrong, that would help a lot.DEBUGGINGEdit1: Tried shutting of the server abruptly, this does not stop the timers from going down. Link to comment Share on other sites More sharing options...
lurv Posted August 21, 2015 Share Posted August 21, 2015 My engine doesn't really save the items Addhunger or effecthunger data. Any idea what i've done wrong? Link to comment Share on other sites More sharing options...
GalacticGlum Posted August 21, 2015 Share Posted August 21, 2015 @'lurv':> My engine doesn't really save the items Addhunger or effecthunger data. Any idea what i've done wrong?Go over the code again. Maybe see if you did something wrong and accidentally forgot that part of the code. Link to comment Share on other sites More sharing options...
lurv Posted August 21, 2015 Share Posted August 21, 2015 @'GalacticGlum':> @'lurv':> > > My engine doesn't really save the items Addhunger or effecthunger data. Any idea what i've done wrong?> > Go over the code again. Maybe see if you did something wrong and accidentally forgot that part of the code.I did before i posted and couldn't seem to figure out what i did wrong.Now as a temp solution i create cases for consume items in Sub UseItem and manually add SetPlayerVital(index, hunger) + enter hunger here Link to comment Share on other sites More sharing options...
Aurelijus1 Posted October 30, 2015 Share Posted October 30, 2015 why i'am getting error in server side modPlayer Run-time error '9': subscript out of range on this line when trying to connect to server :```For i = 0 To ResourceCache(GetPlayerMap(index)).Resource_Count``` Link to comment Share on other sites More sharing options...
lurv Posted January 8, 2016 Share Posted January 8, 2016 Hey, I'm back and i've done this tutorial three timesHunger randomly stops counting down for players(Haven't worked out what the problem is)Usually takes from a couple of hours to two days ish to happenDone this one two engines (Final frontier and Skywyre), same thing happens Link to comment Share on other sites More sharing options...
Mohenjo Daro Posted January 9, 2016 Share Posted January 9, 2016 Sounds like you're having a looping issue, make sure that you put it in the right spot, the loop may have been changed in the engine you're working with Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now