Whats Wrong in This Gameday GameTime System?
#1

Hello..guys as u all know or may not know...im a complete failure in scripting for now tho ..learning slowly slowly...today i was trying to make a ingame gameday and gametime system...look this clock isnt going to work with real world time and day... its gonna work like normal GTA - SA..one hour of this ingame hour will be one minute irl...and one minute will be one second.. it isnt showing any error in compiling tho..

but my problem is -

One second is resulting into one ingame hour..trying getting me? and one minute is passing like one milli second..its working faster than it should be...couldnt figure out the mistake anyway...Help me ._.

My Code - (Includes)
Код:
 #include <a_samp>
#include <sscanf2>
The Defines - They Are Used To Change Color of the textdraw string
Код:
#define COLOR_TIME 0xFFFFFFFF 
#define COLOR_DAY  0xFFFFFFFF
#define MINUTE 1000
My Timer which i forwarded -
Код:
forward GameDay();
The Variables -
Quote:

new Text:gTime;
new Text:gDay;
new gtime=0;
new gday=0;

Under OnGameModeInit -
Код:
SetTimer("Gameday",MINUTE,1);
	
	gTime = TextDrawCreate(605.000000,25.000000,"00:00");
	TextDrawAlignment(gTime,3);
	TextDrawBackgroundColor(gTime,0x000000FF);
	TextDrawFont(gTime,3);
	TextDrawLetterSize(gTime,0.535,2.2);
	TextDrawColor(gTime,COLOR_TIME);
	TextDrawSetOutline(gTime,2);
	TextDrawSetProportional(gTime,1);
	TextDrawSetShadow(gTime,1);

	gDay = TextDrawCreate(610.000000,7.000000,"Sunday");
	TextDrawUseBox(gDay,0);
	TextDrawFont(gDay,3);
	TextDrawLetterSize(gDay,0.6,1.5);
	TextDrawSetShadow(gDay,1);
	TextDrawSetOutline(gDay ,0);
	TextDrawBackgroundColor(gDay, 0x000000FF);
	TextDrawBoxColor(gDay ,0x00000066);
	TextDrawColor(gDay,COLOR_DAY);
	TextDrawTextSize(gDay , -1880.0, -1880.0);
	TextDrawAlignment(gDay,3);
	TextDrawSetOutline(gDay,1);
My Function -
Код:
public Gameday()
{
 	new timestring[256];
  	new daystring[256];
	new gseconds = gtime % 60,
	gminutes = (gtime - gseconds) / 60;
	gtime ++;
	format(timestring, sizeof (timestring), "   %02d:%02d", gminutes, gseconds);
	TextDrawSetString(gTime,timestring);
	TextDrawShowForAll(gTime);
	format(daystring, sizeof (daystring), "%s",GetDayName());
	TextDrawSetString(gDay,daystring);
	TextDrawShowForAll(gDay);
	SetWorldTime(gminutes);
	if(gday==6&&gtime==1440)//One week passed
	{
		gday=0;
		gtime=0;
		//A new week has begun
	}
	if(gtime==1440)//One day passed
	{
		gday++;
		gtime=0;
		format(daystring, sizeof (daystring), "   00:00");
		TextDrawSetString(gTime,daystring);
	}
	return 1;
}
Finally, The Stock -
Код:
stock GetDayName()
{
	new DayName[128];
    switch(gday)
    {
		//All day names can be changed to your language.
		case 0: format(DayName, sizeof(DayName), "Sunday");
        case 1: format(DayName, sizeof(DayName), "Monday");
        case 2: format(DayName, sizeof(DayName), "Tuesday");
        case 3: format(DayName, sizeof(DayName), "Wednesday");
        case 4: format(DayName, sizeof(DayName), "Thursday");
        case 5: format(DayName, sizeof(DayName), "Friday");
        case 6: format(DayName, sizeof(DayName), "Saturday");
    }
    return DayName;
}
Help Me Please - [+REP] i couldnt solve it
Reply
#2

What's gtime?

EDIT: NEvermind I meant what's gseconds? I dont see the reference anywhere.

EDIT2: Took me a second, but I get it now and I see nothing wrong with it. The only thing that might go wrong is that SetTimer is not very accurate. You should look into a post or thread from Slice where he addresses and fixes that issue to most extents to get a more accurate timer, otherwise it should work?
Reply
#3

The Seconds Like 00:01 one is Second..
Reply
#4

u may test it as a filterscript or something
Reply
#5

