Having a constant time for everybody!
#1

'Sup y'all?

First of all, I'm using this FS from 'admigo'; that's why these credits will go for him!

pawn Код:
public OnFilterScriptInit()
    {
            print("\n--------------------------------------");
            print(" Admigo's Gametimer + Gameday!");
            print("--------------------------------------\n");
            return 1;
    }

    public OnFilterScriptExit()
    {
            return 1;
    }

    #else

    main()
    {
            print("\n----------------------------------");
            print(" Blank Gamemode by your name here");
            print("----------------------------------\n");
    }
    new Text:time;
    #endif
    new gametime;
    new h=0;
    new m=0;
    new d=1;
    //new Text:monday;
    public OnGameModeInit()
    {
            print("\n--------------------------------------");
            print(" Admigo's Gametimer + Gameday Loaded!");
            print("--------------------------------------\n");

            SetWorldTime(0);
            time = TextDrawCreate(605.0,25.0,"00:00");
            TextDrawUseBox(time, 0);
            TextDrawFont(time, 3);
            TextDrawSetShadow(time,0); // no shadow
            TextDrawSetOutline(time,2); // thickness 1
            TextDrawBackgroundColor(time,0x000000FF);
            TextDrawColor(time,0xFFFFFFFF);
            TextDrawAlignment(time,3);
            TextDrawLetterSize(time,0.5,1.5);
            KillTimer(gametime);
            gametime = SetTimer("IncreaseTime", 1000, true);//1000
            /*monday = TextDrawCreate(610.000000,7.000000,"Sunday");
            TextDrawUseBox(monday,0);
            TextDrawFont(monday,1);
            TextDrawLetterSize(monday,0.6,1.5);
            TextDrawSetShadow(monday,1);
            TextDrawSetOutline(monday ,0);
            TextDrawBackgroundColor(monday, 0x000000FF);
            TextDrawBoxColor(monday ,0x00000066);
            TextDrawColor(monday,0xFFFFFFFF);
            TextDrawTextSize(monday , -1880.0, -1880.0);
            TextDrawAlignment(monday,3);
            TextDrawSetOutline(monday,1);*/


            return 1;
    }

    public OnGameModeExit()
    {
            return 1;
    }

    forward IncreaseTime(playerid);


    public OnPlayerConnect(playerid)
    {
        //TextDrawShowForPlayer(playerid,monday);
        GetPlayerTimeEx(playerid, h, m);
        //TextDrawShowForPlayer(playerid, time);
        return 1;
    }

    public OnPlayerDisconnect(playerid, reason)
    {
        return 1;
    }

    public OnPlayerDeath(playerid, killerid, reason)
    {
        return 1;
    }
    public OnPlayerCommandText(playerid, cmdtext[])
    {
      return 0;
    }
    public IncreaseTime(playerid)
    {

        new string[20];
        GetPlayerTimeEx(playerid, h, m);
        //TextDrawShowForPlayer(playerid, time);
        m++;

        if(m == 60)
        {
            h++;
            m = 0;
        }
        if(h == 24)
        {
            h = 0;
        }
        if(h == 0 && m == 0)
        {
            d ++;
        }
        /*if(h == 0 && d == 8 && m == 0)
        {
            SendRconCommand("gmx");//or if you want to make more weeks you can add this:d = 8; and look farther in the day part;)
        }*/

        /*if(h == 0 && d == 2 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Monday");
            TextDrawSetString(monday,"Monday");
        }
        if(h == 0 && d == 3 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Tuesday");
            TextDrawSetString(monday,"Tuesday");
        }
        if(h == 0 && d == 4 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Wednesday");
            TextDrawSetString(monday,"Wednesday");
        }
        if(h == 0 && d == 5 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Thursday");
            TextDrawSetString(monday,"Thursday");
        }
        if(h == 0 && d == 6 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Friday");
            TextDrawSetString(monday,"Friday");
        }
        if(h == 0 && d == 7 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Saturday");
            TextDrawSetString(monday,"Saturday");
        }
        if(h == 0 && d == 1 && m ==0)
        {
            SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Sunday");
            TextDrawSetString(monday,"Sunday");
        }*/


        format(string, sizeof(string), "%d", h);
        //TextDrawShowForPlayer(playerid, monday);
        SetPlayerTimeEx(playerid, h, m);

        if(h >= 0 && h < 10 && m >= 0&&m < 10)
        {
            format(string, sizeof(string), "0%d:0%d", h, m);
            TextDrawSetString(time,string);
        }
        else if(h >= 10 && m >= 10)
        {
            format(string, sizeof(string), "%d:%d", h, m);
            TextDrawSetString(time,string);
        }
        else if(h >= 10 && m >= 0&&m < 10)
        {
            format(string, sizeof(string), "%d:0%d", h, m);
            TextDrawSetString(time,string);
        }
        else if(h >= 0 && h < 10 && m >= 10)
        {
            format(string, sizeof(string), "0%d:%d", h, m);
            TextDrawSetString(time,string);
        }
        if(h== 1 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 1:00");
            SetWorldTime(1);
            return 1;
        }
        if(h== 2 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 2:00");
            SetWorldTime(2);
            return 1;
        }
        if(h== 3 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 3:00");
            SetWorldTime(3);
            return 1;
        }
        if(h== 4 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 4:00");
            SetWorldTime(4);
            return 1;
        }
        if(h== 5 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 5:00");
            SetWorldTime(5);
            return 1;
        }
        if(h== 6 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 6:00");
            SetWorldTime(6);
            return 1;
        }
        if(h== 7 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 7:00");
            SetWorldTime(7);
            return 1;
        }
        if(h== 8 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 8:00");
            SetWorldTime(8);
            return 1;
        }
        if(h== 0 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 0:00");
            SetWorldTime(0);
            return 1;
        }
        if(h== 9 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 9:00");
            SetWorldTime(9);
            return 1;
        }
        if(h== 10 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 10:00");
            SetWorldTime(10);
            return 1;
        }
        if(h== 11 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 11:00");
            SetWorldTime(11);
            return 1;
        }
        if(h== 12 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 12:00");
            SetWorldTime(12);
            return 1;
        }
        if(h== 13 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 13:00");
            SetWorldTime(13);
            return 1;
        }
        if(h== 14 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 14:00");
            SetWorldTime(14);
            return 1;
        }
        if(h== 15 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 15:00");
            SetWorldTime(15);
            return 1;
        }
        if(h== 16 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 16:00");
            SetWorldTime(16);
            return 1;
        }
        if(h== 17 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 17:00");
            SetWorldTime(17);
            return 1;
        }
        if(h== 18 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 18:00");
            SetWorldTime(18);
            return 1;
        }
        if(h== 19 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 19:00");
            SetWorldTime(19);
            return 1;
        }
        if(h== 20 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 20:00");
            SetWorldTime(20);
            return 1;
        }
        if(h== 21 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 21:00");
            SetWorldTime(21);
            return 1;
        }
        if(h== 22 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 22:00");
            SetWorldTime(22);
            return 1;
        }
        if(h== 23 && m==0)
        {
            //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 23:00");
            SetWorldTime(23);
            return 1;
        }
        return 1;//h
    }
    stock SetToNull(playerid)
    {
        SetPlayerTimeEx(playerid, 0, 0);
        return 1;
    }
    stock SetPlayerTimeEx(playerid, hour, minute)
    {
        SetPVarInt(playerid, "hours", hour);
        SetPVarInt(playerid, "minutes", minute);
        return 1;
    }
    stock GetPlayerTimeEx(playerid, &hour, &minute)
    {
        hour = GetPVarInt(playerid, "hours");
        minute = GetPVarInt(playerid, "minutes");
        return 1;
    }
