AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking if a entity is certain weapon (https://forums.alliedmods.net/showthread.php?t=248853)

Shlomi 09-25-2014 10:12

Checking if a entity is certain weapon
 
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 ) );
http://cloud-4.steampowered.com/ugc/...AA59C35FFF5B5/

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 :)

RateX 09-25-2014 11:03

Re: Checking if a entity is certain weapon
 
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)) 


HamletEagle 09-25-2014 11:16

Re: Checking if a entity is certain weapon
 
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.

Shlomi 09-25-2014 12:08

Re: Checking if a entity is certain weapon
 
Quote:

Originally Posted by RateX (Post 2203508)
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 (Post 2203514)
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

HamletEagle 09-25-2014 14:34

Re: Checking if a entity is certain weapon
 
Why you would need a check for something that you already know ? It doesn't make sense.

Shlomi 09-25-2014 14:42

Re: Checking if a entity is certain weapon
 
Quote:

Originally Posted by HamletEagle (Post 2203582)
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?

FromTheFuture 09-25-2014 14:53

Re: Checking if a entity is certain weapon
 
PHP Code:

new iWpn get_pdata_int(ent434


Shlomi 09-25-2014 15:05

Re: Checking if a entity is certain weapon
 
Quote:

Originally Posted by FromTheFuture (Post 2203590)
PHP Code:

new iWpn get_pdata_int(ent434


shouldnt it be the index of the player?

FromTheFuture 09-25-2014 18:48

Re: Checking if a entity is certain weapon
 
Quote:

Originally Posted by Shlomi (Post 2203593)
shouldnt it be the index of the player?

PHP Code:

new iWpn 

Wpn - Weapon

Shlomi 09-26-2014 02:49

Re: Checking if a entity is certain weapon
 
Quote:

Originally Posted by FromTheFuture (Post 2203664)
PHP Code:

new iWpn 

Wpn - Weapon

Code:

get_pdata_int
pdata = playerdata


All times are GMT -4. The time now is 13:33.

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