AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about register_plugin (https://forums.alliedmods.net/showthread.php?t=309829)

PurposeLessx 08-08-2018 15:35

Question about register_plugin
 
Hello friends,
I want to know what is different about these codes and also which one is the best I should use.
Thanks for helping.

1st
PHP Code:

public plugin_init() {
    
register_plugin("Plugin""1.0""PurposeLess");


2nd
PHP Code:

#define PLUGIN "Plugin"
#define VERSION "1.0"
#define AUTHOR "PurposeLess" 

3rd
PHP Code:

new const PLUGIN[] = "Plugin";
new const 
VERSION[] = "1.0";
new const 
AUTHOR[] = "PurposeLess"


HamletEagle 08-08-2018 15:37

Re: Question about register_plugin
 
Short version: doesn't matter.

PurposeLessx 08-08-2018 15:43

Re: Question about register_plugin
 
Quote:

Originally Posted by HamletEagle (Post 2609143)
Short version: doesn't matter.

That's mean there is no any different about these in plugins have long or short lines, isn't that?

Relaxing 08-08-2018 15:53

Re: Question about register_plugin
 
2nd and 3rd version use more lines, that's the difference.

PurposeLessx 08-08-2018 15:58

Re: Question about register_plugin
 
Quote:

Originally Posted by Relaxing (Post 2609148)
2nd and 3rd version use more lines, that's the difference.

When should I use new const & static const and #define?

For example;
create_entity("info_target");
and
entity classname

Why people use this code?
PHP Code:

new const entity[] = "info_target";
new const 
classname[] = "parachute" example

create_entity
(entity);
entity_set_string(para_ent[id],EV_SZ_classname,classname); 


Ghosted 08-08-2018 16:08

Re: Question about register_plugin
 
Code:

new const String[] = "string";

function(String)

And


Code:

function("string");
Are same afaik from C++, in 2nd, "string" is another const variable that's only inside that native.
About #define, it will replace everything with ur value and compiles code

Code:

#define A "string"

function(A);

is same as

Code:

function("string");

HamletEagle 08-08-2018 16:12

Re: Question about register_plugin
 
Quote:

Originally Posted by PurposeLessx (Post 2609145)
That's mean there is no any different about these in plugins have long or short lines, isn't that?

Why do you even worry about something that is going to be called ONCE per map?

PurposeLessx 08-08-2018 16:17

Re: Question about register_plugin
 
I know they do same things but must be different. I heard that we should use new const instead of define because of server cache. I have to know lots of information about these, I guess.

I am not worry about that. I just wondered. I am worry about entity classname problem because of I don't know which one is the best to use.

CrazY. 08-08-2018 18:05

Re: Question about register_plugin
 
new const means initialize variables that will never be changed, this mean, keep with a permanent value, then, let's suppose you will create 40 entities with classname info_target. To not occupy much memory I believe it would be best to create a variable with the string info_target instead of define each one.


Code:


new const g_pszNameInfoTarget[] = "info_target";

something()
{
        create_entity(g_pszNameInfoTarget);
        create_entity(g_pszNameInfoTarget);
        create_entity(g_pszNameInfoTarget);
        create_entity(g_pszNameInfoTarget);
        create_entity(g_pszNameInfoTarget);
}

instead of

Code:

something()
{
        create_entity("info_target");
        create_entity("info_target");
        create_entity("info_target");
        create_entity("info_target");
        create_entity("info_target");
}


PurposeLessx 08-09-2018 15:49

Re: Question about register_plugin
 
So, for this?

PHP Code:

set_pev(idpev_healthFloat:pev(idpev_health) + 10.0);

// or 

new Float:health pev(idpev_health);
set_pev(idpev_healthhealth 10.0);

// or

new Float:health pev(idpev_health);
health += 10.0;
set_pev(idpev_healthhealth); 



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

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