All right, now whenever I restart my server with a GMX for example, the time starts at '0:00'. So far, so good. I let the time pass...until it's 8:00 AM for example. The sun will shine then. Now, I'mma relog (disconnect) and join the server again. My time is again 0:00 AM! I want that the time is for EVERY player who joins my server constant and won't get reset after a disconnect. Which ways would make this possible?
Reply
#2

That's probably the most inefficient code that I have ever seen... Anyway, add this under OnPlayerConnect:
pawn Код:
SetPlayerTime(playerid, h, m);
Reply
#3

You got everything pinpointed to a playerid. The time is global, the showing is per-player basis.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
That's probably the most inefficient code that I have ever seen... Anyway, add this under OnPlayerConnect:
pawn Код:
SetPlayerTime(playerid, h, m);
Not trying to argue with you(as you have more Rep points then me LOLs),but,I am pretty sure placing the function under OnPlayerConnect will return error "Function already defined".
Reply
#5

Quote:
Originally Posted by Cjgogo
Посмотреть сообщение
Not trying to argue with you(as you have more Rep points then me LOLs),but,I am pretty sure placing the function under OnPlayerConnect will return error "Function already defined".
Where did you get that from? That's completely incorrect.

ON TOPIC: Use SetPlayerTime under OnPlayerConnect.
Reply
#6

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Where did you get that from? That's completely incorrect.

