AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with blocking command (https://forums.alliedmods.net/showthread.php?t=194492)

vitorrossi 08-28-2012 20:57

Help with blocking command
 
Hey guys, I'm trying to write a code that allows players to use the command "impulse 100" twice every round. This is the very first time I try to write a plugin, so please bear with me. I also wanted it to be applied only to CTs but not Ts, and I have no idea how to do that. Could anyone help?
Thank you


Code:

#include <amxmodx>
#include <fun>

new bool:bAlreadyUsed[ 33 ]

public plugin_init()

{   
    register_event( "HLTV" , "evNewRound" , "a" , "1=0" , "2=0" );   
   
    register_clcmd( "impulse 100" , GiveVitamins );
   
}

public evNewRound( )   
    arrayset( bAlreadyUsed , false , sizeof( bAlreadyUsed ) );

public GiveVitamins( id )
{   
    if( is_user_alive( id ) )
    {       
        if( bAlreadyUsed[ id ] )       
        {           
            client_print( id , print_chat , "You already used your Special this round!" );
        }           
       
        else       
        {           
            bAlreadyUsed[ id ] = true 
        }   
    }
}


I tried to edit someone's else code that was trying to do something similar

fysiks 08-28-2012 21:54

Re: Help with blocking command
 
That code only allows once per round. Also, get_user_team().

vitorrossi 08-28-2012 22:46

Re: Help with blocking command
 
Alright I changed the code a little to be applied only to CTs, and added cstrike module. I don't know how to make it to work twice a round rather than once, any hints? Also I am able to compile it, but it does not work


Code:

#include <amxmodx>
#include <cstrike>
#include <fun>


new bool:bAlreadyUsed[ 33 ]

public plugin_init()

{   
    register_event( "HLTV" , "evNewRound" , "a" , "1=0" , "2=0" );   
   
    register_clcmd( "impulse 100" , "GiveVitamins" );
   
}

public evNewRound( )   
    arrayset( bAlreadyUsed , false , sizeof( bAlreadyUsed ) );

public GiveVitamins( id )
{   
    if ( cs_get_user_team(id) == CS_TEAM_CT )
    {
        if( is_user_alive( id ) )
        {       
            if( bAlreadyUsed[ id ] )       
            {           
                client_print( id , print_chat , "You already used your Special this round!" );
            }           
       
            else       
            {           
                bAlreadyUsed[ id ] = true 
            }
               
        }   
    }
}


fysiks 08-28-2012 23:13

Re: Help with blocking command
 
Quote:

Originally Posted by vitorrossi (Post 1785682)
Alright I changed the code a little to be applied only to CTs, and added cstrike module. I don't know how to make it to work twice a round rather than once, any hints?

Study how it works now. Once you understand that you will be much much closer to getting it to work twice per round.

Regarding the error, see any other working plugin that uses the register_clcmd() command and you will see what you've done wrong.

Also, you must check if they are connected (Hint: If they are alive then they are connected) before you can check for their team.

vitorrossi 08-28-2012 23:34

Re: Help with blocking command
 
Alright, I'll keep studying and reading around to see if I learn it. Just a quick question though, since I am trying to block a command that is part of counter-strike and not a command that I created, is this gonna work? From what I understand, this code is only gonna show the message rather than blocking the command, am I right?

fysiks 08-28-2012 23:40

Re: Help with blocking command
 
Right, it doesn't block anything. I thought you got this from existing working code. I don't even know if this method of hooking that command works. Once you get it to compile you will be able to test it (or I'm sure it's posted somewhere on this forum on how to do it).

My advice is to start very simple and test it (just print a message). Then, you can make it more complex by adding things and testing afterwards.

vitorrossi 08-29-2012 00:43

Re: Help with blocking command
 
I based myself off of http://forums.alliedmods.net/showthread.php?p=660187 and http://forums.alliedmods.net/showthread.php?t=178185

I am doing exactly what they did but it is not working. He registers the client command lets say for buy

Code:

register_clcmd("buy", "bblocked");
So from there he is calling the public bblocked

Code:

public bblocked(id)
    {
    ColorChat(id,GREEN, "%L", id, "BLOCK_BUY", szPrefix);
    return PLUGIN_HANDLED
    }

Is that stopping the player from being able to use buy command?

vitorrossi 08-29-2012 16:17

Re: Help with blocking command
 
Quote:

Originally Posted by fysiks (Post 1785706)
Regarding the error, see any other working plugin that uses the register_clcmd() command and you will see what you've done wrong.

I've seen other plugins that use register_clcmd() and also the description at AMX Mod X Documentation. I do not understand what I am doing wrong.

Blockcommands uses

Code:

register_clcmd("buy", "bblocked");
Deathmatch plugin use

Code:

register_clcmd( "say /guns",    "CmdEnableGuns" );
Both buy and say commands are integrated with Counter-Strike as well as impulse 100, I am really not understanding what is going on here

vitorrossi 08-29-2012 17:10

Re: Help with blocking command
 
I figured out that if I include the module engine I can use

Code:

register_impulse(100, "Impulse_100");
Instead of register_clcmd and it works greatly for my purposes. Could you explain to me why the register_clcmd doesn't work? I will try to change some other things now, thank you fysiks for all the help!

vitorrossi 08-29-2012 17:53

Re: Help with blocking command
 
I accomplished what I wanted to. This code allows you to use impulse 100 every 4 second only. Thank you for the help

Final code:

Code:

/* Script generated by Pawn Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <fun>


new Float:LastUsedAbility[ 33 ];

public plugin_init()

{   
    register_plugin ( "Block Impulse 100", "1.0", "v[R]" );   
   
    register_impulse(100, "Impulse_100");
   
}

public Impulse_100( id )
{   
    if ( is_user_alive( id ) )
    {
        if( cs_get_user_team(id) == CS_TEAM_CT )
        {       
           
            new Float:GameTime = get_gametime();
                   
            new iDelay = 4;
           
            if ( GameTime - LastUsedAbility[ id ] < iDelay )
            {
                return PLUGIN_HANDLED
            }           
       
            else       
            {           
                LastUsedAbility[ id ] = get_gametime();
               
                return PLUGIN_CONTINUE
            }
               
        }   
    }
}



All times are GMT -4. The time now is 05:51.

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