AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Proper way to deal damage without extensions (https://forums.alliedmods.net/showthread.php?t=111684)

API 12-14-2009 17:35

Re: Proper way to deal damage without extensions
 
Why are you creating the event? It will automatically occur if you use DealDamage()
Also, I don't think you can make it headshot unfortunately, maybe a hook inside player_hurt to force a headshot might?

psychonic 12-14-2009 17:39

Re: Proper way to deal damage without extensions
 
Quote:

Originally Posted by TerroriZe (Post 1017134)
I got 2 questions :shock::

1.) Can you fake headshot damage as well? I basically want to create fake damage which kills somebody with a headshot...

Probably not. Most games rely on hitgroup for that from a trace. There does not appear to be any hitgroup key to set on the point_hurt entity.
http://developer.valvesoftware.com/wiki/Point_hurt

Quote:

Originally Posted by TerroriZe (Post 1017134)
I got 2 questions :shock::
2.) Im a bit confused... why is this method failing? ->

Code:

new Handle:event_hurt = CreateEvent("player_hurt");
SetEventInt(event_hurt, "userid", GetClientUserId(victim));
SetEventInt(event_hurt, "attacker", GetClientUserId(client));
SetEventInt(event_hurt, "dmg_health", health+1);
SetEventString(event_hurt, "weapon", weapon);
SetEventBool(event_hurt, "headshot", headshot);
FireEvent(event_hurt);

And how to use it, if not like that?

Events are just notifications. They get fired after the event actually happens and only exist to notify the server, client, and/or any plugins with event listeners that the event occurred. Firing the player_hurt event manually would lie that the player was hurt, but they would not actually take damage or lose health.

TerroriZe 12-14-2009 17:58

Re: Proper way to deal damage without extensions
 
ah ok thanks both of you.. that helped alot ^_^

This got me confused: http://wiki.alliedmods.net/Events_%2...d_Scripting%29

voogru 12-17-2009 19:30

Re: Proper way to deal damage without extensions
 
Quote:

Originally Posted by pimpinjuice (Post 1015426)
Because I love you.

Code:

#define DMG_GENERIC                        0
#define DMG_CRUSH                        (1 << 0)
#define DMG_BULLET                        (1 << 1)
#define DMG_SLASH                        (1 << 2)
#define DMG_BURN                        (1 << 3)
#define DMG_VEHICLE                        (1 << 4)
#define DMG_FALL                        (1 << 5)
#define DMG_BLAST                        (1 << 6)
#define DMG_CLUB                        (1 << 7)
#define DMG_SHOCK                        (1 << 8)
#define DMG_SONIC                        (1 << 9)
#define DMG_ENERGYBEAM                        (1 << 10)
#define DMG_PREVENT_PHYSICS_FORCE        (1 << 11)
#define DMG_NEVERGIB                        (1 << 12)
#define DMG_ALWAYSGIB                        (1 << 13)
#define DMG_DROWN                        (1 << 14)
#define DMG_TIMEBASED                        (DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN)
#define DMG_PARALYZE                        (1 << 15)
#define DMG_NERVEGAS                        (1 << 16)
#define DMG_POISON                        (1 << 17)
#define DMG_RADIATION                        (1 << 18)
#define DMG_DROWNRECOVER                (1 << 19)
#define DMG_ACID                        (1 << 20)
#define DMG_SLOWBURN                        (1 << 21)
#define DMG_REMOVENORAGDOLL                (1 << 22)
#define DMG_PHYSGUN                        (1 << 23)
#define DMG_PLASMA                        (1 << 24)
#define DMG_AIRBOAT                        (1 << 25)
#define DMG_DISSOLVE                        (1 << 26)
#define DMG_BLAST_SURFACE                (1 << 27)
#define DMG_DIRECT                        (1 << 28)
#define DMG_BUCKSHOT                        (1 << 29)

DealDamage(victim,damage,attacker=0,dmg_type=DMG_GENERIC,String:weapon[]="")
{
        if(victim>0 && IsValidEdict(victim) && IsClientInGame(victim) && IsPlayerAlive(victim) && damage>0)
        {
                new String:dmg_str[16];
                IntToString(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","war3_hurtme");
                        DispatchKeyValue(pointHurt,"DamageTarget","war3_hurtme");
                        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","war3_donthurtme");
                        RemoveEdict(pointHurt);
                }
        }
}

Example usage:
Code:

DealDamage(victim_index,50,attacker_index,DMG_BULLET,"weapon_ak47");
Works for CSS and TF2, should work for all games.

Creating and deleting an entity every time you do a damage call is a little inefficient IMO.

If you really wanted to use this method, I'd spawn a point_hurt one time at map start and then always use that entity rather than constantly respawning them.

And even then, I'd only do that in the absence of the extension that does it properly.

Just my opinion dont mind me :)

Sammy-ROCK! 12-17-2009 20:56

Re: Proper way to deal damage without extensions
 
Then it would need to be integrated with your plugin and not a simple snippet.

Darkimmortal 12-23-2009 00:32

Re: Proper way to deal damage without extensions
 
I take it there's no way to deal damage from the client to themselves with this?

Specifically in conjunction with pyro flamethrower to create a jetpack effect in PropHunt.

CrancK 12-23-2009 11:43

Re: Proper way to deal damage without extensions
 
if you kill people using damage like this, making the attacker another client, what kill-message would come up (tf2 particularly?)

the weapon the attacker is currently holding? or a world kill message?

also, i'm guessing this way painsounds automatically play?
(my previous method of dealing damage made use of SetEntityHealth, and thus had no sound, which i had to provide for it :shock:)

edit: ohw, also... does this damage push a player?

Sammy-ROCK! 12-23-2009 16:07

Re: Proper way to deal damage without extensions
 
A suicide message like when a soldier kills himself with a rocket?

Dragonshadow 12-24-2009 09:39

Re: Proper way to deal damage without extensions
 
Quote:

Originally Posted by Darkimmortal (Post 1027857)
I take it there's no way to deal damage from the client to themselves with this?

Specifically in conjunction with pyro flamethrower to create a jetpack effect in PropHunt.


When I kill myself with damage from myself to myself with the demoman bottle it gives me a kill message like this:

|Bottle Icon| |My name|

API 12-24-2009 15:14

Re: Proper way to deal damage without extensions
 
Quote:

Originally Posted by CrancK (Post 1028328)
if you kill people using damage like this, making the attacker another client, what kill-message would come up (tf2 particularly?)

the weapon the attacker is currently holding? or a world kill message?

also, i'm guessing this way painsounds automatically play?
(my previous method of dealing damage made use of SetEntityHealth, and thus had no sound, which i had to provide for it :shock:)

edit: ohw, also... does this damage push a player?

Yes, with this function proper death messages occur, as well as stat plugin compatibility.
DealDamage(victim_index,50,attacker_index,DMG _BULLET,"weapon_ak47");

That would make the engine think victim_index was shot for 50 damage (armor distribution works too) with an AK47 used by attacker_index. You can have alot of fun experimenting with Damage type as well.


All times are GMT -4. The time now is 18:42.

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