AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Better way to optimized this code? (https://forums.alliedmods.net/showthread.php?t=298677)

Celena Luna 06-20-2017 01:06

Better way to optimized this code?
 
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



NiHiLaNTh 06-20-2017 05:10

Re: Better way to optimized this code?
 
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.


All times are GMT -4. The time now is 23:08.

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