AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to modified the damage type of a gun? (https://forums.alliedmods.net/showthread.php?t=132951)

chu1720 07-20-2010 11:50

How to modified the damage type of a gun?
 
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 07-22-2010 21:57

Re: How to modified the damage type of a gun?
 
no one?

honorcode23 07-23-2010 03:35

Re: How to modified the damage type of a gun?
 
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);


Peoples Army 07-23-2010 03:42

Re: How to modified the damage type of a gun?
 
If you did use hook event you would use the pre hook

PHP Code:



HookEvent
("player_hurt",FunctionNameEventHookMode_Pre); 


noodleboy347 07-23-2010 04:15

Re: How to modified the damage type of a gun?
 
You could just use SDKHooks's OnTakeDamage and change the damage type

chu1720 07-23-2010 05:23

Re: How to modified the damage type of a gun?
 
Quote:

Originally Posted by honorcode23 (Post 1248807)
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.

Monkeys 07-23-2010 11:07

Re: How to modified the damage type of a gun?
 
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.

chu1720 07-23-2010 11:59

Re: How to modified the damage type of a gun?
 
Quote:

Originally Posted by Monkeys (Post 1249098)
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.


All times are GMT -4. The time now is 19:15.

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