Raised This Month: $12 Target: $400
 3% 

How to modified the damage type of a gun?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chu1720
Senior Member
Join Date: Mar 2010
Location: Hong Kong
Old 07-20-2010 , 11:50   How to modified the damage type of a gun?
Reply With Quote #1

if i use the following code in the hooked even "player_hurt", the vitim will first will be hurted by a normal damage type (damge type =2 if he is hurted by a gun), then followed by a specified damage type. How can i just replaced the first shoot in stead of add the second added shoot?
PHP Code:
HookEvent("player_hurt"Event_PlayerHurt);

public 
Action:Event_InfectedHurt(Handle:eventString:event_name[], bool:dontBroadcast)
{
    new 
victim GetEventInt(event"entityid");
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
dmg GetEventInt(event"amount");
    new 
dmgtype GetEventInt(event"type");
    
    if (
IsValidClient(attacker))
    {
        if(
GetClientTeam(attacker) == TEAM_SURVIVORS && !IsFakeClient(attacker) && dmgtype != 1024)
        {
            
//力量效果
            
new Float:StrDamage dmg*Str[attacker]*0.01;
            
DealDamage(victim,StrDamage,attacker,1024,"Damge_Add");
        }
    }
    return 
Plugin_Continue;
}

DealDamage(victim,Float:damage,attacker=0,dmg_type=0,String:weapon[]="")
{
    if(
IsValidEdict(victim) && damage>0)
    {
        new 
String:dmg_str[16];
        
FloatToString(damage,dmg_str,16);
        new 
String:dmg_type_str[32];
        
IntToString(dmg_type,dmg_type_str,32);
        new 
PointHurt CreateEntityByName("point_hurt");
        if(
PointHurt)
        {
            
DispatchKeyValue(victim,"targetname","dmged_target");
            
DispatchKeyValue(PointHurt,"DamageTarget","dmged_target");
            
DispatchKeyValue(PointHurt,"Damage",dmg_str);
            
DispatchKeyValue(PointHurt,"DamageType",dmg_type_str);
            if(!
StrEqual(weapon,""))
            {
                
DispatchKeyValue(PointHurt,"classname",weapon);
            }
            
DispatchSpawn(PointHurt);
            
AcceptEntityInput(PointHurt,"Hurt",(attacker>0)?attacker:-1);
            
DispatchKeyValue(PointHurt,"classname","point_hurt");
            
DispatchKeyValue(victim,"targetname","nondmged_target");
            
RemoveEdict(PointHurt);
        }
    }

chu1720 is offline
Send a message via MSN to chu1720
chu1720
Senior Member
Join Date: Mar 2010
Location: Hong Kong
Old 07-22-2010 , 21:57   Re: How to modified the damage type of a gun?
Reply With Quote #2

no one?
chu1720 is offline
Send a message via MSN to chu1720
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 07-23-2010 , 03:35   Re: How to modified the damage type of a gun?
Reply With Quote #3

Not possible, when the "player_hurt" event is fired, the victim has already been damaged. Try healing the victim and attacking it again?

Try hooking it before it happens (EventHookMode_Pre) and see if you can block the damage. But im pretty sure isn't possible.

Also, if you don't want 2 hist at the same time, try doing this:

Code:
new client = GetClientOfUserId(GetClientInt(event, "userid"));
new damage = GetEventInt(event, "damage_health");
new prevhealth = GetClientHealth(client) + damage;

//Additional damage
new total = prevhealth -(damage*multiplier);
SetEntityHealth(client, total);
honorcode23 is offline
Peoples Army
SourceMod Donor
Join Date: Mar 2007
Old 07-23-2010 , 03:42   Re: How to modified the damage type of a gun?
Reply With Quote #4

If you did use hook event you would use the pre hook

PHP Code:


HookEvent
("player_hurt",FunctionNameEventHookMode_Pre); 
__________________
Peoples Army is offline
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 07-23-2010 , 04:15   Re: How to modified the damage type of a gun?
Reply With Quote #5

You could just use SDKHooks's OnTakeDamage and change the damage type

Last edited by noodleboy347; 07-23-2010 at 04:18.
noodleboy347 is offline
chu1720
Senior Member
Join Date: Mar 2010
Location: Hong Kong
Old 07-23-2010 , 05:23   Re: How to modified the damage type of a gun?
Reply With Quote #6

Quote:
Originally Posted by honorcode23 View Post
Not possible, when the "player_hurt" event is fired, the victim has already been damaged. Try healing the victim and attacking it again?

Try hooking it before it happens (EventHookMode_Pre) and see if you can block the damage. But im pretty sure isn't possible.

Also, if you don't want 2 hist at the same time, try doing this:

Code:
new client = GetClientOfUserId(GetClientInt(event, "userid"));
new damage = GetEventInt(event, "damage_health");
new prevhealth = GetClientHealth(client) + damage;

//Additional damage
new total = prevhealth -(damage*multiplier);
SetEntityHealth(client, total);
But then the additinal damage is not casued by, other plugins that make use of the damage will be not accurate. And it may happen that the victim is not killed by me.
chu1720 is offline
Send a message via MSN to chu1720
Monkeys
Veteran Member
Join Date: Jan 2010
Old 07-23-2010 , 11:07   Re: How to modified the damage type of a gun?
Reply With Quote #7

Using the normal player_hurt event won't work. As most have said, even if this uses the EventHookeMode_Pre, it won't fire in time for the plugin to stop the players death. You could only stop the deathmessage, and perhaps heal up but that I doubt.

noodleboy's right, you should use SDKHooks' OnTakeDamage, which can be modified in many ways.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
chu1720
Senior Member
Join Date: Mar 2010
Location: Hong Kong
Old 07-23-2010 , 11:59   Re: How to modified the damage type of a gun?
Reply With Quote #8

Quote:
Originally Posted by Monkeys View Post
Using the normal player_hurt event won't work. As most have said, even if this uses the EventHookeMode_Pre, it won't fire in time for the plugin to stop the players death. You could only stop the deathmessage, and perhaps heal up but that I doubt.

noodleboy's right, you should use SDKHooks' OnTakeDamage, which can be modified in many ways.
Thanks so much! I will try it later.
chu1720 is offline
Send a message via MSN to chu1720
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:45.


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