SA-MP Forums Archive
Stuck on mktime - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Stuck on mktime (/showthread.php?tid=215077)



Stuck on mktime - .Com - 22.01.2011

I keep getting this damn error!

(48967) : error 021: symbol already defined: "mktime"

Код:
stock mktime(hour,minute,second,day,month,year) {
	new timestamp2;

	timestamp2 = second + (minute * 60) + (hour * 3600);

	new days_of_month[12];

	if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
			days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
		} else {
			days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
		}
	new days_this_year = 0;
	days_this_year = day;
	if(month > 1) { // No January Calculation, because its always the 0 past months
		for(new i=0; i<month-1;i++) {
			days_this_year += days_of_month[i];
		}
	}
	timestamp2 += days_this_year * 86400;

	for(new j=1970;j<year;j++) {
		timestamp2 += 31536000;
		if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
	}

	return timestamp2;
Can someone please explain to me what to do with this?


Re: Stuck on mktime - Deji - 22.01.2011

You appear to have another mktime function somewhere. We'd need to see more of the code to be of any help.


Re: Stuck on mktime - Jeffry - 22.01.2011

Just call it differently. Change 'mktime' to 'mktime2' or something else.

The Error appears because you already have a function that is called 'mktime'.


Re: Stuck on mktime - .Com - 22.01.2011

Oh sorry! i forgot to add the rest lol
Код:
stock mktime(hour,minute,second,day,month,year) {
	new timestamp2;

	timestamp2 = second + (minute * 60) + (hour * 3600);

	new days_of_month[12];

	if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
			days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
		} else {
			days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
		}
	new days_this_year = 0;
	days_this_year = day;
	if(month > 1) { // No January Calculation, because its always the 0 past months
		for(new i=0; i<month-1;i++) {
			days_this_year += days_of_month[i];
		}
	}
	timestamp2 += days_this_year * 86400;

	for(new j=1970;j<year;j++) {
		timestamp2 += 31536000;
		if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
	}

	return timestamp2;
}
forward IsBadGun(weaponid);
public IsBadGun(weaponid) {
	if(weaponid==8||weaponid==9||(weaponid>15&&weaponid<22)||weaponid==27||(weaponid>34&&weaponid<43)||weaponid>43) {
		return 1;
	}
	return 0;
}
forward GetUnixTime();
public GetUnixTime() {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime(Hour,Minute,Second,Day,Month,Year);
}
forward GetUnixTimeDays(extradays);
public GetUnixTimeDays(extradays) {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime(Hour,Minute,Second,Day+extradays,Month,Year);
}



Re: Stuck on mktime - Jeffry - 22.01.2011

Meh.
Try this:
pawn Код:
stock mktime2(hour,minute,second,day,month,year) {
    new timestamp2;

    timestamp2 = second + (minute * 60) + (hour * 3600);

    new days_of_month[12];

    if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
            days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
        } else {
            days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
        }
    new days_this_year = 0;
    days_this_year = day;
    if(month > 1) { // No January Calculation, because its always the 0 past months
        for(new i=0; i<month-1;i++) {
            days_this_year += days_of_month[i];
        }
    }
    timestamp2 += days_this_year * 86400;

    for(new j=1970;j<year;j++) {
        timestamp2 += 31536000;
        if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
    }

    return timestamp2;
}
forward IsBadGun(weaponid);
public IsBadGun(weaponid) {
    if(weaponid==8||weaponid==9||(weaponid>15&&weaponid<22)||weaponid==27||(weaponid>34&&weaponid<43)||weaponid>43) {
        return 1;
    }
    return 0;
}
forward GetUnixTime();
public GetUnixTime() {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime2(Hour,Minute,Second,Day,Month,Year);
}
forward GetUnixTimeDays(extradays);
public GetUnixTimeDays(extradays) {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime2(Hour,Minute,Second,Day+extradays,Month,Year);
}



Re: Stuck on mktime - .Com - 22.01.2011

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Meh.
Try this:
pawn Код:
stock mktime2(hour,minute,second,day,month,year) {
    new timestamp2;

    timestamp2 = second + (minute * 60) + (hour * 3600);

    new days_of_month[12];

    if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
            days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
        } else {
            days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
        }
    new days_this_year = 0;
    days_this_year = day;
    if(month > 1) { // No January Calculation, because its always the 0 past months
        for(new i=0; i<month-1;i++) {
            days_this_year += days_of_month[i];
        }
    }
    timestamp2 += days_this_year * 86400;

    for(new j=1970;j<year;j++) {
        timestamp2 += 31536000;
        if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
    }

    return timestamp2;
}
forward IsBadGun(weaponid);
public IsBadGun(weaponid) {
    if(weaponid==8||weaponid==9||(weaponid>15&&weaponid<22)||weaponid==27||(weaponid>34&&weaponid<43)||weaponid>43) {
        return 1;
    }
    return 0;
}
forward GetUnixTime();
public GetUnixTime() {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime2(Hour,Minute,Second,Day,Month,Year);
}
forward GetUnixTimeDays(extradays);
public GetUnixTimeDays(extradays) {
new Year, Month, Day,Hour,Minute,Second;
getdate(Year, Month, Day);
gettime(Hour,Minute,Second);
return mktime2(Hour,Minute,Second,Day+extradays,Month,Year);
}
Alright it worked with this. I kinda get it haha so you basicly just added a 2 to the mktime's?


Re: Stuck on mktime - Jeffry - 22.01.2011

Yes.

Anywhere in your script the 'mktime' has already been defined, thats why the error came. If this happens again, just change the name of the new function, and it will be fixed.
In this case, I just added the 2. I could also add 'xyz'.


Re: Stuck on mktime - .Com - 22.01.2011

Wow that was easy!
Thanks guys