Weekday, hour and minute check
#1

When it is saturday and the time is 00:00 my script should update the DB using a query but it just doesn't work.
This are the timer and functions
resettimer = SetTimer("resettime", 60000, 1);

Код:
public resettime()
{
	new tmphour;
	new tmpminute;
	new tmpsecond;
	new day,month,year;
	new weekday;
	gettime(tmphour, tmpminute, tmpsecond);
	getdate(day, month, year);
	weekday = GetWeekdayNum(day, month, year);
	
	if(weekday == 6 && tmphour == 0 && tmpminute == 0)
	{
	    	new querypanel[500];
			format(querypanel, sizeof(querypanel), "UPDATE playeraccounts SET pRunners = 0, pArrests = 0, pTickets = 0, pDConf = 0, pLConf = 0, pLGive = 0, pTOrders = 0, pHealed = 0, pContracts = 0, pNews = 0, pLive = 0, pDDep = 0, pMaDep = 0, pMoDep = 0, pWK = 0, pWD = 0, pMUsed = 0");
			mysql_tquery(handle, querypanel);
	}
	return 1;
}

public GetWeekdayNum(day,month,year) //by d.wine
{
        month-=2;
        if(month<=0)
                {
                year--;
                month+=12;
                }
        new cen = year/100;
        year=getrem(year,100);
        new w = day + ((13*month-1)/5) + year + (year/4) + (cen/4) - 2*cen;
        w=getrem(w,7);
        if (w==0) w=7;
        return w-1;
}

getrem(a,b) //get remnant of division
{
        new div = a/b;
        new left = a-b*div;
        return left;
}
Reply
#2

bump
Reply
#3

Query doesn't contain any specific data, so this should be all that you need: http://forum.sa-mp.com/showthread.ph...vent+scheduler
Running a timer every minute is seriously inefficient considering the function itself would only get executed 0.00009920634% of the time.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Query doesn't contain any specific data, so this should be all that you need: http://forum.sa-mp.com/showthread.ph...vent+scheduler
Running a timer every minute is seriously inefficient considering the function itself would only get executed 0.00009920634% of the time.
Would't it work if i use the query like this because i need the query to be used from the gamemode?
Код:
	
if(tmphour == 0 && tmpminute == 0)
	{
	    	new querypanel[500];
			format(querypanel, sizeof(querypanel), "UPDATE playeraccounts SET pRunners = 0, pArrests = 0, pTickets = 0, pDConf = 0, pLConf = 0, pLGive = 0, pTOrders = 0, pHealed = 0, pContracts = 0, pNews = 0, pLive = 0, pDDep = 0, pMaDep = 0, pMoDep = 0, pWK = 0, pWD = 0, pMUsed = 0 WHERE	DAYOFWEEK(CURDATE()) = '6'");
			mysql_tquery(handle, querypanel);
	}
Reply
#5

You're completely missing the point here. No, you don't need to run it from the gamemode because a) the query itself does not contain anything special and doesn't even have to be formatted and b) because having a timer that's just eating up CPU 99.9999% of the time is totally inefficient.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
You're completely missing the point here. No, you don't need to run it from the gamemode because a) the query itself does not contain anything special and doesn't even have to be formatted and b) because having a timer that's just eating up CPU 99.9999% of the time is totally inefficient.
Would this work ?
Код:
CREATE
    EVENT `reset_column`
    ON SCHEDULE EVERY 1 WEEK STARTS '2016-02-15 00:00:00'
    DO BEGIN
   UPDATE playeraccounts SET pRunners = 0, pArrests = 0, pTickets = 0, pDConf = 0, pLConf = 0, pLGive = 0, pTOrders = 0, pHealed = 0, pContracts = 0, pNews = 0, pLive = 0, pDDep = 0, pMaDep = 0, pMoDep = 0, pWK = 0, pWD = 0, pMUsed = 0
    END */$$
DELIMITER ;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)