[HELP]Stocks
#1

I Need Help In Understanding Stocks, for eg, This one

pawn Код:
stock SendAdminMessage(col, string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pAdmin] > 0)
            SendClientMessage(i, col, string);
    }

    return 1;
}
Reply
#2

Putting stock infront of your function name basically means that the compiler won't warn you if you haven't used the function anywhere.
Read more here: https://sampwiki.blast.hk/wiki/Stock_Functions

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
This is called a for loop. This loop in particular will go from 0 - 499. It stops before i reaches a value of 500, hence 499.

(MAX_PLAYERS is usually defined as 500)

Using this is the equivalent of putting 1000~ lines of code as such:
pawn Код:
if(PlayerInfo[0][pAdmin] > 0)
 SendClientMessage(0, col, string);

if(PlayerInfo[1][pAdmin] > 0)
 SendClientMessage(1, col, string);

if(PlayerInfo[2][pAdmin] > 0)
 SendClientMessage(2, col, string);
// and so on from 0 > 499
Read more about the for loop here: https://sampwiki.blast.hk/wiki/Keywords:Statements#for

pawn Код:
if(PlayerInfo[i][pAdmin] > 0)
This appears to check if the player's admin level is above 0; 1 and upwards. If it is, then it executes this line of code:

pawn Код:
SendClientMessage(i, col, string);
This is a function that sends the player a message.
Read more here: https://sampwiki.blast.hk/wiki/SendClientMessage
Reply
#3

Thanks...
Reply
#4

To summarize it, it sends a message to all the online admins.
I hope this helped you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)