![]() |
#1 |
Huge Clucker
![]() ![]() ![]() Join Date: Jan 2012
Location: Germany
Posts: 290
Reputation: 47
|
![]()
Intro
So, lately I have seen many people going about this whole damage prevention thing all wrong which is why I'm writing this little tutorial on how to actually achieve damage prevention to a certain degree. I'll explain the options you have for handling damage in general and I'll make you aware of the differences between all available options so you can decide on your own which method suits your needs the best. Without any further ado, let's get right into it. And let me make one thing very clear in the beginning: The only way to make a player invulnerable to all damage is to set his health very high. There is no other reliable (natively implemented) way to bypass the OnPlayerDeath event. Additionally, keep in mind that there are death events hardcoded into the game such as when you die in an exploding car or take fall damage while having an unopened parachute. OnPlayerTakeDamage Of course, when it comes to damage prevention, this callback falls under people's first association. But does it actually serve the purpose? The answer is no. Using OnPlayerTakeDamage for damage prevention is one of the most common errors people do. There are a couple of things you need to understand about this callback.
In which cases is it useful? If you want to script a custom weapon damage system, this callback is a good way to go. BUT: Only if you intend to increase weapon damage! Making a weapon deal less damage than defined in the weapon.dat file will result in the scenario described above. OnPlayerWeaponShot Now, with this callback we're getting somewhere since it can really prevent damage, but not all damage. OnPlayerWeaponShot revolves all around bullet data which means that it can only prevent bullet data from being sent. There are, however, weapons that do not send bullet data, e.g. grenades or rocket launchers. These damage types will not be detected by this callback. Something that is also nice to know is that a player doesn't see that he is being hit by bullets while the callback returns 0, so it is really unfitting for a custom damage system. In which cases is it useful? If you want to make systems that include damaging not only players, but also vehicles and objects, then this is a semi-safe way to go, as it only covers weapons that send bullet data. SetPlayerTeam This is by far the best way to prevent damage since it does not care about any damage types in particular. Setting two players to the same team will prevent all damage between these two entities, both bullet data and explosions caused by the other player. This provides you with a solid foundation for your own damage system and also for a anti health and armor hack. Combined with EnableVehicleFriendlyFire(), this method is the safest way to go. However, be aware of the fact that self-inflicted damage is not prevented which will result in OnPlayerDeath being called. Last edited by Manyula; 02/02/2017 at 03:39 PM. |
![]() |
![]() |
![]() |
#2 |
Big Clucker
![]() ![]() Join Date: Feb 2015
Posts: 164
Reputation: 55
|
![]()
Couldnt you just OnPlayerGiveDamage just set all the weapon values to give 0 damage? lol
|
![]() |
![]() |
![]() |
#3 | ||
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2014
Location: Denmark
Posts: 1,852
Reputation: 114
|
![]() Quote:
You can only reverse the damage by putting his health back when he's hit, but apart from OnPlayerWeaponShot the callbacks are only called afterwards as mentioned. Quote:
|
||
![]() |
![]() |
![]() |
#4 |
Big Clucker
![]() ![]() Join Date: Feb 2015
Posts: 164
Reputation: 55
|
![]()
Very well thanks for the clarification, nice tutorial for those who're unsure.
|
![]() |
![]() |
![]() |
#5 | |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2013
Location: Brazil
Posts: 2,702
Reputation: 246
|
![]() Quote:
Code:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart) { new Float:Health; GetPlayerHealth(damagedid, Health); if(playerid != INVALID_PLAYER_ID) { SetPlayerHealth(damagedid, Health); } return 1; } |
|
![]() |
![]() |
![]() |
#6 | |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2014
Location: Denmark
Posts: 1,852
Reputation: 114
|
![]() Quote:
Say the player that got hit has 30 HP. The damage dealt was 40, killing the player. Then the callback is called with your code which sets his health back to 30, but he's already dead because the callback is called after the damage is already done. |
|
![]() |
![]() |
![]() |
#7 | |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Jun 2013
Location: Brazil
Posts: 2,702
Reputation: 246
|
![]() Quote:
So I used OnPlayerGiveDamage and it did not happen, the player did not die with a greater harm than life itself! Of course I used conditional to check the team and still worked. Verification of the callback seems to be much faster. |
|
![]() |
![]() |
![]() |
#8 |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Oct 2015
Posts: 2,055
Reputation: 494
|
![]()
we can use onplayerupdate for this purpose i think
|
![]() |
![]() |
![]() |
#9 |
Huge Clucker
![]() ![]() ![]() Join Date: Jan 2012
Location: Germany
Posts: 290
Reputation: 47
|
![]()
As already stated by CalcinC, OnPlayerGiveDamage is no different than OnPlayerTakeDamage when it comes to damage prevention. The only difference is that OnPlayerGiveDamage handles damage clientside whereas OnPlayerTakeDamage does it serverside. Generally, I would never recommend letting the client handle damage. As far as I recall, OnPlayerGiveDamage is also called if you shoot someone who is actually out of shot range.
And no, OnPlayerUpdate is the absolute worst way of doing it. Again, it behaves just like the other callbacks. You'd only have to implement an if-clause that checks for incoming damage. The if-clause would be called 30-50 times per second though, so you definitely don't want to be using that. |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[FilterScript] Easy custom damage + damage sound | Voxel | Filterscripts | 14 | 30/09/2013 05:07 PM |
How to detect vehicle damage, and get damage taken? | Micius | Scripting Help | 4 | 31/07/2013 05:08 PM |
How to prevent? | Fernado Samuel | Scripting Help | 2 | 27/03/2013 09:03 AM |
[Include] Car damage system - Damage a car without a driver! | The_Moddler | Includes | 68 | 30/03/2012 02:38 AM |
[Help]Player damage when vehicle damage | jujuv | Help Archive | 6 | 28/12/2010 01:25 AM |