Good Detailed Stock Tutorials?
#1

Title says it all, I want to improve my knowledge in creating stock's.
And I am wondering if there by any chance are good detailed & explained tutorials (with examples Etc.) for it, so far I couldn't find any tutorials based on it besides one. But it didn't help me as good as usual. So therefor I made this topic and searching for a more "advanced" one.

Page that I've already read: https://sampwiki.blast.hk/wiki/Stocks

Thanks in Advance,
Rolyy
Reply
#2

https://sampwiki.blast.hk/wiki/Stocks
Reply
#3

Quote:
Originally Posted by Rolyy
View Post
So far I couldn't find any tutorials based on it besides one. But it didn't help me as good as usual.
Quote:
Originally Posted by Riddick94
View Post
Sorry forgot to add the link at main post.
Link Added.
Reply
#4

stock is a function. So you want to know how to make functions?
Reply
#5

I think there is enough info in that wiki page.
Reply
#6

Quote:
Originally Posted by wups
View Post
I think there is enough info in that wiki page.
Not to be rude, but I am looking for a tutorial.. Not for personal opinions.
Reply
#7

stock is a code to make functions.

It won't send " Symbol is unused "strtok" " if you use stock.

Example :

pawn Code:
strtok( ... )
{
     return 1;
}
If you didn't use it, the compiler will sends a warning except if you use
pawn Code:
#pragma unused strtok
With stock, you can still add it without using it, without any warnings.
pawn Code:
stock strtok( ... )
{
    return 1;
}
Don't use timers or callbacks with stock, instead use forward( ); and public( )
pawn Code:
public OnGameModeInit( )
{
    SetTimer( "gmx", 3000, true );

    return 1;
}

stock gmx( ) // Wrong usage
    return GameModeExit( );

forward gmx( ); public gmx( ) // Correct usage
    return GameModeExit( );
I think wiki is enough.

& ( if you mean &&, scroll the page below ) signs means, you need to create it's own variable first, then use the function. Like :
pawn Code:
stock getName( playerid, &szName ) // idk, if it sends a error try &szName[ 24 ]
{
    GetPlayerName( playerid, szName, sizeof ( szName ) );

    return name; // forgot how to do this :P
}

// Somewhere
new
    name[ 24 ]
;

getName( playerid, name );

print( "%s", name );
About && sign, it means 'And'

Example:
pawn Code:
if ( ( getPlayerName( playerid ) == "Basicz" ) && ( strlen( getPlayerName( playerid ) ) == strlen( "Basicz" ) ) ) { // blablabla } // if playername == basicz and strlen playername == strlen " basicz "

if ( isANoob( playerid ) && GetPlayerMoney( playerid ) < 3500 )
    return Ban( playerid ); // if isanoob && getplayermoney < 3500
A simple one.

Not really advanced, but hope this can help you.

( Im a noob too :P But hope this can help you )
Reply
#8

stock is commonly used for functions that are created and are going to be un-used/used, therefore it will prevent an error caused by the compiler, if the 'stock' keyword is added, the compiler will ignore the function and continue its compiling, if it's used, then of course not, it wouldn't be ignored.

Quote:

For example, if you have a stock that gave the player a vehicle, but you never use it, when you go to compile the compiler wouldn't bothered including it. This makes it advantageous to have large stock libraries stored in includes, as the script will only "extract" the ones it requires upon compiling.

Reply
#9

People seem to misunderstand that stock does not necessarily declares a function. It is merely a modifier. Basicz said pretty much all of it, but you can also use stock when declaring variables;
pawn Code:
new stock MayBeUsed = 1;
This will not generate a warning if the variable is not used. So with that in mind:
Quote:
Originally Posted by Rolyy
View Post
I want to improve my knowledge in creating functions
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)