Help? D:
Reply
#6

@Extremo tried... no use... xD i think its crossing with something in my gamemode...but it shouldnt.. :/ what the fuck
Reply
#7

You've bumped your topic 3 times in 2 hours, read the forum rules.
Quote:
Originally Posted by Forum Rules
No Double Posting - There is a modify button , use it. However, bumping a topic in which you have or require further information is allowed after at least 24 hours. Note that two identical posts appearing at the same time is usually a mistake attributed to lag, and will not be penalized (but the second one will be removed).
You're only allowed to bump your topic once every 24 hours.

EDIT: Also please don't give me a visitor message to visit your topic, if i'm not helping, it's because i can't.
Reply
#8

pawn Код:
#include <a_samp>

#define COLOR_TIME 0xFFFFFFFF
#define COLOR_DAY  0xFFFFFFFF
#define MINUTE 1000

new Text:GameDay, Text:GameTime;
new gTimeMinutes, gTimeHours, gTimeDay;

public OnGameModeInit()
{
    gTimeMinutes = gTimeHours = gTimeDay = 0;
    SetTimer("GameTimeUpdate", MINUTE, true);
    GameTime = TextDrawCreate(605.000000, 25.000000, "00:00");
    TextDrawAlignment(GameTime, 3);
    TextDrawBackgroundColor(GameTime, 0x000000FF);
    TextDrawFont(GameTime, 3);
    TextDrawLetterSize(GameTime, 0.535, 2.2);
    TextDrawColor(GameTime, COLOR_TIME);
    TextDrawSetOutline(GameTime, 2);
    TextDrawSetProportional(GameTime, 1);
    TextDrawSetShadow(GameTime, 1);

    GameDay = TextDrawCreate(610.000000, 7.000000, "Sunday");
    TextDrawUseBox(GameDay, 0);
    TextDrawFont(GameDay, 3);
    TextDrawLetterSize(GameDay, 0.6, 1.5);
    TextDrawSetShadow(GameDay, 1);
    TextDrawSetOutline(GameDay, 0);
    TextDrawBackgroundColor(GameDay, 0x000000FF);
    TextDrawBoxColor(GameDay, 0x00000066);
    TextDrawColor(GameDay, COLOR_DAY);
    TextDrawTextSize(GameDay, -1880.0, -1880.0);
    TextDrawAlignment(GameDay, 3);
    TextDrawSetOutline(GameDay, 1);
    return 1;
}

forward GameTimeUpdate();
public GameTimeUpdate()
{
    if((gTimeMinutes++) >= 59)
    {
        gTimeMinutes -= 60;
        //New hour
        if((gTimeHours++) >= 23)
        {
            gTimeHours -= 24;
            //New day
            if((gTimeDay++) >= 6)
            {
                gTimeDay = 0;
                //New week
            }
        }
    }
    new timestring[15];
    format(timestring, sizeof(timestring), "   %02d:%02d", gTimeHours, gTimeMinutes);
    TextDrawSetString(GameTime, timestring);
    TextDrawShowForAll(GameTime);
    format(timestring, sizeof(timestring), "%s", GetDayName());
    TextDrawSetString(GameDay, timestring);
    TextDrawShowForAll(GameDay);
    SetWorldTime(gTimeHours);
    return 1;
}

GetDayName()
{
    new day[10];
    switch(gTimeDay)
    {
        case 1: day = "Monday";
        case 2: day = "Tuesday";
        case 3: day = "Wednesday";
        case 4: day = "Thursday";
        case 5: day = "Friday";
        case 6: day = "Saturday";
        default: day = "Sunday";
    }
    return day;
}
Already gave him a runthrough of this code, so don't start lecturing me about 'Just posting code'.
Reply
#9

I don't have much to add and I am sure that code is perfectly functional and I'd like to mention, I find that a much more elegant solution than the original one, however the whole "if >=" seems pointless to me. The variable can never exceed 60 in the first place, because the moment it reaches 60, or 24, or 7, it will automatically jump into the if-clause. So why not simply check if it is 60 and set it back to 0 instead of this whole substraction idea?
Reply
#10

Well yeah, it's just a debug just in case something does go wrong and it does happen to go over 60, which is very possible.

I made a /setminute command and I set the minutes to 60 while the timer was about to be called again, and then minutes was at 61. But because I have the subtraction idea, it goes to new hour + 1 second rather than completely resetting the seconds.

The subtraction isn't necessary, but it is better for a more accurate time if anything goes wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)