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

Solved simplify


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-14-2022 , 09:05   simplify
Reply With Quote #1

Is it possible to simplify this code? It must have 2 conditions.
PHP Code:
public Ham_Knife_Deploy_Post(iEnt)
{
    static 
idid get_pdata_cbase(iEntm_pPlayer4)
    
    if(!
g_bBot[id] && g_bConnected[id]) // i don't know why connect checking needed. (when i see any ham deploy hooking there are connection checks)
    
{
        
refreshKnifeModel(id// if user isn't a bot
    
}
    else if(
g_bBot[id] && g_iBotsWithRandomKnives)
    {
        
refreshKnifeModel(id// if user is a bot and bots can have random knives
    
}
    
    return 
HAM_IGNORED

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 04-14-2022 at 13:06.
kww is offline
zXCaptainXz
Member
Join Date: May 2017
Old 04-14-2022 , 12:20   Re: simplify
Reply With Quote #2

PHP Code:
public Ham_Knife_Deploy_Post(iEnt)
{
    static 
idid get_pdata_cbase(iEntm_pPlayer4)
    
    if(!
g_bBot[id]))
    {
        if(!
g_bConnected[id])
        {
            return 
HAM_IGNORED;
        }         
    }
    else if(!
g_iBotsWithRandomKnives)
    {    
        return 
HAM_IGNORED
    
}
    
    
refreshKnifeModel(id)
    
    return 
HAM_IGNORED


Last edited by zXCaptainXz; 04-14-2022 at 12:21. Reason: oops
zXCaptainXz is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-14-2022 , 12:33   Re: simplify
Reply With Quote #3

You don't need to check if the player is connected on Ham_Item_Deploy hook.

Code:
public Ham_Knife_Deploy_Post(iEnt) {     new id = get_pdata_cbase(iEnt, m_pPlayer, 4)         if(g_bBot[id] && g_iBotsWithRandomKnives)     {         return     }     refreshKnifeModel(id) }
__________________








CrazY. is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-14-2022 , 13:05   Re: simplify
Reply With Quote #4

Final look:
PHP Code:
public Ham_Knife_Deploy_Post(iEnt)
{
    static 
idid get_pdata_cbase(iEntm_pPlayer4)
    
    if(!
g_bBot[id])
    {
        
refreshKnifeModel(id// if user isn't a bot
    
}
    else if(
g_iBotsWithRandomKnives)
    {
        
refreshKnifeModel(id// if user is a bot and bots can have random knives
    
}
    
    return 
HAM_IGNORED

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-14-2022 , 13:36   Re: simplify
Reply With Quote #5

The id being within range may not be needed but it's cheap insurance to throw it in there.
PHP Code:
public Ham_Knife_Deploy_Post(iEnt)
{
    static 
idid get_pdata_cbase(iEntm_pPlayer4)
    
    if ( ( 
<= id <= MAX_PLAYERS ) && ( !g_bBot[id] || g_iBotsWithRandomKnives ) )
    {
        
refreshKnifeModel(id)
    }
    
    return 
HAM_IGNORED

__________________

Last edited by Bugsy; 04-14-2022 at 13:42.
Bugsy is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-14-2022 , 14:17   Re: simplify
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
The id being within range may not be needed but it's cheap insurance to throw it in there.
PHP Code:
public Ham_Knife_Deploy_Post(iEnt)
{
    static 
idid get_pdata_cbase(iEntm_pPlayer4)
    
    if ( ( 
<= id <= MAX_PLAYERS ) && ( !g_bBot[id] || g_iBotsWithRandomKnives ) )
    {
        
refreshKnifeModel(id)
    }
    
    return 
HAM_IGNORED

any reason to check if it is a player?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 04-14-2022 at 14:18.
kww is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-14-2022 , 14:20   Re: simplify
Reply With Quote #7

Quote:
Originally Posted by kww View Post
any reason to check if it is a player?
Actually its not needed, entity is certained to have an owner.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-14-2022 , 15:14   Re: simplify
Reply With Quote #8

In normal circumstances, but I suppose other plugins/mods could trigger deploy on knife by a non-player entity. It's not making your server CPU sweat by having it, and there's a good chance you'd not get an error without it. I did mention this in my post, that you can likely get away without it.
__________________

Last edited by Bugsy; 04-14-2022 at 15:15.
Bugsy is offline
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 14:49.


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