Code generator
#1

Hi guys,
I want make one function which create code(for account activation etc...) with time and date.... Code must have 14 numbers(eg. 05100820140611, 05 - hour; 10 - minute; 08 - second; 2014 - year; 06 - month; 11 - day). I made this, but I got negativ code(code in minus).

Код:
stock _SoD_GenerateCode()
{
	new _dan, _mjesec, _godina;
	new _sat, _minuta, _sekunda;
	new _code[15];

	getdate(_godina, _mjesec, _dan);
	gettime(_sat, _minuta, _sekunda);

	format(_code, 15, "%02d%02d%02d%d%02d%02d", _sat, _minuta, _sekunda, _godina, _mjesec, _dan);
	return _code;
}
Reply
#2

Make sure that you're formatting the return of _SoD_GenerateCode() as a string.

pawn Код:
format(string, sizeof string, "%s", _SoD_GenerateCode());
Reply
#3

Just use code = gettime(); lol
Reply
#4

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
Make sure that you're formatting the return of _SoD_GenerateCode() as a string.

pawn Код:
format(string, sizeof string, "%s", _SoD_GenerateCode());
In test command for that function is %s, not %d..

@Pottus

Yeah, but 5 seconds will be 5, I need 05.. It's important to have 14 numbers

@ EDIT: I have this command for test


Код:
CMD:test(playerid, params[])
{
	return va_SendClientMessage(playerid, -1, "Kod je %s.", _SoD_GenerateCode());
}
but I need that code in integrer not like string. I used strval func. but I again had that problem...
Reply
#5

Why not format it like this?
pawn Код:
format(_code, 15, "%i%i%i%i%i%i", _sat, _minuta, _sekunda, _godina, _mjesec, _dan);
Reply
#6

I edited last post... Please, check it..

@ What will %i make with numbers? Like I said, I need code with only 14 numbers, not with 15 or 13 numbers....
Reply
#7

Why should it matter how long it sounds silly to me when gettime() contains all information you need.
Reply
#8

Yeap, look this

10053020140511


10 is hours.. If it's hours less 10, then will be 9 and code will be

9053020140511 and this code have 13 numbers. I need only 14 numbers, so when it's date or time less 10, I need 0 before time/date... Dou You understand now?
Reply
#9

I've just tested it here http://slice-vps.nl:7070/ and it works fine to me.

Код:
Server started.

20233720141010
In which part of the script did you get the negative value?
Reply
#10

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
Yeap, look this

10053020140511


10 is hours.. If it's hours less 10, then will be 9 and code will be

9053020140511 and this code have 13 numbers. I need only 14 numbers, so when it's date or time less 10, I need 0 before time/date... Dou You understand now?
Makes absolutely no sense when gettime() contains all this data all that is required is the correct formatting.

Get this
https://sampforum.blast.hk/showthread.php?tid=347605

Do this
pawn Код:
new year, month, day, hour, minute, second;
TimestampToDate(time, year, month, day, hour, minute, second, 1);
format(line, sizeof(line), "%i/%02i/%02i - %i:%02i:%02i", year, month, day, hour, minute, second);
No need for all that non-sense your trying to do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)