AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register "+command" from client? (https://forums.alliedmods.net/showthread.php?t=234208)

mlar98 01-27-2014 05:11

Register "+command" from client?
 
Hello. I'm using a plugin for unlimited ammo, but I want the plugin to show a message when the client press the reload button. The command is "+reload" so I tried this:
PHP Code:

register_clcmd("+reload""ShowMessage")

public 
ShowMessage(id)
{
     
client_print(idprint_center"You don't need to recharge.")


But no success :( , also tried with register_concmd, the same. How can I do to register a command like "+command" ? Thank you in advance.

DavidJr 01-27-2014 05:17

Re: Register "+command" from client?
 
If you want to hook reload, you can detect reload button with fakemeta like this:

PHP Code:

#define XO_PLAYER 5
#define m_afButtonPressed 246

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Add your code here...
}

public 
client_PreThink(id)
{
    new 
iButtonPressediButtonReleased;
    
iButtonPressed get_pdata_int(idm_afButtonPressedXO_PLAYER);
    
    if (
iButtonPressed IN_RELOAD)
    {
        
//do something here;
    
}



hornet 01-27-2014 05:40

Re: Register "+command" from client?
 
What you've done is close enough to reinvented the game engine method. Therefore effectively the same as register Ham_Weapon_Reload, but very inefficient.

DavidJr 01-27-2014 06:08

Re: Register "+command" from client?
 
He said that he uses unlimited ammo, Ham_Weapon_Reload won't be called because the ammo won't be 0? :oops:

mlar98 01-27-2014 06:20

Re: Register "+command" from client?
 
Hello. Thank you for your help, the Ham_Weapon_Reload method seems to be not working when there's no reload, I mean, if you press the reload button but there's no reload, it doesn't work.
Now my other question, how can I block clients for reloading? Reloading is not needed :)
Again, thank you in advance.

DavidJr 01-27-2014 06:22

Re: Register "+command" from client?
 
You can use Ham_Weapon_Reload and return HAM_SUPERCEDE it ;)

mlar98 01-27-2014 06:34

Re: Register "+command" from client?
 
Quote:

Originally Posted by DavidJr (Post 2091458)
You can use Ham_Weapon_Reload and return HAM_SUPERCEDE it ;)

Sorry if i'm too stupid but, How? :oops:

simanovich 01-27-2014 06:38

Re: Register "+command" from client?
 
Quote:

Originally Posted by mlar98 (Post 2091460)
Sorry if i'm too stupid but, How? :oops:

RTFM :nono:

DavidJr 01-27-2014 06:39

Re: Register "+command" from client?
 
PHP Code:

RegisterHam(Ham_Weapon_Reload"weapon_*""fwd_Weapon_Reload"); 

PHP Code:

public fwd_Weapon_Reload(iEnt)
{
return 
HAM_SUPERCEDE;


weapon_* is your weapon entity.

mlar98 01-27-2014 07:00

Re: Register "+command" from client?
 
Quote:

Originally Posted by DavidJr (Post 2091465)
PHP Code:

RegisterHam(Ham_Weapon_Reload"weapon_*""fwd_Weapon_Reload"); 

PHP Code:

public fwd_Weapon_Reload(iEnt)
{
return 
HAM_SUPERCEDE;


weapon_* is your weapon entity.

THANK YOU! :D Now I got all working with this code:

PHP Code:

RegisterHam(Ham_Weapon_Reload"weapon_deagle""fwd_Weapon_Reload");

public 
fwd_Weapon_Reload(iEnt)
{
    
set_task(0"Message");
    return 
HAM_SUPERCEDE
}  

public 
Message(id)
{
    
client_print(idprint_center"You don't need to recharge.")


PD: For some strange reason (I think because of the iEnt index) client_print doesn't work, it needs the set_task function.

Quote:

Originally Posted by simanovich (Post 2091463)
RTFM :nono:

Sorry, I didn't know how to search about this.


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

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