Raised This Month: $ Target: $400
 0% 

Registering cl_cmd


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mankind
Member
Join Date: Jun 2009
Old 06-23-2011 , 20:33   Registering cl_cmd
Reply With Quote #1

Hello everyone, I was wondering how can you register a cl_cmd to a plugin, like for example there is this plugin that is on all the time, but i want it to be on when i a write a text like : /example, and it turns on and shows message that the player did that thing like turned on longjump stats (its not about lj stats, its just example).
PHP Code:
        client_print(0print_chat"%s example"name); 
And I want to make it so when you write again that /example it turns off and says Example turned off example.

PHP Code:
    register_clcmd("say /example""cmd_example_example"ADMIN_ALL); 
Do i need to write theese 2 lines or something more. And how do I specify that I want it just for counter-terrorists that plugin ( they dont need to be admins ).

Hope You understood me!
Thanks!
Mankind
Mankind is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-23-2011 , 23:05   Re: Registering cl_cmd
Reply With Quote #2

What are you trying to turn on and off? Is it something in the same plugin or is it in another plugin controlled by a cvar or command? The answer to this question may change the answer to your question.

This is a simple example for doing this:

PHP Code:
// plugin_init
    
register_clcmd("say /example""cmdExample")

public 
cmdExample(id)
{
    if( 
cs_get_user_team(id) == CS_TEAM_CT // Only allow do something if player is CT.
    
{
        
// Change state of plugin or function being controlled
        
if( /* on */ }
        {
            
// turn off
        
}
        else
        {
            
// turn on
        
}
    }

If this doesn't work or you don't understand then you need to answer my above question and explain exactly what you are using it for.
__________________
fysiks is online now
Mankind
Member
Join Date: Jun 2009
Old 06-24-2011 , 13:07   Re: Registering cl_cmd
Reply With Quote #3

It's the same plugin im trying to turn on and off.

And the plugin im trying to do this is :

PHP Code:
#include <amxmodx>
#include <engine>

#pragma semicolon 1
#define VERSION "1.0"

new Floatthroworigin[3];
new 
Floatdroporigin[3];

public 
plugin_init()
{
    
register_plugin("Drop Distance"VERSION"Drekes");
    
    
register_touch("weaponbox""worldspawn""Fwd_Weapon_Touch");
    
    
register_clcmd("drop""cmd_drop");
}

public 
cmd_drop(id)
    
entity_get_vector(idEV_VEC_originthroworigin);
    
public 
Fwd_Weapon_Touch(weaponworld)
{
    
entity_get_vector(weaponEV_VEC_origindroporigin);
    
    
check_distance();
}

public 
check_distance()
{
    new 
Floatdistance get_distance_f(throworigindroporigin);
    
    
client_print(0print_chat"Drop distance: %.1f"distance);

So it would be something like this ?

PHP Code:
#include <amxmodx>
#include <engine>

#pragma semicolon 1
#define VERSION "1.0"

new Floatthroworigin[3];
new 
Floatdroporigin[3];

public 
plugin_init()
{
    
register_clcmd("say /toss""cmdSpray")

    
register_plugin("Drop Distance"VERSION"Drekes");
    
    
register_touch("weaponbox""worldspawn""Fwd_Weapon_Touch");
    
    
register_clcmd("drop""cmd_drop");
}
public 
cmdSpray(id)
{
          if( 
cs_get_user_team(id) == CS_TEAM_CT )
          {

public 
cmd_drop(id)
    
entity_get_vector(idEV_VEC_originthroworigin);
    
public 
Fwd_Weapon_Touch(weaponworld)
{
    
entity_get_vector(weaponEV_VEC_origindroporigin);
    
    
check_distance();
}

public 
check_distance()
{
    new 
Floatdistance get_distance_f(throworigindroporigin);
    
    
client_print(0print_chat"Drop distance: %.1f"distance);

Ehh, I tried but dont realy seem to do this.

Last edited by Mankind; 06-24-2011 at 18:59.
Mankind is offline
Old 06-24-2011, 19:17
Mankind
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-25-2011 , 03:18   Re: Registering cl_cmd
Reply With Quote #5

Here is one way to do it. You should be able to add things on your own now. If you don't know if it will work, try it first, if it doesn't work try something else. If you can't get it after trying several times then you may post your question.

PHP Code:
#include <amxmodx>
#include <engine>
#include <cstrike> // Include cstrike.inc so we can use cs_get_user_team().

new Floatthroworigin[3];
new 
Floatdroporigin[3];

new 
g_bEnabled true // Enable the plugin by default.  Change to false if you want it disabled by default.

public plugin_init()
{
    
register_plugin("Drop Distance""1.0""Drekes");

    
register_touch("weaponbox""worldspawn""Fwd_Weapon_Touch");

    
register_clcmd("drop""cmd_drop");
    
register_clcmd("say /example""cmdToggleState")
}

public 
cmdToggleState(id)
{
    if( 
cs_get_user_team(id) == CS_TEAM_CT // Check if player using the command is a Counter-Terrorist
    
{
        if( 
g_bEnabled )
        {
            
// Plugin is currently enabled.
            
g_bEnabled false // Disable plugin.
        
}
        else
        {
            
// Plugin is currently disabled.
            
g_bEnabled true // Enable plugin.
        
}
    }
}

public 
cmd_drop(id)
{
    if( 
g_bEnabled // Perform action only if plugin is enabled.
    
{
        
entity_get_vector(idEV_VEC_originthroworigin);
    }
}

public 
Fwd_Weapon_Touch(weaponworld)
{
    if( 
g_bEnabled // Perform action only if plugin is enabled.
    
{
        
entity_get_vector(weaponEV_VEC_origindroporigin);
        
check_distance();
    }
}

public 
check_distance()
{
    new 
Floatdistance get_distance_f(throworigindroporigin);

    
client_print(0print_chat"Drop distance: %.1f"distance);

__________________
fysiks is online now
Mankind
Member
Join Date: Jun 2009
Old 06-26-2011 , 19:35   Re: Registering cl_cmd
Reply With Quote #6

Thanks, works fine, but how do can i set the function client_print, so when the ct writes /toss, it shows %s turned on gun toss distance? I think it goes something like this, but im not completly sure :

PHP Code:
{
new 
name[32];
get_user_name(idname31);
client_print(0print_chat"%s  turned on gun toss distance."name);

Also I tried to do the same with spray stats but it gave me error on line 27 and 57 :

PHP Code:
#include <amxmodx>
#include <engine>
#include <cstrike>

new g_bEnabled true

public plugin_init()
{
      
/* SVC_TEMPENTITY (event #23) event, trigger if parameter 1 is equal to 112 (TE_PLAYERDECAL) */
      
register_event("23""player_spray""a""1=112")

      
register_clcmd("say /spray""cmdToggleState")
}

public 
cmdToggleState(id)
{
    if(
cs_get_user_team(id) == CS_TEAM_CT )
    {
        if( 
g_bEnabled )
        {
            
// Plugin is currently enabled.
            
g_bEnabled false // Disable plugin.
        
}
        else
        {
            
// Plugin is currently disabled.
            
g_bEnabled ture // Enable plugin.
        
}
    }
}

public 
player_spray()
{
      if( 
g_bEnabled // Perform action only if plugin is enabled.
      
{
{
      new 
id read_data(2/* as seen in the include, player index is the second parameter */
      
new iOrigin[3]

      
iOrigin[0] = read_data(3/* and of course, the coordinates... */
      
iOrigin[1] = read_data(4)
      
iOrigin[2] = read_data(5)

      
/* you can get the rest of parameters too if you need them */

      /* now, what you needed... distance... */

      
new iPlayerOrigin[3]

      
get_user_origin(idiPlayerOrigin)

      new 
iDistance get_distance(iPlayerOriginiOrigin)

      
client_print(idprint_chat"You sprayed your spray %d units far."iDistance)

And how can i do the same when you write /spray it shows %s turned on spray stats.

Big thanks for helping me.
Mankind is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2011 , 02:48   Re: Registering cl_cmd
Reply With Quote #7

Quote:
Originally Posted by Mankind View Post
Thanks, works fine, but how do can i set the function client_print, so when the ct writes /toss, it shows %s turned on gun toss distance? I think it goes something like this, but im not completly sure :

PHP Code:
{
new 
name[32];
get_user_name(idname31);
client_print(0print_chat"%s  turned on gun toss distance."name);

That looks correct. You would put that in the code (without the braces) right after it is enabled.

Quote:
Originally Posted by Mankind View Post
Also I tried to do the same with spray stats but it gave me error on line 27 and 57 :
The first error is obvious, look at line 27 and see (I'm assuming you speak english here). The second error shows that you need to close all your braces. You should always check that ever { had a } to match it before posting errors.
__________________
fysiks is online now
Reply


Thread Tools
Display Modes

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 23:33.


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