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

Solved Trigger Ham_Killed from Ham_TakeDamage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-22-2016 , 10:13   Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #1

Hey guys! I got a code for a grenade launcher and it uses ExecuteHamB with Ham_TakeDamage to dish out the damage to be dealt. The death message reads that the player got killed by a "worldspawn " and I was hoping of making a custom DeathMsg for it.

I've researched around and think Ham_Killed is the best way to do it. But I can't find any example code and am very new to HamSandwich.

I need the Ham_Killed to detect if the player in Ham_TakeDamage gets killed and then execute some code. Can you guys help me?...

Last edited by hellmonja; 06-25-2017 at 04:22. Reason: Solved...
hellmonja is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-22-2016 , 11:41   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #2

One way of doing this would be by using make_deathmsg
EpicMonkey is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2016 , 11:43   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #3

Quote:
Originally Posted by hellmonja View Post
Hey guys! I got a code for a grenade launcher and it uses ExecuteHamB with Ham_TakeDamage to dish out the damage to be dealt. The death message reads that the player got killed by a "worldspawn " and I was hoping of making a custom DeathMsg for it.

I've researched around and think Ham_Killed is the best way to do it. But I can't find any example code and am very new to HamSandwich.

I need the Ham_Killed to detect if the player in Ham_TakeDamage gets killed and then execute some code. Can you guys help me?...
Give use the plugin, or at least the ExecuteHamB(Ham_TakeDamage,....) line.
__________________
HamletEagle is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-22-2016 , 11:49   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #4

sorry about that, I forgot to include the plugin

PHP Code:
    for(new 0get_maxplayers(); i++)
    {
        if(!
is_user_alive(i))
            continue
        
pev(ipev_originOrigin2)
        if(
get_distance_f(OriginOrigin2) > float(GRENADE_RADIUS))
            continue

        
ExecuteHamB(Ham_TakeDamagei0pev(entpev_owner), float(GRENADE_DAMAGE), DMG_BULLET)
    } 
that's the portion of the code where it does the damage. it starts in line 646. I've also attached the plugin itself in case you need the whole thing...
Attached Files
File Type: sma Get Plugin or Get Source (ap-groza.sma - 549 views - 26.6 KB)

Last edited by hellmonja; 04-22-2016 at 11:50.
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-22-2016 , 11:58   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #5

Quote:
Originally Posted by EpicMonkey View Post
One way of doing this would be by using make_deathmsg
thanks. i actually know how to make a custom deathmsg, but the damage has to be dished out normally by the game itself (ie. getting hit by a bullet). i don't know how to do it if the plugin itself is creating the damage.

the other thing about this is, the weapon is an OTs-14 Groza with a GP-30 Grenade Launcher attached. so there's actually 2 ways to kill a player with this single weapon. the Groza's deathmsg works fine. it's the GP-30 that's giving the "worldspawn" deathmsg and i'm hoping to fix that...
hellmonja is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-22-2016 , 12:04   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #6

PHP Code:
ExecuteHamB(Ham_TakeDamagei0pev(entpev_owner), float(GRENADE_DAMAGE), DMG_BULLET
it's about the third parameter, which is 0 here. That's the inflictor, or the entity that caused damage. For guns, it's same as the player, but for other entities (like grenades), it's the entity itself.

What you could do is create an entity with your desired classname before you execute TakeDamage, and input its index in that 3rd param, and then remove that entity afterwards.
klippy is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-22-2016 , 12:39   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #7

Quote:
Originally Posted by KliPPy View Post
PHP Code:
ExecuteHamB(Ham_TakeDamagei0pev(entpev_owner), float(GRENADE_DAMAGE), DMG_BULLET
it's about the third parameter, which is 0 here. That's the inflictor, or the entity that caused damage. For guns, it's same as the player, but for other entities (like grenades), it's the entity itself.

What you could do is create an entity with your desired classname before you execute TakeDamage, and input its index in that 3rd param, and then remove that entity afterwards.
Ok so it works, meaning if I change it, the information on the DeathMsg changes as well. I tested it by replacing "0" with "CSW_HEGRENADE" (i know, but just bear with me a bit) and it read player was killed by "player". I'm trying to replace it so it would look like he died of a hand grenade, FOR NOW. I regrettably admit that I do not know what I am doing and how to create and remove an entity. Sorry for being such an idiot. As of now i'm googling how to create one.

By the way, please don't laugh at my plugin. That came from Dias' OICW plugin but i've added a substantial amount of code there that you guys might find perplexing or even laughable...

Last edited by hellmonja; 04-22-2016 at 12:41.
hellmonja is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-22-2016 , 13:12   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #8

PHP Code:
new Entity create_entity("weapon_hegrenade")
ExecuteHamB(Ham_TakeDamageiEntity, .......)  
remove_entity(Entity
__________________
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-22-2016 , 13:25   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #9

Quote:
Originally Posted by hellmonja View Post
Ok so it works, meaning if I change it, the information on the DeathMsg changes as well. I tested it by replacing "0" with "CSW_HEGRENADE" (i know, but just bear with me a bit) and it read player was killed by "player". I'm trying to replace it so it would look like he died of a hand grenade, FOR NOW. I regrettably admit that I do not know what I am doing and how to create and remove an entity. Sorry for being such an idiot. As of now i'm googling how to create one.
CSW_HEGRENADE is not an entity index (or any other CSW_* constant), they are weapon indexes, which is totally different from entity indexes.
What you did there is put 4 (CSW_HEGRENADE is equal to 4) as inflictor in there, which is a "player" entity as they are in entity slots 1 through 32.

Quote:
Originally Posted by hellmonja View Post
By the way, please don't laugh at my plugin. That came from Dias' OICW plugin but i've added a substantial amount of code there that you guys might find perplexing or even laughable...
No worries, nobody is going to laugh at it, you are here to learn.

Last edited by klippy; 04-22-2016 at 13:25.
klippy is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 04-23-2016 , 13:43   Re: [HELP] Trigger Ham_Killed from Ham_TakeDamage
Reply With Quote #10

sorry i took so long to reply. it actually worked but i wanted to test it thoroughly so i know what to say when i get back here. ok so now i'm going to try and elaborate in case others are researching this as well. the code now looks like this:

PHP Code:
        new Entity create_entity("weapon_hegrenade")
        
ExecuteHamB(Ham_TakeDamageiEntitypev(entpev_owner), float(GRENADE_DAMAGE), DMG_BULLET)
        
remove_entity(Entity
like you guys said, create an entity and use for Ham_TakeDamage them remove it later. i didn't even have to use Ham_Killed. with that said, i edited my DeathMsg code:

PHP Code:
    if(equalszWeapon"aug" ) && g_Has_Groza[iAttacker]) set_msg_arg_string(4"groza")
    if(
equalszWeapon"hegrenade" )) set_msg_arg_string(4"gp30"
the one on top is when you get killed by the bullet. the one on the bottom is for the grenade launcher. "gp30" is the model of the launcher.

for the icon i needed to edit my sprites\hud.txt file, add a "gp30" entry there. that also meant editing an actual sprite file so i can add the icon there.

i did some tests to see if it would conflict with the real he grenade. so far no conflicts what-so-ever. everything is working the way they should.

Thanks for all the help guys! Here's some bacon, it's all I can give for now...
hellmonja is offline
Reply



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 16:44.


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