AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved prevent weapon reload (https://forums.alliedmods.net/showthread.php?t=344660)

Hakim Azizov 11-25-2023 15:53

prevent weapon reload
 
hi guys. i want a plugin it prevents to reload weapons. can anybody help me?

georgik57 11-26-2023 06:07

Re: prevent weapon reload
 
prevent the manual reload or automatic?

Hakim Azizov 11-26-2023 12:53

Re: prevent weapon reload
 
Quote:

Originally Posted by georgik57 (Post 2813543)
prevent the manual reload or automatic?

only manual bro. admins have unmlimted clip. but they click reload button, i want to stop it. (prevent to push reload button)

i did this code but not worked

Code:

#include <amxmodx>
#include <amxmisc>
#include <amx_settings_api>
#include <cs_ham_bots_api>
#include <dhudmessage>
#include <hamsandwich>
#include <fakemeta_util>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <geoip>
#include <fun>

public plugin_init()
{
            register_forward(FM_CmdStart, "fm_cmd_start")
}

public fm_cmd_start(id, uc_handle, seed)
{
        if (!is_user_alive(id))
                return PLUGIN_HANDLED
       
      // comes from admin's unlimited clip
        //if (g_has_unlimited_clip[id])
        //        if (get_uc(uc_handle, UC_Buttons) & IN_RELOAD)
                //        return PLUGIN_HANDLED

        if (get_user_flags(id) & ADMIN_BAN)
                if (get_uc(uc_handle, UC_Buttons) & IN_RELOAD)
                        return PLUGIN_HANDLED
     
        return PLUGIN_CONTINUE       
}


McTavish 11-26-2023 13:28

Re: prevent weapon reload
 
Quote:

Originally Posted by Hakim Azizov (Post 2813564)
only manual bro. admins have unmlimted clip. but they click reload button, i want to stop it. (prevent to push reload button)

i did this code but not worked

Code:

#include <amxmodx>
#include <amxmisc>
#include <amx_settings_api>
#include <cs_ham_bots_api>
#include <dhudmessage>
#include <hamsandwich>
#include <fakemeta_util>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <geoip>
#include <fun>

public plugin_init()
{
            register_forward(FM_CmdStart, "fm_cmd_start")
}

public fm_cmd_start(id, uc_handle, seed)
{
        if (!is_user_alive(id))
                return PLUGIN_HANDLED
       
      // comes from admin's unlimited clip
        //if (g_has_unlimited_clip[id])
        //        if (get_uc(uc_handle, UC_Buttons) & IN_RELOAD)
                //        return PLUGIN_HANDLED

        if (get_user_flags(id) & ADMIN_BAN)
                if (get_uc(uc_handle, UC_Buttons) & IN_RELOAD)
                        return PLUGIN_HANDLED
     
        return PLUGIN_CONTINUE       
}


I'm bad at coding but try this maybe could help you.
write on chat: /reloadcfg
to give yourself unlimited ammo. After this, you should be able to reload without any restrictions.
Code:

#include <amxmodx>

const ADMIN_FLAGS = ADMIN_LEVEL_B;

public plugin_init() {
    register_plugin("NoReload", "1.0", "McTavish");
   
    register_clcmd("say /reload", "cmd_reload");
    register_clcmd("say !reload", "cmd_reload");
    register_clcmd("say @reload", "cmd_reload");
}

public cmd_reload(id) {
    if (is_user_connected(id) && !(get_user_flags(id) & ADMIN_FLAGS)) {
        client_print(id, print_chat, "You are not allowed to reload weapons!");
        return PLUGIN_HANDLED;
    }
   
    return PLUGIN_CONTINUE;
}

public plugin_cfg() {
    register_clcmd("say /reloadcfg", "cmd_reloadcfg");
    register_clcmd("say !reloadcfg", "cmd_reloadcfg");
    register_clcmd("say @reloadcfg", "cmd_reloadcfg");
}

public cmd_reloadcfg(id) {
    if (get_user_flags(id) & ADMIN_FLAGS) {
        set_user_flags(id, ADMIN_FLAGS);
        client_print(id, print_chat, "You now have unlimited ammo!");
        return PLUGIN_HANDLED;
    }

    return PLUGIN_CONTINUE;
}


Hakim Azizov 11-26-2023 13:32

Re: prevent weapon reload
 
Quote:

Originally Posted by McTavish (Post 2813568)
I'm bad at coding but try this maybe could help you.
write on chat: /reloadcfg
to give yourself unlimited ammo. After this, you should be able to reload without any restrictions.
Code:

#include <amxmodx>

const ADMIN_FLAGS = ADMIN_LEVEL_B;

public plugin_init() {
    register_plugin("NoReload", "1.0", "McTavish");
   
    register_clcmd("say /reload", "cmd_reload");
    register_clcmd("say !reload", "cmd_reload");
    register_clcmd("say @reload", "cmd_reload");
}

public cmd_reload(id) {
    if (is_user_connected(id) && !(get_user_flags(id) & ADMIN_FLAGS)) {
        client_print(id, print_chat, "You are not allowed to reload weapons!");
        return PLUGIN_HANDLED;
    }
   
    return PLUGIN_CONTINUE;
}

public plugin_cfg() {
    register_clcmd("say /reloadcfg", "cmd_reloadcfg");
    register_clcmd("say !reloadcfg", "cmd_reloadcfg");
    register_clcmd("say @reloadcfg", "cmd_reloadcfg");
}

public cmd_reloadcfg(id) {
    if (get_user_flags(id) & ADMIN_FLAGS) {
        set_user_flags(id, ADMIN_FLAGS);
        client_print(id, print_chat, "You now have unlimited ammo!");
        return PLUGIN_HANDLED;
    }

    return PLUGIN_CONTINUE;
}


this code you sent me will not work. because these codes only work with type to chat "reload" word. and when this function calls, it willn't prevent to reload because return PLUGIN_HANDLED can be called to own function

georgik57 11-26-2023 15:17

Re: prevent weapon reload
 
1 Attachment(s)
As this is a forum for learning to script, i've given you explanations of how the code works overall.
Please ask if you don't understand something.
PHP Code:

#include <amxmodx>
#include <fakemeta>

// flags that a user needs to have access to unlimited clip
new g_szAccess[] = "mnopqrstu";

public 
plugin_init()
{
    
register_plugin("Block manual reload""0.0.1""D i 5 7 i n c T")
    
    
// catch the event when the players are pressing a button
    
register_forward(FM_CmdStart"fwFmCmdStartPre")
}

public 
plugin_cfg()
    
g_szAccess[0] = read_flags(g_szAccess);

public 
fwFmCmdStartPre(const iID, const iIDUCHandle)//, const iSeed
{
    
// ignore players that are not alive or connected or don't have the needed flags
    
if (!is_user_alive(iID) || get_user_flags(iID) & g_szAccess[0] != g_szAccess[0])
        return;
    
    
// find what buttons the player is pressing
    
new iBsButtons get_uc(iIDUCHandleUC_Buttons);
    
    
// ignore if he is not pressing the reload button
    
if (!(iBsButtons IN_RELOAD))
        return;
    
    
// he is pressing the reload button. "unpress" it.
    
set_uc(iIDUCHandleUC_ButtonsiBsButtons & ~IN_RELOAD)



Hakim Azizov 11-27-2023 10:00

Re: prevent weapon reload
 
Quote:

Originally Posted by georgik57 (Post 2813571)
As this is a forum for learning to script, i've given you explanations of how the code works overall.
Please ask if you don't understand something.
PHP Code:

#include <amxmodx>
#include <fakemeta>

// flags that a user needs to have access to unlimited clip
new g_szAccess[] = "mnopqrstu";

public 
plugin_init()
{
    
register_plugin("Block manual reload""0.0.1""D i 5 7 i n c T")
    
    
// catch the event when the players are pressing a button
    
register_forward(FM_CmdStart"fwFmCmdStartPre")
}

public 
plugin_cfg()
    
g_szAccess[0] = read_flags(g_szAccess);

public 
fwFmCmdStartPre(const iID, const iIDUCHandle)//, const iSeed
{
    
// ignore players that are not alive or connected or don't have the needed flags
    
if (!is_user_alive(iID) || get_user_flags(iID) & g_szAccess[0] != g_szAccess[0])
        return;
    
    
// find what buttons the player is pressing
    
new iBsButtons get_uc(iIDUCHandleUC_Buttons);
    
    
// ignore if he is not pressing the reload button
    
if (!(iBsButtons IN_RELOAD))
        return;
    
    
// he is pressing the reload button. "unpress" it.
    
set_uc(iIDUCHandleUC_ButtonsiBsButtons & ~IN_RELOAD)



thanks bro. you are real man )


All times are GMT -4. The time now is 12:09.

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