View Single Post
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-29-2008 , 15:58   Re: Individual Weapon Restrictions
Reply With Quote #5

No need to set them to 0. They are set to 0 when initialized.
Also, that won't set the whole array to 0.
You should've done: new variable[33] = {1, ...}; // sets all "variable" slots to 1
Code:
new g_NumWeapons[33] = {0};                 //Number of weapon restrictions for each player. new g_JoinedBeforeAuth[33] = {0};          //Set to 1 if player joins a team before authorizing with steam. new g_Authorized[33] = {0};                 //Set to 1 when authorizes.

Should be:
Code:
new g_NumWeapons[33];                 //Number of weapon restrictions for each player. new g_JoinedBeforeAuth[33];          //Set to 1 if player joins a team before authorizing with steam. new g_Authorized[33];                 //Set to 1 when authorizes.
---------------------------------------------
Redundant code:
Code:
            iGrenade = 0;             switch (iIndex)             {                 case 1:                 {                     if( CheckWeapon(id,CSW_HEGRENADE) )                         iGrenade = CSW_HEGRENADE;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }                 case 2:                 {                     if( CheckWeapon(id,CSW_FLASHBANG) )                         iGrenade = CSW_FLASHBANG;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }                 case 3:                 {                     if( CheckWeapon(id,CSW_SMOKEGRENADE) )                         iGrenade = CSW_SMOKEGRENADE;                                             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )                     {                         get_weaponname( iGrenade, szWeapon , 19 );                         PayInfo[0] = id;                         PayInfo[1] = iGrenade;                         cs_set_user_bpammo(id,iGrenade ,0);                         RepayPlayer( PayInfo );                         return PLUGIN_HANDLED;                     }                 }             }

Should be:
Code:
            iGrenade = 0;             switch (iIndex)             {                 case 1:                 {                     if( CheckWeapon(id,CSW_HEGRENADE) )                         iGrenade = CSW_HEGRENADE;                 }                 case 2:                 {                     if( CheckWeapon(id,CSW_FLASHBANG) )                         iGrenade = CSW_FLASHBANG;                 }                 case 3:                 {                     if( CheckWeapon(id,CSW_SMOKEGRENADE) )                         iGrenade = CSW_SMOKEGRENADE;                 }             }             if( iGrenade && cs_get_user_bpammo(id, iGrenade) )             {                 get_weaponname( iGrenade, szWeapon , 19 );                 PayInfo[0] = id;                 PayInfo[1] = iGrenade;                 cs_set_user_bpammo(id,iGrenade ,0);                 RepayPlayer( PayInfo );                 return PLUGIN_HANDLED;             }
------------------------------------------------
This is disgusting:
Code:
public GetWeaponIndex(szPartial[]) {     if( containi( "p228", szPartial ) > -1)         return CSW_P228;     else if( containi("scout", szPartial ) > -1 )             return CSW_SCOUT;     else if( containi("xm1014", szPartial ) > -1 )             return CSW_XM1014;     else if( containi("mac10", szPartial ) > -1 )             return CSW_MAC10;     else if( containi("aug", szPartial ) > -1 )             return CSW_AUG;     else if( containi("elite", szPartial ) > -1 )             return CSW_ELITE;     else if( containi("fiveseven", szPartial ) > -1 )             return CSW_FIVESEVEN;     else if( containi("ump45", szPartial ) > -1 )             return CSW_UMP45;     else if( containi("sg550", szPartial ) > -1 )             return CSW_SG550;     else if( containi("galil", szPartial ) > -1 )             return CSW_GALIL;     else if( containi("famas", szPartial ) > -1 )             return CSW_FAMAS;     else if( containi("usp", szPartial ) > -1 )             return CSW_USP;     else if( containi("glock18", szPartial ) > -1 )             return CSW_GLOCK18;     else if( containi("awp", szPartial ) > -1 )             return CSW_AWP;     else if( containi("mp5navy", szPartial ) > -1 )             return CSW_MP5NAVY;     else if( containi("m249", szPartial ) > -1 )             return CSW_M249;     else if( containi("m3", szPartial ) > -1 )             return CSW_M3;     else if( containi("m4a1", szPartial ) > -1 )             return CSW_M4A1;     else if( containi("tmp", szPartial ) > -1 )             return CSW_TMP;     else if( containi("g3sg1", szPartial ) > -1 )             return CSW_G3SG1;     else if( containi("deagle", szPartial ) > -1 )             return CSW_DEAGLE;     else if( containi("sg552", szPartial ) > -1 )             return CSW_SG552;     else if( containi("ak47", szPartial ) > -1 )             return CSW_AK47;     else if( containi("p90", szPartial ) > -1 )             return CSW_P90;     else if( containi("hegrenade", szPartial ) > -1 )             return CSW_HEGRENADE;     else if( containi("smokegrenade", szPartial ) > -1 )             return CSW_SMOKEGRENADE;     else if( containi("flashbang", szPartial ) > -1 )             return CSW_FLASHBANG;             return 0; }
Should be:
Code:
new const g_weapon_names[][] = {     "p228",     "scout",     "xm1014",     "mac10",     "aug",     "elite",     "fiveseven",     "ump45",     "sg550",     "galil",     "famas",     "usp",     "glock18",     "awp",     "mp5navy",     "m249",     "m3",     "m4a1",     "tmp",     "g3sg1",     "deagle",     "sg552",     "ak47",     "p90",     "hegrenade",     "smokegrenade",     "flashbang" }; new const g_weapon_ids[sizeof(g_weapon_names)] = {     CSW_P228,     CSW_SCOUT,     CSW_XM1014,     CSW_MAC10,     CSW_AUG,     CSW_ELITE,     CSW_FIVESEVEN,     CSW_UMP45,     CSW_SG550,     CSW_GALIL,     CSW_FAMAS,     CSW_USP,     CSW_GLOCK18,     CSW_AWP,     CSW_MP5NAVY,     CSW_M249,     CSW_M3,     CSW_M4A1,     CSW_TMP,     CSW_G3SG1,     CSW_DEAGLE,     CSW_SG552,     CSW_AK47,     CSW_P90,     CSW_HEGRENADE,     CSW_FLASHBANG,     CSW_SMOKEGRENADE }; public GetWeaponIndex(szPartial[]) {     for( new i = 0; i < sizeof(g_weapon_names); i++ )     {         if( containi(szPartial, g_weapon_names[i]) != -1 )         {             return g_weapon_ids[i];         }     }             return 0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline