SA-MP Forums Archive
Code generator - 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: Code generator (/showthread.php?tid=541208)



Code generator - vannesenn - 10.10.2014

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;
}



Re: Code generator - SKAzini - 10.10.2014

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

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



Re: Code generator - Pottus - 10.10.2014

Just use code = gettime(); lol


Re: Code generator - vannesenn - 10.10.2014

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...


Re: Code generator - biker122 - 10.10.2014

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



Re: Code generator - vannesenn - 10.10.2014

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....


Re: Code generator - Pottus - 10.10.2014

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


Re: Code generator - vannesenn - 10.10.2014

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?


Re: Code generator - SimonItaly - 10.10.2014

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?


Re: Code generator - Pottus - 10.10.2014

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.