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

CBaseCombatWeapon Classname


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 12-05-2016 , 20:52   CBaseCombatWeapon Classname
Reply With Quote #1

It is part of my hook, but i have crash when i try to get classname of CBaseCombatWeapon . What i did wrong?

PHP Code:
bool Hook_WeaponCanUse(CBaseCombatWeapon *pWeapon)
{
    
// Get real player index from hook key
    
int ref gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity));
    
int clientIndex gamehelpers->ReferenceToIndex(ref);
    if (!
clientIndex)
    {
        
RETURN_META_VALUE(MRES_IGNOREDtrue);
    }

    
// Validate client
    
ZPBaseClient *CPlayer TOOLS_GetPlayer(clientIndex);
    if (!
CPlayer)
    {
        
RETURN_META_VALUE(MRES_IGNOREDtrue);
    }
    
    
// If player is dead, then stop
    
if(!TOOLS_IsPlayerAlive(clientIndex))
    {
        
RETURN_META_VALUE(MRES_IGNOREDtrue);
    }
    
        if (
strcmp(gamehelpers->GetEntityClassname(pWeapon), "weapon_knife") != 0)
        {
            
RETURN_META_VALUE(MRES_SUPERCEDEfalse);
        } 
__________________

Last edited by gubka; 12-05-2016 at 20:53.
gubka is offline
Send a message via ICQ to gubka
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 12-07-2016 , 14:09   Re: CBaseCombatWeapon Classname
Reply With Quote #2

Most likely the pointer pWeapon is invalid. Try to check it this way:
PHP Code:
if(pWeapon == nullptr) {
//The weapon is invalid
g_pSM->LogMessage(myself"Point1");
}
cell_t rWeapon gamehelpers->EntityToReference(pWeapon ); //May crash here if the pointer is incorrect
if(rWeapon == -1) {
//The weapon is invalid
g_pSM->LogMessage(myself"Point2");


Last edited by kadet.89; 05-07-2017 at 05:34.
kadet.89 is offline
Send a message via Skype™ to kadet.89
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 12-07-2016 , 17:38   Re: CBaseCombatWeapon Classname
Reply With Quote #3

Quote:
Originally Posted by kadet.89 View Post
Most likely the pointer pWeapon is invalid. Try to check it this way:
PHP Code:
if(pWeapon == nullptr) {
//The weapon is invalid
g_pSM->LogMessage(myself"Point1");
}
int rWeapon gamehelpers->EntityToReference(pWeapon ); //May crash here if the pointer is incorrect
if(rWeapon == -1) {
//The weapon is invalid
g_pSM->LogMessage(myself"Point2");

Ok thank you, now i will now
__________________
gubka is offline
Send a message via ICQ to gubka
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 05:17.


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