SA-MP Forums Archive
Help to create Game Time. - 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: Help to create Game Time. (/showthread.php?tid=386659)



Help to create Game Time. - Laure - 21.10.2012

Hey, Can i get some help to add Game time in my script which will be situated on the lower right corner of your window
which displays like this: Game Time: Hours:Minute:Second.

Thanks in advance.


Re: Help to create Game Time. - Laure - 21.10.2012

Isnt here anyone who can help?


Re: Help to create Game Time. - XtremeR - 21.10.2012

well, i'd suggest u to take it from ladmin or use this: https://sampforum.blast.hk/showthread.php?tid=257071


Re: Help to create Game Time. - caki - 21.10.2012

It is not created by me from forum.
pawn Код:
new Text:txtTimeDisp;
new hour, minute;
new timestr[32];

forward UpdateTimeAndWeather();

//--------------------------------------------------

new fine_weather_ids[] = {1,2,3,4,5,6,7,12,13,14,15,17,18,24,25,26,27,28,29,30,40};
new foggy_weather_ids[] = {9,19,20,31,32};
new wet_weather_ids[] = {8};

stock UpdateWorldWeather()
{
    new next_weather_prob = random(100);
    if(next_weather_prob < 70)      SetWeather(fine_weather_ids[random(sizeof(fine_weather_ids))]);
    else if(next_weather_prob < 95) SetWeather(foggy_weather_ids[random(sizeof(foggy_weather_ids))]);
    else                            SetWeather(wet_weather_ids[random(sizeof(wet_weather_ids))]);
}

//--------------------------------------------------

//new last_weather_update=0;

public UpdateTimeAndWeather()
{
    // Update time
    gettime(hour, minute);
    format(timestr,32,"%02d:%02d",hour,minute);
    TextDrawSetString(txtTimeDisp,timestr);
    SetWorldTime(hour);
   
    new x=0;
    while(x!=MAX_PLAYERS) {
        if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE) {
            SetPlayerTime(x,hour,minute);
         }
         x++;
    }

    /* Update weather every hour
    if(last_weather_update == 0) {
        UpdateWorldWeather();
    }
    last_weather_update++;
    if(last_weather_update == 60) {
        last_weather_update = 0;
    }*/

}

//--------------------------------------------------

public OnGameModeInit()
{
    // Init our text display
    txtTimeDisp = TextDrawCreate(605.0,25.0,"00:00");
    TextDrawUseBox(txtTimeDisp, 0);
    TextDrawFont(txtTimeDisp, 3);
    TextDrawSetShadow(txtTimeDisp,0); // no shadow
    TextDrawSetOutline(txtTimeDisp,2); // thickness 1
    TextDrawBackgroundColor(txtTimeDisp,0x000000FF);
    TextDrawColor(txtTimeDisp,0xFFFFFFFF);
    TextDrawAlignment(txtTimeDisp,3);
    TextDrawLetterSize(txtTimeDisp,0.5,1.5);
   
    UpdateTimeAndWeather();
    SetTimer("UpdateTimeAndWeather",1000 * 60,1);

    return 1;
}

//--------------------------------------------------

public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid,txtTimeDisp);
   
    gettime(hour, minute);
    SetPlayerTime(playerid,hour,minute);
   
    return 1;
}

//--------------------------------------------------

public OnPlayerDeath(playerid, killerid, reason)
{
    TextDrawHideForPlayer(playerid,txtTimeDisp);
    return 1;
}

//--------------------------------------------------

public OnPlayerConnect(playerid)
{
    gettime(hour, minute);
    SetPlayerTime(playerid,hour,minute);
    return 1;
}

//--------------------------------------------------



Re: Help to create Game Time. - Laure - 21.10.2012

@caki is that a FS?


Re: Help to create Game Time. - Adil - 21.10.2012

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(string, "/time", true) == 0)
    {
        new hour, minute, second;
        gettime(hour,minute,second);
        format(string, sizeof(string), "~w~%d:0%d", hour, minute);
        GameTextForPlayer(playerid, string, 5000, 1);
        return 1;
    }
}
You can use textdraws instead of GameTextForPlayer if you want to. The server time is taken from the time of your computer.


Re: Help to create Game Time. - Laure - 21.10.2012

I want it to show up 24/7 without enterting any cmd.


Re: Help to create Game Time. - Adil - 21.10.2012

Quote:
Originally Posted by Imperor
Посмотреть сообщение
I want it to show up 24/7 without enterting any cmd.
You just need to create a textdraw instead of using GameTextForPlayer.
https://sampwiki.blast.hk/wiki/TextDrawCreate
https://sampwiki.blast.hk/wiki/TextDrawShowForPlayer
https://sampwiki.blast.hk/wiki/TextDrawSetString


Re: Help to create Game Time. - caki - 21.10.2012

Quote:
Originally Posted by Imperor
Посмотреть сообщение
@caki is that a FS?
No it is a code but it is better to use this on your main script. Just copy the code into your script in the right places. Complie and test it


Re: Help to create Game Time. - Laure - 21.10.2012

Oh thank you i made it.