Raised This Month: $ Target: $400
 0% 

Using #define to set command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-12-2013 , 11:07   Using #define to set command
Reply With Quote #1

Hello everybody,

I have this code here :

PHP Code:
#define SAY_COMMAND_INV    pmodel

new szSayCommandSlash[64],szSayCommand[64]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
formatex(szSayCommand,charsmax(szSayCommand) - 1,            "say %s",    SAY_COMMAND_INV)
    
formatex(szSayCommandSlash,charsmax(szSayCommandSlash) - 1,    "say /%s",    SAY_COMMAND_INV)
    
    
register_clcmd(szSayCommand,"Test")
    
register_clcmd(szSayCommandSlash,"Test")

But I get this error :
Quote:
I:\AMXXdev\PStudio\temp682.sma(32) : error 017: undefined symbol "pmodel"
If I set
PHP Code:
#define SAY_COMMAND_INV    pmodel 
to
PHP Code:
#define SAY_COMMAND_INV    "pmodel" 
the command isn't working ingame.

Anyone knows how to solve that?
__________________

Last edited by Kia; 05-12-2013 at 11:07.
Kia is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 05-12-2013 , 11:16   Re: Using #define to set command
Reply With Quote #2

First off you need a space after the
Code:
 #define variable value
Secondly why a define?

Also charsmax is already sizeof -1

And Lastly just register the command exactly.

Code:
 register_clcmd ("say /command", "CallBack");
Or you can hook say and day team and compare it that way

Last edited by Doc-Holiday; 05-12-2013 at 11:21.
Doc-Holiday is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-12-2013 , 11:33   Re: Using #define to set command
Reply With Quote #3

1. There is a space, maybe wasn't copied correctly.
2. Why not?
3. I dont want to Hook Say for that, isn't a possible to use register_clcmd?

Sorry, I went full retard, didn't check the log. -_-
Quote:
[AMXX] Plugin "test.amxx" failed to load: Module/Library "iwasabi" required for plugin. Check modules.ini.
Working now.

PHP Code:
new const szSayCommandSlash[]     = "say /pmodel"
new const szSayCommand[]         = "say pmodel"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd(szSayCommand        ,"Test")
    
register_clcmd(szSayCommandSlash,"Test")
}

public 
Test(id)
{
    
user_kill(id)

__________________

Last edited by Kia; 05-12-2013 at 11:51.
Kia is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 05-12-2013 , 13:15   Re: Using #define to set command
Reply With Quote #4

Quote:
Originally Posted by Kia View Post
1. There is a space, maybe wasn't copied correctly.
2. Why not?
3. I dont want to Hook Say for that, isn't a possible to use register_clcmd?

Sorry, I went full retard, didn't check the log. -_-


Working now.

PHP Code:
new const szSayCommandSlash[]     = "say /pmodel"
new const szSayCommand[]         = "say pmodel"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd(szSayCommand        ,"Test")
    
register_clcmd(szSayCommandSlash,"Test")
}

public 
Test(id)
{
    
user_kill(id)

why would you use arrays for registring it as a command? It's easier to put the string into your register_clcmd() instead of creating an array (this will save CPU)
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
didoWEE
Senior Member
Join Date: Oct 2012
Location: Bulgaria
Old 05-12-2013 , 13:27   Re: Using #define to set command
Reply With Quote #5

Quote:
Originally Posted by Napoleon_be View Post
(this will save CPU)
Won't it save Memory instead of CPU? Or I'm wrong?
didoWEE is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-12-2013 , 13:18   Re: Using #define to set command
Reply With Quote #6

I use it as a template for some other plugins and don't want to search it all the time.
__________________
Kia is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-12-2013 , 13:37   Re: Using #define to set command
Reply With Quote #7

Quote:
Originally Posted by Kia View Post
I use it as a template for some other plugins and don't want to search it all the time.
You should use a define here. Creating a global var for that is pointless since the string is used only in plugin_init(). To save memory, that' something you should use directly in plugin_init.
__________________
Arkshine is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-12-2013 , 13:38   Re: Using #define to set command
Reply With Quote #8

There also used in some functions, there just not shown here.
I made several strings, but I'll make them defines, thanks for information.
__________________

Last edited by Kia; 05-12-2013 at 13:39.
Kia is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 05-12-2013 , 18:39   Re: Re: Using #define to set command
Reply With Quote #9

Quote:
Originally Posted by Kia View Post
There also used in some functions, there just not shown here.
I made several strings, but I'll make them defines, thanks for information.
If they are used in multiple places according to Connor it's better to have a global var.
Doc-Holiday is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 05-12-2013 , 22:43   Re: Using #define to set command
Reply With Quote #10

PHP Code:
stock register_custom_clcmd(const szCommand[],const szFunction[],iFlags 0,const szInfo[]="")
{
    static 
szBuffer[192];

    
formatex(szBuffer,charsmax(szBuffer),"/%s",szCommand);
    
register_clcmd(szBuffer,szFunction,iFlags,szInfo);

    
formatex(szBuffer,charsmax(szBuffer),"%s",szCommand);
    
register_clcmd(szBuffer,szFunction,iFlags,szInfo);

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 05-12-2013 at 22:43. Reason: Edited from YAP Pug MOD (Rukia)
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
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 16:20.


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