[TUT] Recording Damage/Hits Per-Round and Displaying It
This tutorial has been written under the assumption that you are a
Alright, let's get straight to the point. The following will teach you how to create your own damage recording system that will reset every round. If you've ever played in ESEA, this is extremely similar (if not exactly) like the .dmg command. Let's begin with the top. PHP Code:
We also have RESET_DELAY. This is the time after round start that the damage count will be reset. Most importantly, we have our two variables that eventually will be holding the damage amount that tells the plugin how much damage was received and taken for each player. The two array sizes (MAX_PLAYERS+1) are necessary to hold player-specific data. We also have the HitsGiven variable, pretty self-explanatory. You will see b_CanTypeWhileAlive in use later on. Finally, there's g_iMaxPlayers which will be used in accordance with IsPlayer. Let's move on, shall we? PHP Code:
g_iMaxPlayers obtains the maximum players, which will be used with IsPlayer, as said earlier. Next! PHP Code:
First off, you'll notice the IsPlayer being put to use. This macro makes sure that the specified attacker is a player, and not the map or other entity. Without this check, there's a strong possibility that an excessive amount of The macro up top makes sure the player is within the player range, since each player is given an imaginary number on connect (correct me if I'm wrong, anybody), and we check to see if they're between 0 and 32 (legitimate player range). Next, we have our two variables. These two will be holding the amount of damage given and recieved. The two indexes hold the players involved in the damage. Also, pev( victim, pev_dmg_take ) is getting the ACTUAL amount of damage taken after taken into consideration the armor and other factors of the victim (thanks to Connor, Arkshine, and Bugsy). Finally, there's iHitsTaken and iHitsGiven to record the amount of hits given and taken, just to make your life more difficult. Alright, the following two blocks of code are going to be a bit more difficult to comprehend, but I'll try my best to explain them in simple terms. PHP Code:
Now, the rest of the code may come off as a bit confusing if you're new. What I'm doing at first is getting the amount of players in-game and then declaring a new variable that will hold the name and message that will be sent. I then initiate the for loop, declaring a new variable, making the conditional, and then the increment. This declares the new variable, then checks the conditional. If the conditional is true, it executes the code inside the block. After that, it executes the third param of the loop, and repeats from the 2nd param. When the conditional is false, it ends the for loop. Inside the for loop, I check if the current player it's looping through is the player we're display it to, and if the player's team is the same as the player we're looping through. If it is, we continue to the next iteration (go back to the conditional) of the loop. Otherwise, we get their name, and format a message that we'll be displaying to the player. It will look something like Code:
[Wrecked] Given: ( 49 Damage / 2 Hits ) Taken: ( 100 Damage / 4 Hits ) We then display the message to the user (%s means replace it with a string), and return PLUGIN_CONTINUE to let the say command run through and let everyone else see what the original client command was. Phewf! Next! PHP Code:
The RoundStart function sets the delay to reset the player data if it's defined. If it's not, the function automatically calls TASK_ResetStats to reset the player damage / hit data. The bool lets players type .damage until the player stats are reset in the following function. So, as you can see, it's a quite extensive function, as it has 2 for loops, but it really isn't much code at all. What I'm doing is;
So, we reset the player data in relation to the original player index with the new player index in relation to the secondary player index. If you have any personal questions on this function, let me know and I'll explain it more in-depth. So, our final plugin should look something like this: PHP Code:
Alright, well, I'm off to go begin my new life as a lemon. Good bye. |
Re: Recording Damage/Hits Per-Round and Displaying It
yes :p
|
Re: Recording Damage/Hits Per-Round and Displaying It
Great job wrecked.
|
Re: Recording Damage/Hits Per-Round and Displaying It
Just to let you know that damage param passed in TakeDamage is not the real damage taken/given, to retrieve the real damage done, you have to check pev_dmg_take value in TakeDamage post registered.
You could also hook Damage event as well. |
Re: Recording Damage/Hits Per-Round and Displaying It
Quote:
|
Re: Recording Damage/Hits Per-Round and Displaying It
It holds the original damage value. pev_dmg_take is the final damage after considering armor and other things.
|
Re: Recording Damage/Hits Per-Round and Displaying It
Quote:
Also, csx should provide some natives that can give you all information. |
Re: Recording Damage/Hits Per-Round and Displaying It
Oh, interesting, I'll look into that pev.
Thanks guys. |
Re: [TUT] Recording Damage/Hits Per-Round and Displaying It
pev_dmg_take is normally a float, but you can retrieve its integer value using it as if it was an integer, pev(victim, pev_dmg_take) will work fine.
Also, if you look at HLSDK, TakeDamage returns the damage done, but it's not the case on counter-strike. You could extend your snippet to specific weapon damage save ;) But first, double check that you can't achieve this with csx module, because you would make it for nothing. |
Re: [TUT] Recording Damage/Hits Per-Round and Displaying It
1 Attachment(s)
hi! wrecked_ I have tried to implement this code in the yap mode but i did not succeed when you start a new round tells me that i have done no harm in that round you puts my code help please!
PHP Code:
|
All times are GMT -4. The time now is 15:15. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.