Only for genius in math, help please..
#1

Hello guys. I need to help with math.. xD

I will explain what I need. I have command, in that command as params I am writing seconds. And I need to make from these seconds the minutes. For example: player type /command 60 and I need to make so mod will write to me it is one minute, or /command 120 mod will write 2 minutes. Now harder part: When player type /command 70 I need to make 1 minute and 10 seconds.. Hope you understand!

Reply
#2

Put mod 60. This means that number 60 = 0, 61 = 1, 62 = 2... etc. 90 mod 60 will be 30. It's the "rest" of what is left. If you ****** any with the format: "number1 'mod' number2" ****** will count it for you. This in scripting is the % sign.

For instance if you put: 100 % 60, it will print out 40. If you don't believe me, try this on OnGameModeInit, start your console and use printf to print out the number. Now this will print out the seconds only so far right? You also want the minutes. Then you divide the seconds divided by 60, then you will get the minutes if you round DOWN. Let's say you get 100/60 you will get 1,66... This is greater than 1,5 and closest rounded will be 2 right? But you don't want that. You only care about the number "1" in here. The "0,5" will be counted with the modullus operator % later. If you make it a float and use https://sampwiki.blast.hk/wiki/Floatround you will probably find the answer. Still need help? Just ask. :P I love math btw. xD

Example:
Код:
        new value = 200;
	new Float:minutes, seconds;

	minutes = value / 60;
	new IntMinutes = floatround(minutes, floatround_floor); //minutes are now equals 3.000, therefore we set it to a new INTEGER instead of float this time! Just for designing sake

	seconds = value % 60; //seconds is now = 20

	new all[128];
	format(all, sizeof(all), "Time left: %i minutes and %i seconds!", IntMinutes, seconds);
	printf(all);
EDIT: Edited so it would show 3 minutes in the example instead of 3.0000 xD
Reply
#3

uhh, mate can you put it to my command? I will send code to you check pm, please.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)