SA-MP Forums Archive
OnPlayerLogin - setting of vars - 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: OnPlayerLogin - setting of vars (/showthread.php?tid=467673)



OnPlayerConnect - setting of vars - ThomasTailor93 - 04.10.2013

Hello guys,

I've got a simple question. On OnPlayerConnect, I'm setting all variables of "PlayerInfo" to a certain value. Because of the mass of this variables I wanted to ask if there is a shorter way to set ALL variables of the enum "PlayerInfo" in the same time to a certain value in only one line. I remember, that there is a way for but I forgot this already.

Regards, ThomasTailor93


Re: OnPlayerLogin - setting of vars - Dragonsaurus - 04.10.2013

pawn Код:
for(new i; i < _: pInfo; i++) PlayerInfo[playerid][pInfo: i] = 0;
// Change the pInfo with your enum's title.
Example:
pawn Код:
enum LolInfo
{
    Register,
    // Other
    LoggedIn
};
new PlayerInfo[MAX_PLAYERS][LolInfo];
for(new i; i < _: LolInfo; i++) PlayerInfo[playerid][LolInfo: i] = 0;



AW: OnPlayerLogin - setting of vars - ThomasTailor93 - 04.10.2013

This is it. Thanks.


Re: OnPlayerLogin - setting of vars - Pottus - 04.10.2013

There is another way as well call it the ****** method

pawn Код:
enum LolInfo
{
    Register,
    // Other
    LoggedIn
};
new PlayerInfo[MAX_PLAYERS][LolInfo];

MyFunction(playerid)
{
    new tmp[LolInfo];
    PlayerInfo[playerid] = tmp;

}

Try running this here http://slice-vps.nl:7070/

pawn Код:
#include <a_samp>

enum TestInfo
{
    test1,
    test2,
    test3,
}

new Test[TestInfo];

main()
{  
    new tcount = GetTickCount();
   
    for(new i = 0; i < 100000; i++)
    {
        for(new j = 0; j < _: TestInfo; j++)
        {
            Test[TestInfo: j] = 0;
        }

    }
    printf("Method 1 Took - %d Milliseconds", GetTickCount() - tcount);

    tcount = GetTickCount();
   
    for(new i = 0; i < 100000; i++)
    {
        new tmp[TestInfo];
        Test = tmp;
   
    }
    printf("Method 2 Took - %d Milliseconds", GetTickCount() - tcount);

}
[17:22:03] Method 1 Took - 22 Milliseconds
[17:22:03] Method 2 Took - 8 Milliseconds

So indeed the ****** method is faster but it's too small to make any significant difference.


AW: OnPlayerLogin - setting of vars - ThomasTailor93 - 04.10.2013

Well, it's indeed faster. For me it's anyway if 22 or 8 ms. I optimizing other things :P

But thanks for your reply.


Re: OnPlayerLogin - setting of vars - Pottus - 04.10.2013

It wasn't so much for optimizing but just showing another way to do that is just as effective so you can choose your preference