String formatting problem
#1

So I made a /setvip command a long time ago and today I added the 30 day package thing, but I have a problem with formatting the days and hours that are left.

Here is my code:

Код:
// this is just a part of my /stats command
	if(pInfo[playerid][pVip] > 0)
	{
	    new vtime = pInfo[playerid][pVipTime] - gettime(), days, hours, str[64];
		vtime /= 60;
		vtime /= 60;
		hours = vtime % 60;
		vtime /= 24;
		days = vtime % 24;
		format(str, sizeof(str), "{FFFF40}Remaining time:{FFFFFF}%i days, %i hours\n", days, hours);
		strcat(string, str);
	}
// The /setvip command
pInfo[id][pVipTime] = gettime() + 30*24*60*60;
I checked the code few times but I can't figure out what I did wrong.
It says that there are 12 days and 59 hours left, so am I blind or what?
Reply
#2

Bump
Reply
#3

So many equations, and calculations... Have you tried seeing the output of each variable at each step?

Where'd you get that calculation from? And what's the usage of the setvip, how long is it supposed to give? Are you looking at expanding it to allow for '/setvip 30' or '/setvip 180' in terms of time allowance?


You could SendClientMessage the variables info to yourself in the commands, and that could be something simple to try read more into the miscalculation.
Reply
#4

"gettime(), days, hours," is totally wrong.

https://sampwiki.blast.hk/wiki/Gettime
Код:
new Hour, Minute, Second, Timestamp;
Timestamp = gettime(Hour, Minute, Second);
Reply
#5

PHP код:
// use this
vtime /= 60 60;
hours vtime 24;
days vtime 24;
// or that to save one div operation
#emit load.s.pri vtime
#emit const.alt 3600
#emit sdiv
#emit const.alt 24
#emit sdiv // each div operation always calculates the quotient and remainder at once
#emit stor.s.alt hours
#emit stor.s.pri days 
Reply
#6

Nero has the best plan... Avoid the weird calculations, and try simplify it. The top section is what should be good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)