ON TOPIC: Use SetPlayerTime under OnPlayerConnect.
:O,but for me it does so,really,it says function already defined unless I don't place it inside another function,THAT'S where I got it from,from my own exeperienced gamemode error,okay,if you're a genius,tell me how to fix it,as I DO NOT have the function anywhere in the gamemode before.
EDIT:I MEANT "symbol already defined"
Reply
#7

SetWorldTime part couldve easy be rewritten to "if(m == 0) SetWorldTime(h);" Code is higly inconsistent en will result in a lot of headaches over time. Please use your own system (in less then 15 lines instead of 2000) as you will be able to maintain it more easily.
Reply
#8

Try with this:
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xFF0000AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_VIOLETBLUE 0x8A2BE2AA
#define COLOR_DEADCONNECT 0x808080AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_FORESTGREEN 0x228B22AA
#define COLOR_DODGERBLUE 0x1E90FFAA
#define COLOR_DARKOLIVEGREEN 0x556B2FAA
#define COLOR_ORANGE 0xFFA500AA
#define COLOR_PURPLE 0x800080AA
#define COLOR_ROYALBLUE 0x4169FFAA
#define COLOR_ERROR 0xD2691EAA
#define COLOR_PINK 0xFF0080FF
#define COLOR_SEXYGREEN 0x00FF00FF
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIME 0x10F441AA
#define COLOR_ADMIN 0x10F441AA // Currently Lime.
#define COLOR_CYAN 0x40FFFFFF
#define COLOR_ORANGERED 0xFF4500AA
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Admigo's Gametimer + Gameday!");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}
#endif
new Text:time;
new gametime;
new h=0;
new m=0;
new d=1;
//new Text:monday;
public OnGameModeInit()
{
    print("\n--------------------------------------");
    print(" Admigo's Gametimer + Gameday Loaded!");
    print("--------------------------------------\n");

    SetWorldTime(0);
    time = TextDrawCreate(605.0,25.0,"00:00");
    TextDrawUseBox(time, 0);
    TextDrawFont(time, 3);
    TextDrawSetShadow(time,0); // no shadow
        TextDrawSetOutline(time,2); // thickness 1
        TextDrawBackgroundColor(time,0x000000FF);
        TextDrawColor(time,0xFFFFFFFF);
        TextDrawAlignment(time,3);
    TextDrawLetterSize(time,0.5,1.5);
    KillTimer(gametime);
        gametime = SetTimer("IncreaseTime", 1000, true);//1000
        /*monday = TextDrawCreate(610.000000,7.000000,"Sunday");
    TextDrawUseBox(monday,0);
    TextDrawFont(monday,1);
    TextDrawLetterSize(monday,0.6,1.5);
    TextDrawSetShadow(monday,1);
    TextDrawSetOutline(monday ,0);
    TextDrawBackgroundColor(monday, 0x000000FF);
    TextDrawBoxColor(monday ,0x00000066);
    TextDrawColor(monday,0xFFFFFFFF);
    TextDrawTextSize(monday , -1880.0, -1880.0);
    TextDrawAlignment(monday,3);
    TextDrawSetOutline(monday,1);*/


    return 1;
}

public OnGameModeExit()
{
    return 1;
}

forward IncreaseTime(playerid);


