Which 1?
#1

Hello all, I have small question.

Which one "method" is better? And, how much?

1st:

pawn Код:
new PlayerIP[MAX_PLAYERS][16], PlayerName[MAX_PLAYERS][24];

public OnPlayerConnect(playerid)
{
    new Name[24], IP[16];
    strcat(PlayerName[playerid], Name, 24);
    strcat(PlayerIP[playerid], IP, 16);
    return 1;
}

stock GetPlayerIpEx(playerid)
{
    return PlayerIP[playerid];
}

stock GetPlayerNameEx(playerid)
{
    return PlayerName[playerid];
}
2st:


pawn Код:
stock GetPlayerNameEx(playerid)
{
    new pName[24];
    GetPlayerName(playerid, pName, 24);
    return pName;
}

stock GetPlayerIpEx(playerid)
{
    new rIP[16];
    GetPlayerIp(playerid, rIP, 16);
    return rIP;
}
Thanks!
Reply
#2

Test them yours self ?
Reply
#3

Quote:
Originally Posted by Darnell
Посмотреть сообщение
Test them yours self ?
Dont spam? ****** said the same, and Im going to do that.
Reply
#4

I already tested that: CLICK! CLIKC!
loading from variable is faster.
Reply
#5

OK. Now other question.

pawn Код:
stock date(timestamp)
{
    new year = 1970, day = 0, month = 0, hour = 0, mins = 0, sec = 0;
    new days_of_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    new returnstring[21];
    while(timestamp > 31622400)
    {
        timestamp -= 31536000;
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) timestamp -= 86400;
        ++ year;
    }
    if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) days_of_month[1] = 29;
    else days_of_month[1] = 28;
    while(timestamp > 86400)
    {
        timestamp -= 86400;
        ++ day;
        if(day == days_of_month[month]) day = 0, ++ month;
    }
    while(timestamp > 60)
    {
        timestamp -= 60;
        ++ mins;
        if(mins == 60) mins = 0, ++ hour;
    }
    sec = timestamp;
    format(returnstring, 21, "%02d/%02d/%02d %02d:%02d:%02d", year, month + 1, day + 1, hour, mins, sec);
    return returnstring;
}
Is there a way to optimizate this? Because, this function is made ~1,5 years ago, so I think there might be a better way?

Im using mktime function by ****** -

pawn Код:
stock mktime(hour, minute, second, day, month, year) // By: ******
{
    static const
        days_of_month[12] =
        {
            0   * 86400, 31  * 86400, 59  * 86400,
            90  * 86400, 120 * 86400, 151 * 86400,
            181 * 86400, 212 * 86400, 243 * 86400,
            273 * 86400, 304 * 86400, 334 * 86400
        };
    static
        lMonth, lYear, lMonthS, lYearS;
    if (year != lYear)
    {
        year -= 1970;
        lYearS = year * 31536000;
        lYearS += 86400 * (year / 4);
        year += 70;
        lYearS -= (year / 100) * 86400;
        year += 300;
        lYearS += (year / 400) * 86400;
        year += 1600; // 1970 - 370
        lYear = year;
    }
    if (month != lMonth)
    {
        --month;
        lMonthS = days_of_month[month];
        if (IsLeapYear(year) && month >= 2)
        {
            lMonthS += 86400;
        }
        lMonth = month + 1;
    }
    day = (day - 1) * 86400;
    hour = (hour - (0 TIME_ZONE)) * 3600;
    minute = minute * 60;
    return lYearS + lMonthS + day + hour + minute + second;
}
Reply
#6

bumpp Xd
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)