Raised This Month: $ Target: $400
 0% 

Solved Better way to optimized this code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 06-20-2017 , 01:06   Better way to optimized this code?
Reply With Quote #1

I am trying to make Glock's based weapon don't have the same ammo with MP5 Navy.
I used CurWeapon. it work well but I think i bad for server and I want to find another way
Can I anyone help me?

PHP Code:
public plugin_init()
{
    
register_event("CurWeapon""Event_CurWeapon""be""1=1")

    
RegisterHam(Ham_Weapon_Reloadweapon_infinity"fw_Weapon_Reload_Post"1)
}

public 
Event_CurWeapon(id)
{
    if(!
is_alive(id))
        return
       
    static 
CSWCSW read_data(2)
 
    if((
CSW == CSW_INFINITY && g_OldWeapon[id] != CSW_INFINITY) && Get_BitVar(g_Had_Infinityid))
    {
        
g_PreAmmo[id] = cs_get_user_bpammo(idCSW_INFINITY)
        
cs_set_user_bpammo(idCSW_INFINITYg_InfinityBPAmmo[id])
    } else if((
CSW == CSW_INFINITY && g_OldWeapon[id] == CSW_INFINITY) && Get_BitVar(g_Had_Infinityid)) {
        
cs_set_user_bpammo(idCSW_INFINITYg_InfinityBPAmmo[id])
    } else if((
CSW != CSW_INFINITY && g_OldWeapon[id] == CSW_INFINITY) && Get_BitVar(g_Had_Infinityid)) {
        
g_InfinityBPAmmo[id] = cs_get_user_bpammo(idCSW_INFINITY)
        
cs_set_user_bpammo(idCSW_INFINITYg_PreAmmo[id])
    }
   
    
g_OldWeapon[id] = CSW
}

public 
fw_Weapon_Reload_Post(ent)
{
    static 
idid pev(entpev_owner)
    if(!
is_user_alive(id))
        return 
HAM_IGNORED
    
if(!Get_BitVar(g_Had_Infinityid))
        return 
HAM_IGNORED    
    
    
if((get_pdata_int(ent544) == 1))
    { 
// Reload
        
if(g_Clip[id] == -1)
            return 
HAM_IGNORED
        
        set_pdata_int
(ent51g_Clip[id], 4)
        
Set_WeaponAnim(idANIME_RELOAD)
        
        
Set_PlayerNextAttack(idTIME_RELOAD)
        
g_InfinityBPAmmo[id] -= (CLIP g_Clip[id])
    }
    
    return 
HAM_HANDLED


Last edited by Celena Luna; 06-21-2017 at 10:29. Reason: Solved
Celena Luna is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 06-20-2017 , 05:10   Re: Better way to optimized this code?
Reply With Quote #2

The best idea is combination of Ham_Item_PrimaryAmmoIndex+Ham_Item_GetItemInf o+new WeaponList message. But that's only for amxx v1.8.3.

If you want to stick with your code, you need to override AmmoX and not CurWeapon (AmmoX is responsible to showing the rest of the ammo). Also you need to update your ammo on Reload and also save it when you drop your weapon and restore on pickup.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Old 06-20-2017, 06:34
PurposeLessx
This message has been deleted by PurposeLessx.
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:08.


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