[Tutorial]Timp variabil(Ora|Data)

Moderator: Leut.Adv

Locked
User avatar
CataLynHD
Membru
Membru
Posts: 381
Joined: 5 years ago
Location: Rm.Valcea
Has thanked: 0
Been thanked: 0
Zodiac:
Age: 20
Contact:
Status: Offline

5 years ago

Cred ca va intrebati ce am mai pregatit !
Ei bine, un tutorial simplu,consta in depistarea orei si a datei din viata reala in joc(viata virtuala).
Poate ma ve-ti critica ca sunt o gramada de tutoriale pe aceasta tema,dar acesta are ceva mai special sa spun asa.

Specialul consta in:
- simplitate si stil.
- textdraw

Propun sa incepem, deoarece timpul costa bani.




new Text:Clock[MAX_PLAYERS];
new TextataClock[MAX_PLAYERS];
new Text:YearClock[MAX_PLAYERS];

new bool:Change_Clock[MAX_PLAYERS];

new const MonthName[][12] =
{
"Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie",
"Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"
};

//*Variabilele



forward TimeServer(playerid);
//*Forward-ul



public OnPlayerConnect(playerid)
{
Change_Clock[playerid] = false;
return 1;
}
//*Resetare variabile



public OnPlayerSpawn(playerid)
{
Clock[playerid] = TextDrawCreate(550.000000, 30.000000, "22:55");
TextDrawBackgroundColor(Clock[playerid], 255);
TextDrawFont(Clock[playerid], 1);
TextDrawLetterSize(Clock[playerid], 0.500000, 1.000000);
TextDrawColor(Clock[playerid], -1);
TextDrawSetOutline(Clock[playerid], 0);
TextDrawSetProportional(Clock[playerid], 1);
TextDrawSetShadow(Clock[playerid], 1);
TextDrawSetSelectable(Clock[playerid], 0);

DataClock[playerid] = TextDrawCreate(547.000000, 24.000000, "22 decembrie");
TextDrawBackgroundColor(DataClock[playerid], 255);
TextDrawFont(DataClock[playerid], 1);
TextDrawLetterSize(DataClock[playerid], 0.270000, 1.300000);
TextDrawColor(DataClock[playerid], -1);
TextDrawSetOutline(DataClock[playerid], 0);
TextDrawSetProportional(DataClock[playerid], 1);
TextDrawSetShadow(DataClock[playerid], 1);
TextDrawSetSelectable(DataClock[playerid], 0);

YearClock[playerid] = TextDrawCreate(565.000000, 33.000000, "2016");
TextDrawBackgroundColor(YearClock[playerid], 255);
TextDrawFont(YearClock[playerid], 1);
TextDrawLetterSize(YearClock[playerid], 0.270000, 1.300000);
TextDrawColor(YearClock[playerid], -1);
TextDrawSetOutline(YearClock[playerid], 0);
TextDrawSetProportional(YearClock[playerid], 1);
TextDrawSetShadow(YearClock[playerid], 1);
TextDrawSetSelectable(YearClock[playerid], 0);
return 1;
}
//*Textdraw-urile propriu-zise.



public OnPlayerDeath(playerid, killerid, reason)
{
for(new t = 0; t < MAX_TEXT_DRAWS; t++)
{
TextDrawHideForPlayer(playerid, Text:t);
}
return 1;
}
//*Ascunde toate textdraw-urile afisate.



public OnGameModeInit()
{
SetTimer("TimeServer", 10000, true);
return 1;
}
//*Lansare timer.



public TimeServer(playerid)
{
new string[2][256],
str_year[4],
hour,
minute,
second,
year,
month,
day;
getdate(year, month, day);
gettime(hour, minute, second);
SetWorldTime(hour);
if(Change_Clock[playerid]) {
format(str_year, 4, "%d", year);
format(string[0], 256, "%d %s", day, MonthName[month-1]);
TextDrawSetString(DataClock[playerid], string[0]);
TextDrawShowForPlayer(playerid, DataClock[playerid]);
TextDrawShowForPlayer(playerid, YearClock[playerid]);
TextDrawHideForPlayer(playerid, Clock[playerid]);
Change_Clock[playerid] = false;
}
else {
format(string[1], 256, "%s%d:%s%d", (hour < 10) ? ("0") : (""), hour, (minute < 10) ? ("0") : (""), minute);
TextDrawSetString(Clock[playerid], string[1]);
TextDrawShowForPlayer(playerid, Clock[playerid]);
TextDrawHideForPlayer(playerid, DataClock[playerid]);
TextDrawHideForPlayer(playerid, YearClock[playerid]);
Change_Clock[playerid] = true;
}
return 1;
}

//*Actiunea public-ului actionata de timer.
Image
Image
Locked

Return to “Tutoriale”