1)
Public is used when you want to use that function as a timer or callback, or even if you want to call the function from outside the script using CallRemoteFunction.
In all other cases you don't put anything in front of the function name.
Stock is used for include libraries.
When you write an include that holds different functions but they aren't called directly by code inside that include, you would get warnings about functions being declared which aren't used anywhere.
Putting "stock" in front of it will make the compiler ignore the entire function if it's never used and won't even include it in the compiled amx file.
It basically says: "don't compile and ignore this function if never used".
2)
Using return at the end of a function is required if there is at least one return anywhere inside that function.
pawn Код:
SomeFunction(a, b)
{
if (a > b) return 1000;
}
Functions like this REQUIRE you to add "return 1;" at the end.
Why?
Because it has at least one return statement inside it, you declare the entire function to always return a value, in EVERY situation.
The above function will only return something if a is bigger than b.
But what happens when a is smaller than b?
The code won't know what to do in that situation.
So you make it like this:
pawn Код:
SomeFunction(a, b)
{
if (a > b) return 1000;
return 0;
}
If a is bigger than b, it will return 1000.
If a is equal to b or smaller than b, the if-statement will fail and the compiler needs to know what to do in that case.
By putting "return 0;" (or whatever value you prefer) you declare to return 0 in ALL other situations where you if-statement fails (a = b or a < b).
Now all situations are covered and the compiler will won't generate errors/warnings.