AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using #define to set command (https://forums.alliedmods.net/showthread.php?t=215798)

Kia 05-12-2013 11:07

Using #define to set command
 
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?

Doc-Holiday 05-12-2013 11:16

Re: Using #define to set command
 
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

Kia 05-12-2013 11:33

Re: Using #define to set command
 
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)



Napoleon_be 05-12-2013 13:15

Re: Using #define to set command
 
Quote:

Originally Posted by Kia (Post 1950591)
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)

Kia 05-12-2013 13:18

Re: Using #define to set command
 
I use it as a template for some other plugins and don't want to search it all the time.

didoWEE 05-12-2013 13:27

Re: Using #define to set command
 
Quote:

Originally Posted by Napoleon_be (Post 1950663)
(this will save CPU)

Won't it save Memory instead of CPU? Or I'm wrong?

Arkshine 05-12-2013 13:37

Re: Using #define to set command
 
Quote:

Originally Posted by Kia (Post 1950665)
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.

Kia 05-12-2013 13:38

Re: Using #define to set command
 
There also used in some functions, there just not shown here.
I made several strings, but I'll make them defines, thanks for information.

Doc-Holiday 05-12-2013 18:39

Re: Re: Using #define to set command
 
Quote:

Originally Posted by Kia (Post 1950670)
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.

^SmileY 05-12-2013 22:43

Re: Using #define to set command
 
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);




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

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