Raised This Month: $ Target: $400
 0% 

Help with blocking command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-28-2012 , 20:57   Help with blocking command
Reply With Quote #1

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

Last edited by vitorrossi; 08-28-2012 at 20:58.
vitorrossi is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-28-2012 , 21:54   Re: Help with blocking command
Reply With Quote #2

That code only allows once per round. Also, get_user_team().
__________________

Last edited by fysiks; 08-28-2012 at 21:54.
fysiks is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-28-2012 , 22:46   Re: Help with blocking command
Reply With Quote #3

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  
            }
                
        }     
    } 
}

Last edited by vitorrossi; 08-28-2012 at 23:09.
vitorrossi is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-28-2012 , 23:13   Re: Help with blocking command
Reply With Quote #4

Quote:
Originally Posted by vitorrossi View Post
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.
__________________
fysiks is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-28-2012 , 23:34   Re: Help with blocking command
Reply With Quote #5

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?
vitorrossi is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-28-2012 , 23:40   Re: Help with blocking command
Reply With Quote #6

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.
__________________

Last edited by fysiks; 08-28-2012 at 23:41.
fysiks is offline
Old 08-29-2012, 00:02
DjOptimuS
This message has been deleted by DjOptimuS.
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-29-2012 , 00:43   Re: Help with blocking command
Reply With Quote #7

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?

Last edited by vitorrossi; 08-29-2012 at 00:48.
vitorrossi is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-29-2012 , 16:17   Re: Help with blocking command
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
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 is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-29-2012 , 17:10   Re: Help with blocking command
Reply With Quote #9

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!

Last edited by vitorrossi; 08-29-2012 at 17:11.
vitorrossi is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 08-29-2012 , 17:53   Re: Help with blocking command
Reply With Quote #10

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 
            }
                
        }     
    } 
}

Last edited by vitorrossi; 08-29-2012 at 17:54.
vitorrossi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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