Raised This Month: $ Target: $400
 0% 

Checking if a entity is certain weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shlomi
Junior Member
Join Date: Oct 2013
Old 09-25-2014 , 10:12   Checking if a entity is certain weapon
Reply With Quote #1

first of all, sry for bad english.

mkay, i have an entity index and i want to check if its deagle.

Code:
public plugin_init( ) {
	RegisterHam( Ham_Weapon_PrimaryAttack, "weapon_deagle", "OnDeagleAttack", 1 );
}

public OnDeagleAttack( ent )
{
 // what now?
}
ive tried with pev( ent, pev_classname ) and then check if it is equal to "weapon_deagle" but its seems it returns number and not string, heres what happend when i tried to print this on chat:
Code:
client_print( 0, print_chat, "%s", pev( ent, pev_classname ) );


i also tried to check if ent == CSW_DEAGLE although i know this function returns me the id of the entity, and it didn't work.

thanks

Last edited by Shlomi; 09-25-2014 at 10:18.
Shlomi is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 09-25-2014 , 11:03   Re: Checking if a entity is certain weapon
Reply With Quote #2

Why would you even need to check? It's very redundant because you're hooking deagle.
BTW, you're using pev_classname wrong. It should be:
PHP Code:
static name[32]
pev(entpev_classnamenamecharsmax(name)) 
RateX is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-25-2014 , 11:16   Re: Checking if a entity is certain weapon
Reply With Quote #3

RegisterHam( Ham_Weapon_PrimaryAttack, "weapon_deagle", "OnDeagleAttack", 1 );

weapon_deagle is the classname for what you are registering your hook, so it will work only for deagles. What pev_classname gives you is a string, so you have to use it like pev( iEnt, pev_classname, szString, charsmax( szString ) ). Also, you have to create your szString variabile with a given size like new szString[ 20 ] or whatever.
__________________
HamletEagle is offline
Shlomi
Junior Member
Join Date: Oct 2013
Old 09-25-2014 , 12:08   Re: Checking if a entity is certain weapon
Reply With Quote #4

Quote:
Originally Posted by RateX View Post
Why would you even need to check? It's very redundant because you're hooking deagle.
BTW, you're using pev_classname wrong. It should be:
PHP Code:
static name[32]
pev(entpev_classnamenamecharsmax(name)) 
Quote:
Originally Posted by HamletEagle View Post
RegisterHam( Ham_Weapon_PrimaryAttack, "weapon_deagle", "OnDeagleAttack", 1 );

weapon_deagle is the classname for what you are registering your hook, so it will work only for deagles. What pev_classname gives you is a string, so you have to use it like pev( iEnt, pev_classname, szString, charsmax( szString ) ). Also, you have to create your szString variabile with a given size like new szString[ 20 ] or whatever.
i know what im hooking, i just need this check.
anyway, thanks, i guess i forgot it works this way.
you can lock this thread or whatever
Shlomi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-25-2014 , 14:34   Re: Checking if a entity is certain weapon
Reply With Quote #5

Why you would need a check for something that you already know ? It doesn't make sense.
__________________
HamletEagle is offline
Shlomi
Junior Member
Join Date: Oct 2013
Old 09-25-2014 , 14:42   Re: Checking if a entity is certain weapon
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
Why you would need a check for something that you already know ? It doesn't make sense.
Code:
new const WeaponsInfo[ ] [ Weapons ] =
{
	{ "weapon_deagle", CSW_DEAGLE, "Deagle" },
	{ "weapon_m4a1", CSW_M4A1, "M4A1" },
	{ "weapon_m3", CSW_M3, "Shotgun" },
	{ "weapon_ak47", CSW_AK47, "AK47" },
	{ "weapon_awp", CSW_AWP, "AWP" },
	{ "weapon_scout", CSW_SCOUT, "Scout" }
}

new HamHook:Weapons_Attacks[ sizeof( WeaponsInfo ) ];
Code:
	for( new i = 0 ; i < sizeof( Weapons_Attacks ) ; i++ )
		Weapons_Attacks[ i ] = RegisterHam( Ham_Weapon_PrimaryAttack, WeaponsInfo[ i ] [ ID ], "OnPrimaryAttack", 1 );
now you understand genious?

Last edited by Shlomi; 09-25-2014 at 14:42.
Shlomi is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 09-25-2014 , 14:53   Re: Checking if a entity is certain weapon
Reply With Quote #7

PHP Code:
new iWpn get_pdata_int(ent434
FromTheFuture is offline
Shlomi
Junior Member
Join Date: Oct 2013
Old 09-25-2014 , 15:05   Re: Checking if a entity is certain weapon
Reply With Quote #8

Quote:
Originally Posted by FromTheFuture View Post
PHP Code:
new iWpn get_pdata_int(ent434
shouldnt it be the index of the player?
Shlomi is offline
FromTheFuture
Senior Member
Join Date: Jan 2013
Old 09-25-2014 , 18:48   Re: Checking if a entity is certain weapon
Reply With Quote #9

Quote:
Originally Posted by Shlomi View Post
shouldnt it be the index of the player?
PHP Code:
new iWpn 
Wpn - Weapon
FromTheFuture is offline
Shlomi
Junior Member
Join Date: Oct 2013
Old 09-26-2014 , 02:49   Re: Checking if a entity is certain weapon
Reply With Quote #10

Quote:
Originally Posted by FromTheFuture View Post
PHP Code:
new iWpn 
Wpn - Weapon
Code:
get_pdata_int
pdata = playerdata
Shlomi 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 23:13.


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