public OnPlayerConnect(playerid)
{
    //TextDrawShowForPlayer(playerid,monday);
    GetPlayerTimeEx(playerid, h, m);
    SetPlayerTimeEx(playerid, h, m);
    //TextDrawShowForPlayer(playerid, time);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
  return 0;
}
public IncreaseTime(playerid)
{

    new string[20];
    GetPlayerTimeEx(playerid, h, m);
    //TextDrawShowForPlayer(playerid, time);
    m++;

    if(m == 60)
    {
        h++;
        m = 0;
    }
    if(h == 24)
    {
        h = 0;
    }
    if(h == 0 && m == 0)
    {
        d ++;
    }
    /*if(h == 0 && d == 8 && m == 0)
    {
        SendRconCommand("gmx");//or if you want to make more weeks you can add this:d = 8; and look farther in the day part;)
    }
    if(h == 0 && d == 2 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Monday");
        TextDrawSetString(monday,"Monday");
    }
    if(h == 0 && d == 3 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Tuesday");
        TextDrawSetString(monday,"Tuesday");
    }
    if(h == 0 && d == 4 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Wednesday");
        TextDrawSetString(monday,"Wednesday");
    }
    if(h == 0 && d == 5 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Thursday");
        TextDrawSetString(monday,"Thursday");
    }
    if(h == 0 && d == 6 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Friday");
        TextDrawSetString(monday,"Friday");
    }
    if(h == 0 && d == 7 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Saturday");
        TextDrawSetString(monday,"Saturday");
    }
    if(h == 0 && d == 1 && m ==0)
    {
        SendClientMessageToAll(COLOR_WHITE,"[GAME DAY] Sunday");
        TextDrawSetString(monday,"Sunday");
    }*/

    format(string, sizeof(string), "%d", h);
    //TextDrawShowForPlayer(playerid, monday);
    SetPlayerTimeEx(playerid, h, m);
    if(h >= 0 && h < 10 && m >= 0&&m < 10)
    {
        format(string, sizeof(string), "0%d:0%d", h, m);
        TextDrawSetString(time,string);
    }
    else if(h >= 10 && m >= 10)
    {
        format(string, sizeof(string), "%d:%d", h, m);
        TextDrawSetString(time,string);
    }
    else if(h >= 10 && m >= 0&&m < 10)
    {
        format(string, sizeof(string), "%d:0%d", h, m);
        TextDrawSetString(time,string);
    }
    else if(h >= 0 && h < 10 && m >= 10)
    {
        format(string, sizeof(string), "0%d:%d", h, m);
        TextDrawSetString(time,string);
    }
    if(h== 1 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 1:00");
        SetWorldTime(1);
        return 1;
    }
    if(h== 2 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 2:00");
        SetWorldTime(2);
        return 1;
    }
    if(h== 3 && m==0)
    {
      //  SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 3:00");
        SetWorldTime(3);
        return 1;
    }
    if(h== 4 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 4:00");
        SetWorldTime(4);
        return 1;
    }
    if(h== 5 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 5:00");
        SetWorldTime(5);
        return 1;
    }
    if(h== 6 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 6:00");
        SetWorldTime(6);
        return 1;
    }
    if(h== 7 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 7:00");
        SetWorldTime(7);
        return 1;
    }
    if(h== 8 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 8:00");
        SetWorldTime(8);
        return 1;
    }
    if(h== 0 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 0:00");
        SetWorldTime(0);
        return 1;
    }
    if(h== 9 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 9:00");
        SetWorldTime(9);
        return 1;
    }
    if(h== 10 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 10:00");
        SetWorldTime(10);
        return 1;
    }
    if(h== 11 && m==0)
    {
      //  SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 11:00");
        SetWorldTime(11);
        return 1;
    }
    if(h== 12 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 12:00");
        SetWorldTime(12);
        return 1;
    }
    if(h== 13 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 13:00");
        SetWorldTime(13);
        return 1;
    }
    if(h== 14 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 14:00");
        SetWorldTime(14);
        return 1;
    }
    if(h== 15 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 15:00");
        SetWorldTime(15);
        return 1;
    }
    if(h== 16 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 16:00");
        SetWorldTime(16);
        return 1;
    }
    if(h== 17 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 17:00");
        SetWorldTime(17);
        return 1;
    }
    if(h== 18 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 18:00");
        SetWorldTime(18);
        return 1;
    }
    if(h== 19 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 19:00");
        SetWorldTime(19);
        return 1;
    }
    if(h== 20 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 20:00");
        SetWorldTime(20);
        return 1;
    }
    if(h== 21 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 21:00");
        SetWorldTime(21);
        return 1;
    }
    if(h== 22 && m==0)
    {
       // SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 22:00");
        SetWorldTime(22);
        return 1;
    }
    if(h== 23 && m==0)
    {
        //SendClientMessageToAll(COLOR_WHITE,"[GAME TIME] 23:00");
        SetWorldTime(23);
        return 1;
    }
    return 1;//h
}
stock SetToNull(playerid)
{
    SetPlayerTimeEx(playerid, 0, 0);
    return 1;
}
stock SetPlayerTimeEx(playerid, hour, minute)
{
    SetPVarInt(playerid, "hours", hour);
    SetPVarInt(playerid, "minutes", minute);
    return 1;
}
stock GetPlayerTimeEx(playerid, &hour, &minute)
{
    hour = GetPVarInt(playerid, "hours");
    minute = GetPVarInt(playerid, "minutes");
    return 1;
}
PD: As Vince said, it's an inefficient code. You should use gl_realtime, which comes for default with the SA-MP Server.

_______________________
And Cjgogo, what you said is incorrect. He isn't defining a function here, he's using it. Try use two SendClientMessage, one below other. It won't give you errors. Salutari! Hehe...
_______________________

Best regards.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)