Adding a new stock
#1

Hey. I'll write this fastly, because I don't have much time. I have this:

Код:
for(new i = 0; i < MaxPariticipants; i++)
{
	if(PlayersAtMinigame[i] != -1 etc...)
	{
I have no idea how to add this into a new stock, LoopThroughParticipants (because I use this over 50 times, would be less code to do this then). The problem is that I don't know how to add with a few brackets. With no one, it would be easy, for example (if return 1 is needed, but I don't need that code below for now):

Код:
stock LoopThroughParticipants()
{
	for(new i = 0; i < MaxPariticipants; i++)
	return 1;
}
So, anyone can give a code of stock using those two things (loop and if...)? I'd be glad if someone would do it (if possible, I think it is).

Thanks
Reply
#2

Use a definition for that.
Reply
#3

Erm, not sure if this is what you're getting at:

pawn Код:
stock LoopThroughParticipants()
{
    for(new i = 0; i < MaxPariticipants; i++)
    {
        if(PlayersAtMinigame[i] != -1 etc.)
        {
            // Do stuff
        }
    }
    return 1;
}
Reply
#4

As Vince said, you need to use definitions:

pawn Код:
#define LoopThroughParticipants() for(new i; i < MaxPariticipants; i++) if(PlayersAtMinigame[i] != -1)
The pre-processor will look for "LoopThroughParticipants()" and replace it with "for(new i; i < MaxPariticipants; i++) if(PlayersAtMinigame[i] != -1)"

So, you can do something like this:

pawn Код:
public OnPlayerConnect(playerid)
{
    LoopThroughParticipants()
    {
        //Do something
    }
}
And it will be interpreted as:

pawn Код:
public OnPlayerConnect(playerid)
{
    for(new i; i < MaxPariticipants; i++) if(PlayersAtMinigame[i] != -1)
    {
        //Do something
    }
}
https://sampforum.blast.hk/showthread.php?tid=166680
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)