AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Return. (https://forums.alliedmods.net/showthread.php?t=220112)

Moody92 07-07-2013 06:08

Return.
 
Hello guys,

I don't know why but I still don't get
PHP Code:

return 

even though I read so many articles

so I actually understand

PHP Code:

return PLUGIN_HANDLED 

and

PHP Code:

return PLUGIN_CONTINUE 

but I saw in some scripts there is

PHP Code:

return 

&
PHP Code:

return -

&
PHP Code:

return Random-Number 

so could someone explain to me how does random number return works ?

Serkan Kischa 07-07-2013 06:09

Re: Return.
 
nope

pokemonmaster 07-07-2013 06:39

Re: Return.
 
I'm horrible in explaining
PHP Code:

// In stocks we just return any number that fits our needs
stock IsUserAliveExampleStock(id)
{
    if(
is_user_alive(id))
    {
        return 
1;
    }
    
    return 
0;
}

public Function(
id)
{
    
// iReturn will hold the value that was returned in the stock
    
new iReturn IsUserAliveExampleStock(id)
    if(
iReturn == 0)
    {
        
console_print(id"You must be alive to use this fuction")
        
        
// This type of return just stops further code,and returns the default return number
        
return;
    }
}

/* If you look in amxconst.inc, you would find these
#define PLUGIN_CONTINUE        0
#define PLUGIN_HANDLED        1
#define PLUGIN_HANDLED_MAIN    2

So you can see that PLUGIN_HANDLED, PLUGIN_CONTINUE and PLUGIN_HANDLED_MAIN are just defines to numbers
and are replaced when the script is compiled to the numbers.
*/ 


Moody92 07-07-2013 06:55

Re: Return.
 
Quote:

Originally Posted by Serkan Kischa (Post 1985223)
nope

Don't bother posting then

Quote:

Originally Posted by pokemonmaster (Post 1985252)
I'm horrible in explaining
Spoiler

Thank you khalid... That was useful.

ConnorMcLeod 07-07-2013 09:55

Re: Return.
 
use PLUGIN_*** when it improves readability and when it makes sense, so in amxx forwards and callbacks, because it means you want to block or not something.

Use true/false when functions are IsUserSomeThing or similar stuff that only return 0 or 1

And use values when functions are similar to get_user_team, get_user_maxspeed

For fakemeta and hamsandwich hooks, use defined returns [HAM/FMRES]_[IGNORED/HANDLED/OVERRIDE/SUPERCEDE]


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

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