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

[EO 2.0] Kill and Death counter with command and NPC kills


JeffHudson
 Share

Recommended Posts

**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 Counter
Dim totalkills As Long
Dim totaldeaths As Long
Dim combatdeaths As Long
Dim 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 Counter
Case "/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 PlayerRec

Add the following code at the bottom of Type PlayerRec (Right before the "End 
Type" statement.)

[code]'Kill Counter
Kill as Long
Dead as Long
NpcKill as Long
NpcDead as Long
EnviroDead 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 Counter
Player(i).Kill = Buffer.ReadLong
Player(i).Dead = Buffer.ReadLong
Player(i).NpcKill = Buffer.ReadLong
Player(i).NpcDead = Buffer.ReadLong
player(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 nothing
Call SetPlayerVital(index, Vitals.HP, 0)[/code]
Add this line between that piece of code and the comment:

[code]'Kill Counter
Player(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 Counter
Kill as Long
Dead as Long
NpcKill as Long
NpcDead as Long
EnviroDead 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 Counter
Player(index).Kill = 0
Player(index).Dead = 0
Player(index).NpcKill = 0
Player(index).NpcDead = 0
Player(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 Counter
Player(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 dead
Call GlobalMsg(GetPlayerName(victim) & " has been killed by " & Name,  BrightRed)[/code]
Add this little code snippet underneath it:

[code]'Kill Counter
Player(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 Counter
Player(attacker).Kill = Player(attacker).Kill + 1
Player(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 Counter
Buffer.WriteLong Player(Index).Kill
Buffer.WriteLong Player(Index).Dead
Buffer.WriteLong Player(Index).NpcKill
Buffer.WriteLong Player(Index).NpcDead
Buffer.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. XD

2/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

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

My bad, SendPlayerData is for server, and your doing it client. ;P

And to fix your issue put:
```
SendRequestPlayerData
```in front of the /killcounter and /deadcounter cases, so like this:
```
'Kill Counter
Call SendRequestPlayerData

Case "/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

@JeffHudson:

> Lol, accidently pasted the url in between the ur and l in the bbcode.  Problem fixed. XD

Yay, 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

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...