String formatting problem - 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: String formatting problem (
/showthread.php?tid=654805)
30 day VIP package -
andrejc999 - 06.06.2018
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?
Re: String formatting problem -
andrejc999 - 09.06.2018
Bump
Re: String formatting problem -
Sew_Sumi - 09.06.2018
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.
Re: String formatting problem -
Awide - 09.06.2018
"gettime(), days, hours," is totally wrong.
https://sampwiki.blast.hk/wiki/Gettime
Код:
new Hour, Minute, Second, Timestamp;
Timestamp = gettime(Hour, Minute, Second);
Re: String formatting problem -
Nero_3D - 09.06.2018
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
Re: String formatting problem -
Sew_Sumi - 09.06.2018
Nero has the best plan... Avoid the weird calculations, and try simplify it. The top section is what should be good.