AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to block the buy of a weapon and what's my error ? (https://forums.alliedmods.net/showthread.php?t=209428)

MiniBrackeur 02-25-2013 09:48

How to block the buy of a weapon and what's my error ?
 
Hello, I have created with the help of some coders, a plugin of limitation for my server, but I would like to block the buy of the weapon who are restricted to the player by his limitation, because, actually, the player can buy a weapon restricted, but the weapon will drop directly... How to make it ?

My others problems is:
1) I have a problem to the line (66):
Quote:

client_print_color(id, Grey, "^4[CSD]^3 Tu es au^4 niveau %d^3 de limitation.^4 (%s)", pl_level[id], g_levels_names[pl_level[id]]);
The plugin display in the chat:
- Level 1: [CSD] .......... (pistolets | fusils a pompe | mitraillettes | fusils d'assault | mitrailleuse)
- Level 2: [CSD] .......... (istolets | fusils a pompe | mitraillettes | fusils d'assault | mitrailleuse)
- Level 3: [CSD] .......... (stolets | fusils a pompe | mitraillettes | fusils d'assault | mitrailleuse)
- Level 4: [CSD] .......... (tolets | fusils a pompe | mitraillettes | fusils d'assault | mitrailleuse)
ETC...
But in level 2, it was normaly display: "pistolets | fusils a pompe | mitraillettes | fusils d'assault"...
What's the problem ?

2) I have a small problem in the boucle "current_weapon" (CurWeapon), If I buy a weapon restricted, it will display 2 times the message: "Tu n'as pas le droit a cette arme !", and it will drop 2 weapons, my weapon restricted (m4a1 for example) and my weapon not restricted (usp for example).
And when I'm in spectator (when I'm dead), when I switch of plyaer or when the player switch weapon and the weapon is restricted for me, it will display a message in the chat: "Tu n'as pas le droit a cette arme !", What the fuck ? It's not me ! Oo It's not my weapon.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <csx>
#include <fun>
#include <hamsandwich>
#include <fakemeta>
#include <chatcolor>
#tryinclude <cstrike_pdatas>

new g_maxplayersg_disable_pluginpl_level[33];
#define is_player(%0) (1 <= %0 <= g_maxplayers)

new const g_levels[] = {
    (
1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_SG550)|(1<<CSW_G3SG1),
    (
1<<CSW_M249),
    (
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)
}
new const 
g_levels_names[] = {
    
"pistolets | fusils a pompe | mitraillettes | fusils d'assault | mitrailleuse",
    
"pistolets | fusils a pompe | mitraillettes | fusils d'assault",
    
"pistolets | fusils a pompe | mitraillettes",
    
"pistolets | fusils a pompe",
    
"pistolets",
    
"usp et glock",
    
"couteau"
}

public 
plugin_init()
{
    
register_plugin("[ADDON] Limitation","1.0","Daminou");
    
RegisterHam(Ham_Spawn"player""client_spawn"1);
    
RegisterHam(Ham_Touch"armoury_entity""armoury_entity_touch"false);
    
RegisterHam(Ham_Touch"weaponbox""weapon_box_touch"false);
    
register_event("CurWeapon""current_weapon""b");
    
g_disable_plugin register_cvar("amx_limitation""1");
    
g_maxplayers get_maxplayers();
}

public 
bomb_explode(iddefuser)
{
    
set_user_frags(idget_user_frags(id) - 3);
    return 
PLUGIN_CONTINUE;
}

public 
bomb_defused(id)
{
    
set_user_frags(idget_user_frags(id) - 3);
    return 
PLUGIN_CONTINUE;
}

public 
check_ratio(id)
{
    new 
ratio = (get_user_frags(id) - get_user_deaths(id));
    if(
ratio >= 16) { pl_level[id] = 6; }
    else if(
ratio >= 12) { pl_level[id] = 5; }
    else if(
ratio >= 10) { pl_level[id] = 4; }
    else if(
ratio >= 8) { pl_level[id] = 3; }
    else if(
ratio >= 6) { pl_level[id] = 2; }
    else if(
ratio >= 2) { pl_level[id] = 1; }
    else if(
ratio 2) { pl_level[id] = 0; }
    
client_print_color(idGrey"^4[CSD]^3 Tu es au^4 niveau %d^3 de limitation.^4 (%s)"pl_level[id], g_levels_names[pl_level[id]]);
    if(
pl_level[id]) { check_weapons(id); }
}

public 
client_spawn(id)
{
    if(!
is_user_alive(id)) { return HAM_IGNORED; }
    if(
get_pcvar_num(g_disable_plugin)) { set_task(0.5"check_ratio"id); }
    return 
HAM_IGNORED;
}

public 
check_weapons(id)
{
    if(
get_pcvar_num(g_disable_plugin) && is_user_alive(id)) 
    {
        new 
weapon get_user_weapon(id);
        for(new 
0<= pl_level[id] && sizeof(g_levels); i++)
        {
            if(
g_levels[i] & (<< weapon))
            {
                new 
weapon_name[32];
                
get_weaponname(weaponweapon_namecharsmax(weapon_name));
                
engclient_cmd(id"drop"weapon_name);
            }
        }
    }
    return 
PLUGIN_HANDLED;
}

public 
armoury_entity_touch(armouryid)
{
    if(
get_pcvar_num(g_disable_plugin) && is_user_alive(id)) { if(is_player(id) && is_user_alive(id)  && !user_pickup_weapon(idcs_get_armoury_type(armoury))) { return HAM_SUPERCEDE; } }
    return 
HAM_IGNORED;
}

public 
weapon_box_touch(weapon_boxid)
{
    if(
get_pcvar_num(g_disable_plugin) && is_user_alive(id)) { if(is_player(id) && is_user_alive(id) && (pev(weapon_boxpev_flags) & FL_ONGROUND) && !get_pdata_bool(idm_bUsesShield) && !user_pickup_weapon(idcs_get_weaponbox_type(weapon_box))) { return HAM_SUPERCEDE; } }
    return 
HAM_IGNORED;
}

cs_get_weaponbox_type(weapon_box)
{
    new 
weapon;
    for(new 
i=1i<=5i++)
    {
        
weapon get_pdata_cbase(weapon_boxm_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX);
        if(
weapon 0) { return cs_get_weapon_id(weapon); }
    }
    return 
0;
}

bool:user_pickup_weapon(idweapon_type)
{
    for(new 
0<= pl_level[id] && sizeof(g_levels); i++) { if(g_levels[i] & (<< weapon_type)) { return false; } }
    return 
true;
}

public 
current_weapon(id)
{
    if(
get_pcvar_num(g_disable_plugin))
    {
        new 
clipammo;
        new 
weapon get_user_weapon(idclipammo);
        for(new 
0<= pl_level[id] && sizeof(g_levels); i++)
        {
            if(
g_levels[i] & (<< weapon) || cs_get_user_shield(id))
            {
                
client_cmd(id"drop");
                
client_print_color(idGrey"^4[CSD]^3 Tu n'as pas le droit a cette arme !");
            }
        }
    }
    return 
PLUGIN_HANDLED;


My greats salutations.

Unkolix 02-26-2013 02:26

Re: How to block the buy of a weapon and what's my error ?
 
I suggest you to look at Dunn0's VIP plugin and search for handle cmd. It stops from buying AWP, SG550 and G3SG1.

MiniBrackeur 02-26-2013 06:12

Re: How to block the buy of a weapon and what's my error ?
 
Yes, I have think to look in the "snipers restrict" or "restemenu.amxx", thank's for the idea.
Have you got an other idea for my problem 1 or 2 ? ^^'

Unkolix 02-26-2013 06:37

Re: How to block the buy of a weapon and what's my error ?
 
As soon as I'll get home I'll try to help you.

MiniBrackeur 02-26-2013 07:15

Re: How to block the buy of a weapon and what's my error ?
 
Ok, thank's you :)

Unkolix 02-26-2013 08:41

Re: How to block the buy of a weapon and what's my error ?
 
Try doing like this:
PHP Code:

/*Before plugin init*/
new const weaponnames[][] =
{
    
"awp""sg550""g3sg1""scout""m249" //And so on

/*In plugin init*/
for(new 0sizeof weaponnamesi++)
register_clcmd(weaponnames[i], "HandleCmd")
/*After plugin init*/
public HandleCmd(id)
{
    
client_printidprint_center"This weapon is restricted!" );
    return 
PLUGIN_HANDLED


This method should fix all your problems.


All times are GMT -4. The time now is 21:49.

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