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

[HOWTO] Dead Bodies


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 09-08-2007 , 17:17   [HOWTO] Dead Bodies
Reply With Quote #1

This tutorial assumes you're an intermediate level scripter and will not explain basic syntax, logic, etc.

I'm going to be explaining how to make a dead body on top of the body that normally is on the ground after someone dies. It's sorta hacky, but I've found it works pretty well. Problems I've had with my method shouldn't cause any trouble in CS, since my implementations have been done in TS. This implementation is designed to be mod inspecific.

The first thing you have to do is hook the DeathMsg event, obviously. However, a delay must be added, otherwise the body will just instantly appear when someone dies - as if they fell over at lightspeed.

Code:
public plugin_init() {     register_plugin("Murder Mod","1.0","Hawk552")         register_event("DeathMsg","EventDeathMsg","a") } public EventDeathMsg()     set_task(2.0,"DelayedDeathMsg",read_data(2))

With this in place, we can now detect when a player dies, and (hopefully) after the animation has taken place. The first problem arises from getting rid of the player's body. This can easily be solved in CS by blocking the ClCorpse message (I think, haven't tried it). In other mods, however, you have to drop the origin of the player and the dead body will follow.

Code:
public DelayedDeathMsg(id) {        new Float:Origin[3]     entity_get_vector(id,EV_VEC_origin,Origin)         Origin[2] -= 40.0     entity_set_origin(id,Origin)     Origin[2] += 40.0 }

Now that the player's corpse is out of the way, we're going to spawn another entity to take its place. I'd use a message, but we want it to be able to have a box with which players can't move into and other stuff (for example a name of the person that died when you mouse-over the corpse).

Code:
public DelayedDeathMsg(id) {        new Float:Origin[3],Float:Angle[3],Model[33]     entity_get_vector(id,EV_VEC_origin,Origin)     entity_get_vector(id,EV_VEC_v_angle,Angle)     entity_get_string(id,EV_SZ_model,Model,32)         Origin[2] -= 40.0     entity_set_origin(id,Origin)     Origin[2] += 40.0         new Ent = create_entity("info_target")         entity_set_string(Ent,EV_SZ_classname,"dead_body")     entity_set_model(Ent,Model)     entity_set_int(Ent,EV_INT_movetype,MOVETYPE_FLY)     entity_set_int(Ent,EV_INT_sequence,100)     entity_set_size(Ent,Float:{-6.0,-12.0,-6.0},Float:{6.0,12.0,6.0})     entity_set_int(Ent,EV_INT_solid,SOLID_BBOX)     entity_set_vector(Ent,EV_VEC_v_angle,Angle)     entity_set_edict(Ent,EV_ENT_owner,id)         entity_set_origin(Ent,Origin)     drop_to_floor(Ent)     entity_get_vector(Ent,EV_VEC_origin,Origin)     Origin[2] += 13.0     entity_set_origin(Ent,Origin) }

A couple notes: I don't know why I set it to MOVETYPE_FLY, so you can probably get rid of that. Also, it may be more effective to run a trace_line to the ground and just add 13.0 units to the z value of the result, but I figure it's less work for a marginal optimization when you just use drop_to_floor.

So that's basically it on how to do it. You can add some more stuff like a timer that'll get rid of it after a certain time (so the server doesn't get too crowded or crash due to too many ents). The finished plugin (based on my Murder Mod, an unreleased plugin for TSRP) would look something like this:

Code:
#include <amxmodx> #include <amxmisc> #include <engine> new g_ClassName[] = "dead_body" new p_Time public plugin_init() {     register_plugin("Dead Bodies","1.0","Hawk552")         register_event("DeathMsg","EventDeathMsg","a")         p_Time = register_cvar("amx_body_time","60.0") } public EventDeathMsg()     set_task(2.0,"DelayedDeathMsg",read_data(2)) public DelayedDeathMsg(id) {        new Float:Origin[3],Float:Angle[3],Model[33]     entity_get_vector(id,EV_VEC_origin,Origin)     entity_get_vector(id,EV_VEC_v_angle,Angle)     entity_get_string(id,EV_SZ_model,Model,32)         Origin[2] -= 40.0     entity_set_origin(id,Origin)     Origin[2] += 40.0         new Ent = create_entity("info_target")         entity_set_string(Ent,EV_SZ_classname,g_ClassName)     entity_set_model(Ent,Model)     entity_set_int(Ent,EV_INT_movetype,MOVETYPE_FLY)     entity_set_int(Ent,EV_INT_sequence,100)     entity_set_size(Ent,Float:{-6.0,-12.0,-6.0},Float:{6.0,12.0,6.0})     entity_set_int(Ent,EV_INT_solid,SOLID_BBOX)     entity_set_float(Ent,EV_FL_nextthink,1.0)     entity_set_vector(Ent,EV_VEC_v_angle,Angle)     entity_set_edict(Ent,EV_ENT_owner,id)         entity_set_origin(Ent,Origin)     drop_to_floor(Ent)     entity_get_vector(Ent,EV_VEC_origin,Origin)     Origin[2] += 13.0     entity_set_origin(Ent,Origin)             set_task(get_pcvar_float(p_Time),"EntRemove",Ent) } public EntRemove(Ent)     remove_entity(Ent)

Some general notes:

This method has not been tested on anything other than TS, but it should generally be mod inspecific. I really doubt this would work on CS, but with a few tweaks it probably would. You can also use mod specific messages (as I stated prior to this), but you lose some functionality and portability. Also, the sequence used (100) is for TS only and will have to be changed for any other mod.

As always, if you have any questions, comments or whatever, post them up.
__________________

Last edited by Hawk552; 09-08-2007 at 17:18. Reason: added comment
Hawk552 is offline
Send a message via AIM to Hawk552
X-Script
BANNED
Join Date: Jul 2007
Location: (#504434)
Old 09-08-2007 , 17:47   Re: [HOWTO] Dead Bodies
Reply With Quote #2

Sweet.
I wouldn't of guessed at all how to do this.

Thanks.
X-Script is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 09-08-2007 , 19:09   Re: [HOWTO] Dead Bodies
Reply With Quote #3

nice tut hawk
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 09-26-2007 , 03:41   Re: [HOWTO] Dead Bodies
Reply With Quote #4

As you can see in my plugin Dod Weapon/Corpse Stay, the origin and angles are both included in the ClCorpse message and can thus be immediately routed to the new dead body corpse. Apart from that, you're doing basically the same thing as I am in the plugin.

Overall nice tutorial Hawk.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 09-26-2007 , 07:11   Re: [HOWTO] Dead Bodies
Reply With Quote #5

I posted this because ClCorpse isn't in every mod. I don't know if you're trying to imply that I read your plugin and then posted this using it, but I can assure you I haven't.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 09-26-2007 , 11:46   Re: [HOWTO] Dead Bodies
Reply With Quote #6

Lower thy sword, Hawk. I was not implying that...I was simply reinforcing my compliment with the "that's how I did it too" idea.

flaming deleted by mod
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician

Last edited by Greentryst; 09-28-2007 at 09:40. Reason: no flaming. the misunderstanding was your fault
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
Old 09-26-2007, 15:24
Hawk552
This message has been deleted by Greentryst. Reason: reply to deleted post fragment
Old 09-26-2007, 16:50
Lord_Destros
This message has been deleted by Greentryst. Reason: reply to deleted post fragment
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 09-27-2007 , 05:19   Re: [HOWTO] Dead Bodies
Reply With Quote #7

I like it.

Though would it not be possible to avoid the "remove body" task, and just set its nextthink to the CVAR?

And register the think for dead_body to be EntRemove?

Swish tutorial - I might play with the idea.
Maybe allow users to define an "I killed you" message which gets attached to the corpse? I'll think of something, I'm sure.
purple_pixie is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 09-27-2007 , 06:49   Re: [HOWTO] Dead Bodies
Reply With Quote #8

Yeah, you can always do that.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 21:14.


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