AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to intercept amount of damage? (https://forums.alliedmods.net/showthread.php?t=27039)

Wolle 04-13-2006 17:58

How to intercept amount of damage?
 
How do you intercept the amount of damage that is about to be substracted from the receivers health and modify it?

SweatyBanana 04-13-2006 17:59

you can modify bullet damage..

you can give players back the health they lose.

dont know if thats what you want..

Wolle 04-13-2006 18:02

Actually yes.
At the moment I dont care what inflicts damage and how.
I just want to intercept the amount of damage (caused by whatever) that is about to be substracted from the players health and modify it.
How would you do that?

p3tsin 04-13-2006 19:07

if u dont want to add health back later on (coz the player could die before that :) ), u can directly modify the damage:

Code:
register_message(get_user_msgid("Damage"), "hook_damage") .. public hook_damage(msg_id, msg_dest, entity) {     new dmg = get_msg_arg_int(2)     new type = get_msg_argtype(2)     set_msg_arg_int(2,type, dmg/3)     return PLUGIN_CONTINUE }

that should reduce the damage made to third of the original :o

Wolle 04-13-2006 19:24

I see!!!
That gives me something to work with.
Thanks!

++karma ;

Wolle 04-13-2006 20:14

I see 2 flaws.
1. Damage caused by something else than weapons (gravity) isn't indicated.
2. The new health has also already been set.
2.1. Your
Code:
set_msg_arg_int(2,type, dmg/3)
suggestion doesn't seem to work.

There doesn't seem to be a way to do what I want to do.

p3tsin 04-14-2006 04:31

hmm.. events registered with register_message() are called just before they occur, so i dont see why modifying the damage doesnt work :?
although changing damagetype to something else works

the function does get called for me when i fall, except when dmg >= health (the player dies, so thats another wrong assumption by me)

also seems that the event cant even be blocked with PLUGIN_HANDLED, which is even more weird..
i just thought hooking it with register_message() would be as simple as any other message, guess i was wrong, sry :(

VEN 04-14-2006 05:14

Quote:

also seems that the event cant even be blocked with PLUGIN_HANDLED
You can block Damage message which sends to the client but you can't block actual damage with that method. When Damage message is sent server already "damaged" a player.

Wolle 04-14-2006 08:35

Quote:

Originally Posted by p3tsin
...guess i was wrong, sry :(

Don't worry p3tsin you can keep the ++karma anyway!! :wink:
Just too bad that this isnt possible.
Is there a way to realize that through different module code?
I mean writing a module that allows to do what I want to do?
If yes, where am I gonna find a good introduction tutorial to module coding?
If no, where am I gonna find it anyway? :D

EDIT:
Nvm my last 2 questions.
Looks like the guide in the docs is pretty good.
:oops: :D

Hawk552 04-14-2006 10:45

The only way I was able to intercept damage when I needed to was by setting every person's HP to 1024, and then working with their HP. This means that if you want them dead, you can just add some code that's basically like:

Code:
if(iDamage >= 100)      user_kill(id)

Or whatever. You can also reset their HP to 1024 every time they get hit. Or you can check if their HP is:

Code:
if(iHealth < 9024)      user_kill(id)

You'll have to use messages to let clients know that they didn't just suicide.


All times are GMT -4. The time now is 05:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.