JeffHudson Posted February 6, 2012 Author Share Posted February 6, 2012 **INTRO**>! First, allow me the opportunity to thank [iHero](http://www.touchofdeathforums.com/smf/index.php?action=profile;u=38908) for creating the base code and saving me numerous headaches in writing it from scratch. I took his tutorial and used the basic outline to create this counter. There are a couple of differences in what we counted, and how we displayed the counter. iHero opted to send a player message on each PvP kill or death with the updated count, whereas I decided to go a step further and eliminate the messages, and instead created to /commands for it. (The messages would have driven me crazy after a while.) I also added in the ability to count NPC kills, deaths from NPCs, and the good old environmental death counter. The environmental death counter adds on each time someone calls the Sub OnDeath. By typing in /killcounter it will display your number of PvP kills, NPC kills, and your total kills. If you type in /deathcounter it will display the number of PvP deaths, deaths by NPC, combat deaths, environmental deaths, and total deaths. I also clarified a few confusing area's that iHero had in his tutorial. (Specifically, when he said find this piece of code, and never mentioned what file it was located in. It took me a little while to run searches on all the areas to find them. Lol.) Anyways, I hope you all enjoy my first script, even though it's not much more than an edit with some added functionality. Thank you again, iHero, for saving me a lot of headaches in writing this from scratch, and if you for some reason want me to take this down then feel free to say so. XD>! Michael W.>! [Original Post from iHero](http://www.touchofdeathforums.com/smf/index.php/topic,77730.0.html)**CLIENT SIDE**Open the client.vbp file with Visual Basic 6 and edit the modInput.bas file. Find the Sub HandleKeyPresses. After you find that scroll down to the last of the "Dim" statements. Specifically:```Dim Buffer As clsBuffer```After you find that add this code snippet to the bottom of them "Dim" statements:```'Kill CounterDim totalkills As LongDim totaldeaths As LongDim combatdeaths As LongDim alldeaths As Long'Calls updated varibles (THANKS ERWIN!)SendRequestPlayerData```After you add them in, scroll down a little more until you see the following code:```Select Case Command(0) Case "/help" Call AddText("Social Commands:", HelpColor) Call AddText("'msghere = Broadcast Message", HelpColor) Call AddText("-msghere = Emote Message", HelpColor) Call AddText("!namehere msghere = Player Message", HelpColor) Call AddText("Available Commands: /info, /who, /fps, /fpslock", HelpColor)```Now we are going to edit the last line of that code snippet so it reads as follows:```Call AddText("Available Commands: /info, /who, /fps, /fpslock, /killcounter, /deathcounter", HelpColor)```This allows your new users to type /help in the chat box and it will list the available commands to them. We are going to add one called /kdcounter, although you can name it whatever you want. Now that the above line has been edited, lets proceed to create another case for /killcounter and one more for /deathcounter. Find this piece of code:```Case "/stats" Set Buffer = New clsBuffer Buffer.WriteLong CGetStats SendData Buffer.ToArray() Set Buffer = Nothing```Now add this piece of code in between that and the comment below it.```'Kill CounterCase "/killcounter"totalkills = Player(MyIndex).Kill + Player(MyIndex).NpcKill Call AddText("Player Kills: " + Str(Player(i).Kill), HelpColor) Call AddText(" NPC Kills: " + Str(Player(MyIndex).NpcKill), HelpColor) Call AddText(" Total Kills: " + Str(totalkills), HelpColor)Case "/deathcounter" combatdeaths = Player(MyIndex).Dead + Player(MyIndex).NpcDead alldeaths = combatdeaths + Player(MyIndex).EnviroDead Call AddText("Killed by Player : " + Str(Player(MyIndex).Dead), HelpColor) Call AddText("Killed by NPC : " + Str(Player(MyIndex).NpcDead), HelpColor) Call AddText("Total Combat Deaths : " + Str(combatdeaths), HelpColor) Call AddText("Environmental Deaths: " + Str(Player(MyIndex).EnviroDead), HelpColor) Call AddText("Total Deaths : " + Str(alldeaths), HelpColor)```Alright, close out of modInput.bas and open modTypes.bas for editing. Inside modTypes.bas find the following piece of code:```Private Type PlayerRecAdd the following code at the bottom of Type PlayerRec (Right before the "End Type" statement.)[code]'Kill CounterKill as LongDead as LongNpcKill as LongNpcDead as LongEnviroDead as Long[/code]Next open modHandleData.bas for editing and find:[code]Call SetPlayerPK(i, Buffer.ReadLong)[/code]Now to add a couple of lines of code immediately below that:[code]'Kill CounterPlayer(i).Kill = Buffer.ReadLongPlayer(i).Dead = Buffer.ReadLongPlayer(i).NpcKill = Buffer.ReadLongPlayer(i).NpcDead = Buffer.ReadLongplayer(i).EnviroDead = Buffer.ReadLong[/code]Finally time to save and generate the client.exe file. Save the project, the go to File > Make Eclipse Origins.exe. Hopefully it compiles with no errors. (It did for me, done this at two in the morning after having had 2.5 hours of sleep in two days...)[b]SERVER SIZE[/b]Next let us open the server.vbp file. After you open the Server Project edit modPlayer.bas and find the Sub OnDeath. Find this chunk of code in that Sub:[code]' Set HP to nothingCall SetPlayerVital(index, Vitals.HP, 0)[/code]Add this line between that piece of code and the comment:[code]'Kill CounterPlayer(index).EnviroDead = Player(index).EnviroDead + 1[/code]Close out of modPlayer.bas and open modTypes.bas for editing. Find the same line as we did on the client side, specifically:[code]Private Type PlayerRec[/code]Add the following code right above the "End Type" statement:[code]'Kill CounterKill as LongDead as LongNpcKill as LongNpcDead as LongEnviroDead as long[/code]Close out of modTypes.bas and open modDatabase.bas. In the Sub AddChar find:[code]Player(index).Vital(Vitals.HP) = GetPlayerMaxVital(index, Vitals.HP)Player(index).Vital(Vitals.MP) = GetPlayerMaxVital(index, Vitals.MP)[/code]Now insert the following lines of code in between that and the commented line below it:[code]'Kill CounterPlayer(index).Kill = 0Player(index).Dead = 0Player(index).NpcKill = 0Player(index).NpcDead = 0Player(index).EnviroDead = 0[/code]Exit out of modDatabase.bas and open modCombat.bas for editing. (Not too much more stuff then we will be done. XD) Find the sub PlayerAttackNpc and look for this bit of code:[code]If Damage >= MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP) Then SendActionMsg GetPlayerMap(attacker), "-" & MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP), BrightRed, 1, (MapNpc(mapNum).Npc(mapNpcNum).x * 32), (MapNpc(mapNum).Npc(mapNpcNum).y * 32) SendBlood GetPlayerMap(attacker), MapNpc(mapNum).Npc(mapNpcNum).x, MapNpc(mapNum).Npc(mapNpcNum).y[/code]Add the following code snippet between that and the comment:[code]'Kill CounterPlayer(attacker).NpcKill = Player(attacker).NpcKill + 1[/code]Next find the Sub NpcAttackPlayer (Should be four Subs down) and look for this bit of code:[code]' Player is deadCall GlobalMsg(GetPlayerName(victim) & " has been killed by " & Name, BrightRed)[/code]Add this little code snippet underneath it:[code]'Kill CounterPlayer(victim).NpcDead = Player(victim).NpcDead + 1[/code]Now go down to what should be three Subs lower (PlayerAttackPlayer) and find this piece of code:[code]If exp = 0 Then Call PlayerMsg(victim, "You lost no exp.", BrightRed) Call PlayerMsg(attacker, "You received no exp.", BrightBlue)Else Call SetPlayerExp(victim, GetPlayerExp(victim) - exp) SendEXP victim Call PlayerMsg(victim, "You lost " & exp & " exp.", BrightRed)[/code]Add the following code right below it (Right before the comment):[code]'Kill CounterPlayer(attacker).Kill = Player(attacker).Kill + 1Player(victim).Dead = Player(victim).Dead + 1[/code]Close out of modCombat.bas and open modServerTCP.bas. Next find this bit of code:[code]Buffer.WriteLong GetPlayerPK(Index)[/code]Add this code below it and above the For statement:[code]'Kill CounterBuffer.WriteLong Player(Index).KillBuffer.WriteLong Player(Index).DeadBuffer.WriteLong Player(Index).NpcKillBuffer.WriteLong Player(Index).NpcDeadBuffer.WriteLong Player(Index).EnviroDead[/code]Save the project and go to File > Make Server.exe. Hopefully it compiles with no errors and you should be ready to rock and roll. Start the server then the client, log in and in the chat box type /help to verify that the edit we did worked then type /killcounter or /deathcounter (or whatever you named the cases) and verify it shows your kills and deaths as it's supposed to. Kill some random mess and get killed once or twice and make sure it works. Haven't had time to beta test mine or his, just made sure it compiled with no errors. CONSTRUCTIVE criticism is welcome; DESTRUCTIVE criticism, trolls, and flamers will be promptly reported. I hope you all enjoy. XD2/6/12: Edited the code to fix an invalid type error. Forgot to convert the varibles under modInput.bas to a string.2/8/12: Finally fixed the issue of having to call the command twice or logging on and off to update the stats. Huge thanks to [url]Erwin[/url] for assisting me with that. I probably would still be looking for where to add the statement. Anyways, code is updated. Now it is time to get to work on the items in the poll. Starting with a crazy cat forcing people to choose that option. *Heads to drawing board and coffee pot...*``` Link to comment Share on other sites More sharing options...
erkro1 Posted February 7, 2012 Share Posted February 7, 2012 Try:```Call SendPlayerData(index)```for updating kills/deaths Link to comment Share on other sites More sharing options...
JeffHudson Posted February 8, 2012 Author Share Posted February 8, 2012 Thanks for that Erwin, umm I couldn't call that function for some reason though, so I called SendRequestPlayerData. It somewhat fixed the issue, the only problem is I have to type my command twice to get the updated status. It works better than what I had, but for the life of me cannot figure out why I can't call that function. (I'm supposed to call it in the command right?)Anyways, I couldn't update the code tonight, but to get the code to the point where I am, add this line```SendRequestPlayerData```Immediately after the /killcounter and /deathcounter cases in **modInput.bas**Thanks again Erwin. Link to comment Share on other sites More sharing options...
erkro1 Posted February 8, 2012 Share Posted February 8, 2012 My bad, SendPlayerData is for server, and your doing it client. ;PAnd to fix your issue put:```SendRequestPlayerData```in front of the /killcounter and /deadcounter cases, so like this:```'Kill CounterCall SendRequestPlayerDataCase "/killcounter"totalkills = Player(MyIndex).Kill + Player(MyIndex).NpcKill Call AddText("Player Kills: " + Str(Player(i).Kill), HelpColor) Call AddText(" NPC Kills: " + Str(Player(MyIndex).NpcKill), HelpColor) Call AddText(" Total Kills: " + Str(totalkills), HelpColor)Case "/deathcounter" combatdeaths = Player(MyIndex).Dead + Player(MyIndex).NpcDead alldeaths = combatdeaths + Player(MyIndex).EnviroDead Call AddText("Killed by Player : " + Str(Player(MyIndex).Dead), HelpColor) Call AddText("Killed by NPC : " + Str(Player(MyIndex).NpcDead), HelpColor) Call AddText("Total Combat Deaths : " + Str(combatdeaths), HelpColor) Call AddText("Environmental Deaths: " + Str(Player(MyIndex).EnviroDead), HelpColor) Call AddText("Total Deaths : " + Str(alldeaths), HelpColor)``` Link to comment Share on other sites More sharing options...
JeffHudson Posted February 9, 2012 Author Share Posted February 9, 2012 I updated the main post to fix that issue, it works good for me. If anyone has issues post it here and I will see if I can find out why. Thanks again Erwin, you have been a big help with that irritating issue. Link to comment Share on other sites More sharing options...
erkro1 Posted February 9, 2012 Share Posted February 9, 2012 Your welcome, and my profile link in the main post isn't working. ;P Link to comment Share on other sites More sharing options...
JeffHudson Posted February 10, 2012 Author Share Posted February 10, 2012 Lol, accidently pasted the url in between the ur and l in the bbcode. Problem fixed. XD Link to comment Share on other sites More sharing options...
erkro1 Posted February 10, 2012 Share Posted February 10, 2012 @JeffHudson:> Lol, accidently pasted the url in between the ur and l in the bbcode. Problem fixed. XDYay, also, the link in your signature doesn't work too.And a small advice for your poll; never put stupid answers in it (A crazy cat made me push this option…), people would always vote for that and that doesn't help you. ;) Link to comment Share on other sites More sharing options...
JeffHudson Posted February 11, 2012 Author Share Posted February 11, 2012 Fixing that now, and edited the poll, didn't realize that it would erase the results, but so far a window to display the stats is in the lead. BB code is just different enough from html to mess me up. Link to comment Share on other sites More sharing options...
Domino_ Posted February 18, 2012 Share Posted February 18, 2012 Good tutorial, also this would be more fun with ranking panel or smtn like that when you go to trainer and in speech window he shows you top 5 players with most kills. :) Link to comment Share on other sites More sharing options...
JeffHudson Posted February 18, 2012 Author Share Posted February 18, 2012 Hmm, that is a route I never considered. I will see what I can cook up, though. Thanks for the feedback, as it makes me want to put out a few more basic scripts/tutorials for the noob programmers here. Link to comment Share on other sites More sharing options...
Esmeyana Posted February 21, 2012 Share Posted February 21, 2012 I have a similar system as this, but I also added a counter for the resources and made a level system of it.Like if you cut out 100 rocks you will get lvl 2 mining..I also made a slayer level system of the 'killing NPC counter'. Link to comment Share on other sites More sharing options...
JeffHudson Posted February 22, 2012 Author Share Posted February 22, 2012 I plan to eventually incorporate some form of a level system like you mentioned, but for the tutorial I figured I would do something simple. Now for an update, I almost got the window displaying the stats done, just got some tweaks to do, and lay it out nicely. 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