OnPlayerLogin - setting of vars
#1

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
Reply
#2

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;
Reply
#3

This is it. Thanks.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)