Tupi Posted October 10, 2020 Share Posted October 10, 2020 În acest tutorial vă voi prezenta cum se poate afișa data cât și ora pe server. Înainte de toate eu am folosit include-ul: a_samp și am definit FUNCTION #include <a_samp> #define function%0(%1) forward %0(%1); public %0(%1) 1. Creăm două variabile, una pentru dată, iar celalaltă pentru oră. new Text: ServerDate; new Text: ServerTime; 2. Creăm două textdraw-uri globale, unul pentru dată și unul pentru oră. ServerDate = TextDrawCreate(576.999694, 31.525890, "10.10.2020"); TextDrawLetterSize(ServerDate, 0.271666, 1.309629); TextDrawAlignment(ServerDate, 2); TextDrawColor(ServerDate, -1); TextDrawSetShadow(ServerDate, 0); TextDrawSetOutline(txtDateDisp, 1); TextDrawBackgroundColor(ServerDate, 255); TextDrawFont(ServerDate, 2); TextDrawSetProportional(ServerDate, 1); ServerTime = TextDrawCreate(577.000122, 14.933329, "00:00"); TextDrawLetterSize(ServerTime, 0.484999, 1.890370); TextDrawAlignment(ServerTime, 2); TextDrawColor(ServerTime, -1); TextDrawSetShadow(ServerTime, 0); TextDrawSetOutline(ServerTime, 1); TextDrawBackgroundColor(ServerTime, 255); TextDrawFont(ServerTime, 3); TextDrawSetProportional(ServerTime, 1); 3. Mergem la OnGameModeInit și vom crea un timer global cu intervalul de 1 secundă. public OnGameModeInit() { OneSecondTimer = SetTimer("OneSecond", 1000, true); return 1; } 4. Creăm funcția care va fi apelată la fiecare secundă de către timer-ul creat. function OneSecond() { new hour, min, sec, year, month, day, dateString[32], timeString[32]; //cream variabilele necesare gettime(hour, min, sec); //luam ora, minutele si secundele getdate(year, month, day); //luam anul, luna si ziua format(dateString, 32, "~w~%02d/%02d/%d", day, month, year); //formatam string-ul pentru data cu valorile luate mai sus format(timeString, 32, "~w~%02d:%02d:%02d",hour, min, sec); //formatam string-ul pentru ora cu valorile luate mai sus TextDrawSetString(ServerDate, dateString); //Setam textdraw-ului pentru data string-ul formatat mai sus TextDrawSetString(ServerTime, timeString); //Setam textdraw-ului pentru ora string-ul formatat mai sus TextDrawShowForAll(ServerDate); //Afisam tuturor jucatorilor textdraw-ul pentru data TextDrawShowForAll(ServerTime); //Afisam tuturor jucatorilor textdraw-ul pentru ora return 1; } Cam așa se poate afișa data și ora pe server. Sper că v-a fost de ajutor acest tutorial. Pentru orice întrebare/nelămurire puteți trimite un PM la un Programmer sau să deschideți un topic in secțiunea Help and Discussions. Link to comment Share on other sites More sharing options...
CouldnoT Posted October 10, 2020 Share Posted October 10, 2020 Hey, Congratulations for this great tutorial. getTime() probably gets the timing of the hosting machine, can we base our time on something else? ( a timestamp for example ). Link to comment Share on other sites More sharing options...
Tupi Posted October 10, 2020 Author Share Posted October 10, 2020 9 minutes ago, CouldnoT said: Hey, Congratulations for this great tutorial. getTime() probably gets the timing of the hosting machine, can we base our time on something else? ( a timestamp for example ). Answer is no, because it is not possible for the timestamp time to be server time on host (timestamp time is your computer time). If you have a localhost server, your server have your computer time (of the host practically). Link to comment Share on other sites More sharing options...
CouldnoT Posted October 10, 2020 Share Posted October 10, 2020 @Tupi I don't have idea if timestamp is predefined this way for SA:MP what I meant by timestamp is export the timestamp timing from a site web ( timestamp : is the number of seconds counted starting from 1970 I can't remember the exact date ), so, all I have to do to regulate the date is so it can match the real timing is my country, for example. hour = hour - 1; Am I right? Link to comment Share on other sites More sharing options...
Tupi Posted October 11, 2020 Author Share Posted October 11, 2020 (edited) 12 hours ago, CouldnoT said: hour = hour - 1; Am I right? @CouldnoT This statement is extraordinarily false, it has absolutely nothing to do with that. You neet call API for date and time for the date and time of a country different from yours. Edited October 11, 2020 by Tupi Link to comment Share on other sites More sharing options...
CouldnoT Posted October 11, 2020 Share Posted October 11, 2020 1 hour ago, Tupi said: You neet call API for date and time for the date and time of a country different from yours. Provide an example. Link to comment Share on other sites More sharing options...
Tupi Posted October 11, 2020 Author Share Posted October 11, 2020 5 minutes ago, CouldnoT said: Provide an example. forward MyHttpResponse(index, response_code, data[]); public OnPlayerCommandText(playerid, cmdtext[]) { if (!strcmp("/hello",cmdtext,true)) { HTTP(playerid, HTTP_GET, "kc.gd/hello.txt", "", "MyHttpResponse"); return 1; } return 0; } public MyHttpResponse(index, response_code, data[]) { new buffer[ 128 ]; if (response_code == 200) { format(buffer, sizeof(buffer), "The URL replied: %s", data); SendClientMessage(index, 0xFFFFFFFF, buffer); } else { format(buffer, sizeof(buffer), "The request failed! The response code was: %d", response_code); SendClientMessage(index, 0xFFFFFFFF, buffer); } } It's not too complicated, but I don't know how many I understand. Link to comment Share on other sites More sharing options...
CouldnoT Posted October 12, 2020 Share Posted October 12, 2020 @Tupi Missing some information, but I get the idea. Link to comment Share on other sites More sharing options...
Tupi Posted October 15, 2020 Author Share Posted October 15, 2020 Link to comment Share on other sites More sharing options...
Recommended Posts