AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ham_Touch / Limitation (https://forums.alliedmods.net/showthread.php?t=184156)

MiniBrackeur 05-01-2012 14:01

Ham_Touch / Limitation
 
Hello everybody !
I have got a problem, my code works good exept two bugs, the famas and scout aren't limited (I do not know why! O_o).

So, I seek to delete this problem and shorten the code if possible...

PHP Code:

public client_weapon_pickup(id)
{
    new 
Weapons[32]
    new 
WeaponNum
    
new Weapon
    
    get_user_weapons
(idWeaponsWeaponNum)
    
    for (new 
<= WeaponNumi++)
    {
        
Weapon Weapons[i]
        
        new 
niveau_limitation pl_limitation[id]
        if(
niveau_limitation >= 1)
        {
            if(
niveau_limitation >= 2)
            {
                if(
niveau_limitation >= 3)
                {
                    if(
niveau_limitation >= 4)
                    {
                        if(
niveau_limitation >= 5)
                        {
                            if(
niveau_limitation >= 6)
                            {
                                if(
niveau_limitation >= 7)
                                {
                                    if((
Weapon == CSW_USP) || (Weapon == CSW_GLOCK18))   
                                    {
                                        switch(
Weapon)
                                        {
                                            case 
CSW_USP:
                                            {
                                                
console_cmd(id"drop weapon_usp")
                                            }
                                            case 
CSW_GLOCK18:
                                            {
                                                
console_cmd(id"drop weapon_glock18")
                                            }
                                        }
                                        
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                                    }
                                }
                                if((
Weapon == CSW_P228) || (Weapon == CSW_DEAGLE) || (Weapon == CSW_FIVESEVEN) || (Weapon == CSW_ELITE))   
                                {
                                    switch(
Weapon)
                                    {
                                        case 
CSW_P228:
                                        {
                                            
console_cmd(id"drop weapon_p228")
                                        }
                                        case 
CSW_DEAGLE:
                                        {
                                            
console_cmd(id"drop weapon_deagle")
                                        }
                                        case 
CSW_FIVESEVEN:
                                        {
                                            
console_cmd(id"drop weapon_fiveseven")
                                        }
                                        case 
CSW_ELITE:
                                        {
                                            
console_cmd(id"drop weapon_elite")
                                        }
                                    }
                                    
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                                }
                            }
                            if((
Weapon == CSW_M3) || (Weapon == CSW_XM1014))   
                            {
                                switch(
Weapon)
                                {
                                    case 
CSW_M3:
                                    {
                                        
console_cmd(id"drop weapon_m3")
                                    }
                                    case 
CSW_XM1014:
                                    {
                                        
console_cmd(id"drop weapon_xm1014")
                                    }
                                }
                                
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                            }
                        }
                        if((
Weapon == CSW_MAC10) || (Weapon == CSW_TMP) || (Weapon == CSW_MP5NAVY) || (Weapon == CSW_UMP45) || (Weapon == CSW_P90))   
                        {
                            switch(
Weapon)
                            {
                                case 
CSW_MAC10:
                                {
                                    
console_cmd(id"drop weapon_mac10")
                                }
                                case 
CSW_TMP:
                                {
                                    
console_cmd(id"drop weapon_tmp")
                                }
                                case 
CSW_MP5NAVY:
                                {
                                    
console_cmd(id"drop weapon_mp5navy")
                                }
                                case 
CSW_UMP45:
                                {
                                    
console_cmd(id"drop weapon_ump45")
                                }
                                case 
CSW_P90:
                                {
                                    
console_cmd(id"drop weapon_p90")
                                }
                            }
                            
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                        }
                    }
                    if((
Weapon == CSW_GALIL) || (Weapon == CSW_FAMAS) || (Weapon == CSW_M4A1) || (Weapon == CSW_AK47) || (Weapon == CSW_AUG) || (Weapon == CSW_SG552))   
                    {
                        switch(
Weapon)
                        {
                            case 
CSW_GALIL:
                            {
                                
console_cmd(id"drop weapon_galil")
                            }
                            case 
CSW_FAMAS:
                            {
                                
console_cmd(id"drop weapon_famas")
                            }
                            case 
CSW_M4A1:
                            {
                                
console_cmd(id"drop weapon_m4a1")
                            }
                            case 
CSW_AK47:
                            {
                                
console_cmd(id"drop weapon_ak47")
                            }
                            case 
CSW_AUG:
                            {
                                
console_cmd(id"drop weapon_aug")
                            }
                            case 
CSW_SG552:
                            {
                                
console_cmd(id"drop weapon_sg552")
                            }
                        }
                        
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                    }
                }
                if((
Weapon == CSW_SCOUT) || (Weapon == CSW_AWP) || (Weapon == CSW_SG550) || (Weapon == CSW_G3SG1))   
                {
                    switch(
Weapon)
                    {
                        case 
CSW_SCOUT:
                        {
                            
console_cmd(id"drop weapon_scout")
                        }
                        case 
CSW_AWP:
                        {
                            
console_cmd(id"drop weapon_awp")
                        }
                        case 
CSW_SG550:
                        {
                            
console_cmd(id"drop weapon_sg550")
                        }
                        case 
CSW_G3SG1:
                        {
                            
console_cmd(id"drop weapon_g3sg1")
                        }
                    }
                    
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
                }
            }
            if(
Weapon == CSW_M249)   
            {
                
console_cmd(id"drop weapon_m249")
                
client_print(idprint_center"%L"LANG_PLAYER"LIMITATION_DROP")
            }
        }
    }


Sorry for my bad english, I'm french ^^'

Thank's for your attention :)

Exolent[jNr] 05-01-2012 15:03

Re: how to shorten and debug this code?
 
Make something like this:
Code:
new const gWeaponLimits[] = {     // no limit, allow all weapons     0,     // limit 1 = M249     (1<<CSW_M249),     // limit 2 = scout, awp, sg550, g3sg1     (1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_SG550)|(1<<CSW_G3SG1),     // limit 3 = galil, famas, m4a1, ak47, aug, sg552     (1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_M4A1)|(1<<CSW_AK47)|(1<<CSW_AUG)|(1<<CSW_SG551),     // limit 4 = mac10, tmp, mp5, ump45, p90     (1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_MP5NAVY)|(1<<CSW_UMP45)|(1<<CSW_P90),     // limit 5 = m3, xm1014     (1<<CSW_M3)|(1<<CSW_XM1014),     // limit 6 = p228, deagle, fiveseven, elites     (1<<CSW_P228)|(1<<CSW_DEAGLE)|(1<<CSW_FIVESEVEN)|(1<<CSW_ELITE),     // limit 7 = usp, glock     (1<<CSW_USP)|(1<<CSW_GLOCK18) };

Then here's your modified function:
Code:
public client_weapon_pickup(id) {     new niveau_limitation = pl_limitation[id]         new Weapon = read_data(1);         for (new i = 1; i <= niveau_limitation && i < sizeof(gWeaponLimits); i++)     {         if(gWeaponLimits[i] & (1 << Weapon))         {             new data[3];             data[0] = id;             data[1] = get_user_userid(id);             data[2] = Weapon;                         set_task(0.1, "TaskDropWeapon", id, data, sizeof(data));                         break;         }     } } public TaskDropWeapon(data[]) {     new id = data[0];         if(!is_user_connected(id) || get_user_userid(id) != data[1])     {         return;     }         new Weapon = data[2];         if(!user_has_weapon(id, Weapon))     {         return;     }         new WeaponName[32];     get_weaponname(Weapon, WeaponName, charsmax(WeaponName));         engclient_cmd(id, "drop", WeaponName);         client_print(id, print_center, "%L", id, "LIMITATION_DROP") }

Much better.

MiniBrackeur 05-01-2012 16:37

Re: how to shorten and debug this code?
 
You are my god sir *_* very very very thank's !!! :D

MiniBrackeur 05-01-2012 18:08

Re: how to shorten and debug this code?
 
Hum, well the message is displayed each time, but the weapon is not dropped, and there are no errors in the logs amxx. Could you fix the code? : s Thank's

Exolent[jNr] 05-03-2012 09:36

Re: how to shorten and debug this code?
 
When is that function called?

MiniBrackeur 05-03-2012 12:59

Re: how to shorten and debug this code?
 
Oh, this function was called when the player picks up a weapon.

Quote:

register_event("WeapPickup", "client_weapon_pickup", "b")

Exolent[jNr] 05-03-2012 15:08

Re: how to shorten and debug this code?
 
WeapPickup
Quote:

Is fired right before weapon is picked up (notice "before").
That is why the drop command is not working.
Also, you should only need to check the picked up weapon, not all of the player's weapons.

Code has been edited for this.

MiniBrackeur 05-03-2012 18:25

Re: how to shorten and debug this code?
 
ah ok, I understand better, and thank you very much, everything works perfectly.

Thank you ! :)

MiniBrackeur 06-09-2012 07:03

Re: how to shorten and debug this code?
 
I opened this topic because I changed the code, I want that the player can't pick up the weapon if he is limited, but I can't do it :/

Somebody can help me again? x)

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <fakemeta>

new disable_plugin
new disable_help

new pl_limitation[33]

new const 
gWeaponLimits[] = {
    
0,
    
0,
    (
1<<CSW_M249),
    (
1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_SG550)|(1<<CSW_G3SG1),
    (
1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_M4A1)|(1<<CSW_AK47)|(1<<CSW_AUG)|(1<<CSW_SG552),
    (
1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_MP5NAVY)|(1<<CSW_UMP45)|(1<<CSW_P90),
    (
1<<CSW_M3)|(1<<CSW_XM1014),
    (
1<<CSW_P228)|(1<<CSW_DEAGLE)|(1<<CSW_FIVESEVEN)|(1<<CSW_ELITE),
    (
1<<CSW_USP)|(1<<CSW_GLOCK18)
}

public 
plugin_init()
{
    
register_plugin("[CSD] Limitation","1.0","Daminou")
    
    
RegisterHam(Ham_Spawn"player""client_spawn"1)
    
RegisterHam(Ham_Touch"armoury_entity""anti_weapon_pickup1"0)
    
RegisterHam(Ham_Touch"weaponbox""anti_weapon_pickup2"0)
    
    
disable_plugin register_cvar("csd_lim_p_disable""0")
    
disable_help register_cvar("csd_lim_h_disable""0")
    
    
register_dictionary("csd_plugins.txt")
}

public 
check_ratio(id)
{
    new 
frags get_user_frags(id)
    new 
deaths get_user_deaths(id)
    
    new 
ratio = (frags deaths)
    if(
ratio 14)
    {
        
pl_limitation[id] = 8
    
}
    else if(
ratio 12)
    {
        
pl_limitation[id] = 7
    
}
    else if(
ratio 10)
    {
        
pl_limitation[id] = 6
    
}
    else if(
ratio 8)
    {
        
pl_limitation[id] = 5
    
}
    else if(
ratio 6)
    {
        
pl_limitation[id] = 4
    
}
    else if(
ratio 4)
    {
        
pl_limitation[id] = 3
    
}
    else if(
ratio 3)
    {
        
pl_limitation[id] = 2
    
}
    else if(
ratio > -3)
    {
        
pl_limitation[id] = 1
    
}
    else if(
ratio < -4)
    {
        
pl_limitation[id] = 0
    
}
    new 
niveau_limitation pl_limitation[id]
    
client_print(idprint_chat"test 0: %s"niveau_limitation)
    if(
<= niveau_limitation <= 8)
    {
        
check_armes(id)
    }
    else if(
niveau_limitation == 0)
    {
        if(!
get_pcvar_num(disable_help))
        {
            
give_stuff(id)
            
client_print(idprint_chat"test 1")
        }
    }
}

public 
client_spawn(id)
{
    if(!
get_pcvar_num(disable_plugin))
    {
        
set_task(0.5"check_ratio"id)
    }
    else
    {
        
pl_limitation[id] = 1
    
}
}

public 
check_armes(id)
{
    if(
is_user_alive(id)) 
    {
        new 
niveau_limitation pl_limitation[id]
        new 
Weapon get_user_weapon(id)
        for (new 
1<= niveau_limitation && sizeof(gWeaponLimits); i++)
        {
            if(
gWeaponLimits[i] & (<< Weapon))
            {
                new 
WeaponName[32]
                
get_weaponname(WeaponWeaponNamecharsmax(WeaponName))
                
engclient_cmd(id"drop"WeaponName)
                
client_print(idprint_chat"test 2")
            }
        }
    }
}

public 
anti_weapon_pickup1(entid)
{
    if(
is_user_alive(id)) 
    {
        new 
niveau_limitation pl_limitation[id]
        new 
Weapon cs_get_armoury_type(ent)
        for (new 
1<= niveau_limitation && sizeof(gWeaponLimits); i++)
        {
            if(
gWeaponLimits[i] & (<< Weapon))
            {
                
client_print(idprint_chat"test 3")
                return 
HAM_SUPERCEDE
            
}
        }
    }
    return 
HAM_IGNORED
}

public 
anti_weapon_pickup2(ident
{
    if(
is_user_alive(id)) 
    {        
        new 
niveau_limitation pl_limitation[id]
        new 
Weapon =  cs_get_weapon_id(ent)
        for (new 
1<= niveau_limitation && sizeof(gWeaponLimits); i++)
        {
            if(
Weapon gWeaponLimits[i])
            {
                
client_print(idprint_chat"test 4")
                return 
HAM_SUPERCEDE
            
}
        }
    }    
    return 
HAM_IGNORED
}  

public 
give_stuff(id)
{
    switch(
cs_get_user_team(id))
    {
        case 
CS_TEAM_CT:
        {
            if(!
cs_get_user_defuse(id))
            {
                
cs_set_user_defuse(id1)
            }
            if(!
user_has_weapon(idCSW_M4A1))
            {
                
give_item(id"weapon_m4a1")
                
cs_set_user_bpammo(idCSW_M4A190)
            }
        }
        case 
CS_TEAM_T:
        {
            if(!
user_has_weapon(idCSW_AK47))
            {
                
give_item(id"weapon_ak47")
                
cs_set_user_bpammo(idCSW_AK4790)
            }
        }
    }
    if(!
user_has_weapon(idCSW_HEGRENADE))
    {
        
give_item(id"weapon_hegrenade")
    }
    if(!
user_has_weapon(idCSW_FLASHBANG))
    {
        
give_item(id"weapon_flashbang")
        
give_item(id"weapon_flashbang")
    }
    if(!
user_has_weapon(idCSW_SMOKEGRENADE))
    {
        
give_item(id"weapon_smokegrenade")
    }
    if(!
user_has_weapon(idCSW_DEAGLE))
    {
        
give_item(id"weapon_deagle")
        
cs_set_user_bpammo(idCSW_DEAGLE35)
    }
    
cs_set_user_armor(id100CS_ARMOR_VESTHELM)


PS: I changed the title of the topic.


All times are GMT -4. The time now is 07:53.

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