Raised This Month: $ Target: $400
 0% 

If Entity is touched or shot at destroy.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
infek
Senior Member
Join Date: May 2009
Location: Behind you
Old 02-22-2011 , 22:34   If Entity is touched or shot at destroy.
Reply With Quote #1

How do you destroy an Entity if it is touched or shot at. Using its Classname.

Example how would you destroy this? vvv
PHP Code:
CreateTruckFloat:vOrigin[3] = { 0.000.00 0.00 } ) {
 new 
ent create_entity"info_target" )
 if( 
is_valid_entent ) ) {
  
entity_set_stringentEV_SZ_classnamegszTruckClass ); // gszTruckClass
  
entity_set_intent EV_INT_solidSOLID_BBOX);
  
entity_set_modelentgszModel );
  
entity_set_originentvOrigin );
  
entity_set_sizeent Float:{ -5.0, -5.00.0 }, Float:{ 5.05.0150.0 } );
 }
 return 
0;

__________________
"Domo Arigato, Mr. Roboto!"
PM me if you want to know a secret

Last edited by infek; 02-22-2011 at 23:28.
infek is offline
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 02-23-2011 , 02:19   Re: If Entity is touched or shot at destroy.
Reply With Quote #2

For destroy with damage:

PHP Code:
set_pev(idpev_health10.0)
set_pev(idpev_takedamageDAMAGE_YES
And you should to hook touch your info_target with another entities
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 02-23-2011 , 02:21   Re: If Entity is touched or shot at destroy.
Reply With Quote #3

Something like this, I assume?

Code:
#include < engine > #include < hamsandwich > public plugin_init( ) {     register_touch( gszTruckClass, "player", "Forward_TruckTouch" );         RegisterHam( Ham_TakeDamage, gszTruckClass, "Forward_TakeDamage" ); } public Forward_TruckTouch( entity, player ) {     remove_entity( entity ); } public Forward_TakeDamage( entity, inflictor, attacker, Float:damage, damagebits ) {     remove_entity( entity ); }
Xellath is offline
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 02-23-2011 , 02:56   Re: If Entity is touched or shot at destroy.
Reply With Quote #4

You don't need to hook Ham_TakeDamage.

With that
PHP Code:
set_pev(idpev_health10.0)    // ent health
set_pev(idpev_takedamageDAMAGE_YES
entity will die after 10 pts of damage.
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
infek
Senior Member
Join Date: May 2009
Location: Behind you
Old 02-25-2011 , 18:50   Re: If Entity is touched or shot at destroy.
Reply With Quote #5

@Flipper Yeah but what if you want to set a message saying "Entity is destroyed". wouldnt that only work if you hook takedamage. how would you do that with Pev?
__________________
"Domo Arigato, Mr. Roboto!"
PM me if you want to know a secret
infek is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 02-25-2011 , 19:08   Re: If Entity is touched or shot at destroy.
Reply With Quote #6

Well, if you want to send a message you would have to hook TakeDamage. Without the message you wouldn't though.
__________________
Hi.
Kreation is offline
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 02-25-2011 , 20:07   Re: If Entity is touched or shot at destroy.
Reply With Quote #7

hook Ham_Killed for that
__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
infek
Senior Member
Join Date: May 2009
Location: Behind you
Old 02-26-2011 , 00:13   Re: If Entity is touched or shot at destroy.
Reply With Quote #8

PHP Code:
RegisterHamHam_KilledgszCowClass"Forward_TakeDamage" );

public 
Forward_TakeDamageplayer ) {
client_cmd0"spk %s"gszSound )
client_print0print_chat"test" )

For some reason that didnt even work x|
__________________
"Domo Arigato, Mr. Roboto!"
PM me if you want to know a secret
infek is offline
Elusive138
Senior Member
Join Date: Dec 2010
Old 02-26-2011 , 00:18   Re: If Entity is touched or shot at destroy.
Reply With Quote #9

Quote:
Originally Posted by infek View Post
PHP Code:
RegisterHamHam_KilledgszCowClass"Forward_TakeDamage" );

public 
Forward_TakeDamageplayer ) {
client_cmd0"spk %s"gszSound )
client_print0print_chat"test" )

For some reason that didnt even work x|
Ham_Killed callbacks should be like this:
Code:
public function(this, idattacker, shouldgib)
Where this is the killed entity id (the cow?) and idattacker is the killer id (the player). Also, it's probably better to name your function Forward_Killed or some variation.

You can see the params of the other ham hooks in ham_const.inc.
Elusive138 is offline
infek
Senior Member
Join Date: May 2009
Location: Behind you
Old 02-26-2011 , 00:45   Re: If Entity is touched or shot at destroy.
Reply With Quote #10

Alright but since I changed "player" to gszCowClass shouldnt (this, idattacker, shouldgib) be different? cause wouldnt then gszCowClass be under idattacker??
__________________
"Domo Arigato, Mr. Roboto!"
PM me if you want to know a secret

Last edited by infek; 02-26-2011 at 00:55.
infek 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 10:36.


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