SA-MP Forums Archive
Adding a new stock - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Adding a new stock (/showthread.php?tid=311443)



Adding a new stock - Libra_PL - 16.01.2012

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


Re: Adding a new stock - Vince - 16.01.2012

Use a definition for that.


Re: Adding a new stock - MP2 - 16.01.2012

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;
}



Respuesta: Adding a new stock - OPremium - 16.01.2012

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