Raised This Month: $ Target: $400
 0% 

Optimize code, menu and nvault


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Ualasxd
New Member
Join Date: Dec 2011
Old 05-05-2012 , 18:45   Optimize code, menu and nvault
Reply With Quote #1

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault>

new g_iSave[33][33]

enum _:Data
{
    
_Nome[30],
    
_Valor_CSW // CSW_*
}
new 
iVault
new Weapons[][Data] = {
    {
"Knife"29},
    {
"Glock 18"17 },
    {
"USP .45 ACP Tactical",16},
    {
"P228 Compact"1},
    {
"FiveseveN"11}, // 5
    
{"Desert Eagle .50 AE"26},
    {
"Dual Elite Berettas"10},
    {
"Schmidt TMP"23},
    {
"Ingram MAC-10"7},
    {
"UMP 45"12},
    {
"MP5 Navy",  19},
    {
"ES P90"30},
    {
"M3 Super"21},
    {
"XM1014 M4"5},
    {
"Famas"15},
    {
"IMI Galil"14},
    {
"AK-47"28},
    {
"M4A1 Carbine"22},
    {
"Scout"3},
    {
"Steyr AUG A1"8}, // 20
    
{"SG-552 Commando",27},
    {
"AWP Magnum Sniper"18},
    {
"G3SG1 Auto-Sniper"24},
    {
"SG-550 Auto-Sniper"13},
    {
"M249 Para Machinegun" 20}
}
new 
g_iLevels[33][32// 4 = CSW_GRENADE, 6 = CSW_C4, 9 = CSW_SMOKEGRENADE
new g_iKills[33][32]
new 
g_pcvar_kills_level
public plugin_init()
{
    
register_plugin("ZM WEAPONS : Levels""0.01""jz")
    
    
register_clcmd("say /menu","cmd_armas_menu")
    
    
RegisterHam(Ham_TakeDamage"player""fwd_TakeDamage_Pre"0)
    
RegisterHam(Ham_Killed"player""fwd_Killed_Post"1)
    
    
g_pcvar_kills_level register_cvar("zm_kills_levels""10")
    
    
iVault nvault_open("weapon_levels")
    if ( 
iVault == INVALID_HANDLE )
        
set_fail_state"Error" );
    
}

public 
plugin_end()
{
    
nvault_closeiVault );
}
public 
cmd_armas_menu(id)
{
    new 
menu menu_create("menu - test""menu_handler")
    
    new 
szOpcao[128]
    new 
csw_id
    
for(new 0sizeof Weapons i++)
    {
        
csw_id Weapons[i][_Valor_CSW]
        
formatex(szOpcaosizeof szOpcao -1"\w%s \d-\y Level: \r %d" Weapons[i][_Nome], g_iLevels[id][csw_id]) //show name and level weapon of player
        
menu_additem(menuszOpcao)
    }

    
menu_display(idmenu)
    return 
PLUGIN_HANDLED;
}
public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    
client_print(idprint_chat"Weapon %s - Level %d "Weapons[item][_Nome] , g_iLevels[id][item])
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED;
}

public 
fwd_TakeDamage_Pre(victiminflictorattackerFloat:damagedamage_bits)
{
    if(!
is_user_connected(attacker))
    return 
HAM_IGNORED

    
new weapon get_user_weapon(attacker)
    if (
weapon == CSW_HEGRENADE)
    return 
HAM_IGNORED

    
new level g_iLevels[attacker][weapon]
    
SetHamParamFloat(4level 10.0)
    return 
HAM_IGNORED;
}
public 
fwd_Killed_Post(victimidwtf)
{
    if(!
is_user_connected(id))
    return 
HAM_IGNORED;
    
    new 
weapon get_user_weapon(id_,_)
    if(++
g_iKills[id][weapon] >= get_pcvar_num(g_pcvar_kills_level))
    {
        
g_iLevels[id][weapon]++
        
g_iKills[id][weapon] = 0
        Save
(id);
    }
    return 
HAM_IGNORED;
}
public 
client_putinserver(id)
{
    
get_user_authid(idg_iSave[id], 32)
    
Load(id)
}
public 
Load(id)
{
    
    new 
szData[120];
    
    if ( 
nvault_getiVault g_iSave[id], szData charsmaxszData ) ) )
    {
        new 
space
        
for(new sizeof Weapons i++)
        {
            if(
szData[i] == ' ')
            
space 1
            
            g_iLevels
[id][i] =  szData[space i
            
        }
    }
}
public 
Save(id)
{
    new 
szData[128],temp[40]
    
    for(new 
isizeof Weaponsi++)
    {
        
formatex(tempsizeof temp -1" %d",  g_iLevels[id][i])
        
add(szData,sizeof szData -1temp)
    }
    
//server_print(szData) //debug
    
nvault_setiVault g_iSave[id] , szData );

Don't load correctly .
And the menu sometimes shows the wrong level of the weapon. What can be?


Any suggestions to optimize the code?

Last edited by Ualasxd; 05-05-2012 at 18:46. Reason: [code]
Ualasxd is offline
 


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 00:21.


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