SA-MP Forums Archive
[FilterScript] Date & Time Textdraw [First Release] - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] Date & Time Textdraw [First Release] (/showthread.php?tid=646941)



Date & Time Textdraw [First Releases] - Barnwell - 27.12.2017

[FS] Date & Time Textdraw - Real Time - +2GMT
This is my first filter-script it took me about 15 mintues. Here we go.
I hope you guys like it. its my first filter-script.

Shows day, month,year
Shows hour, mintues

Image: https://imgur.com/a/nM61N

Here is the code:
Code:
// Date & Time textdraw by Barnwell.
// Real Time - Date
// If you found any bug don't forget to reply on sa-mp forum.

#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT
new Text:DateText;
new Text:TimeText;

public OnFilterScriptInit()
{
    SetTimer("SetTimeDate",1000,true);
    DateText = TextDrawCreate(545.500000, 16.177732, "18/3/2016");
    TextDrawLetterSize(DateText, 0.298500, 1.058665);
    TextDrawAlignment(DateText, 1);
    TextDrawColor(DateText, -1);
    TextDrawSetShadow(DateText, 0);
    TextDrawSetOutline(DateText, 1);
    TextDrawBackgroundColor(DateText, 51);
    TextDrawFont(DateText, 2);
    TextDrawSetProportional(DateText, 1);

    TimeText = TextDrawCreate(556.000000, 28.622150, "19:49");
    TextDrawLetterSize(TimeText, 0.329499, 0.977777);
    TextDrawAlignment(TimeText, 1);
    TextDrawColor(TimeText, -1);
    TextDrawSetShadow(TimeText, 0);
    TextDrawSetOutline(TimeText, 1);
    TextDrawBackgroundColor(TimeText, 51);
    TextDrawFont(TimeText, 2);
    TextDrawSetProportional(TimeText, 1);

	print("\n--------------------------------------");
	print(" Date & Time Textdraw with functions by Barnwell");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

#endif
public OnPlayerConnect(playerid)
{
	return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
        TextDrawHideForPlayer(playerid,DateText);
        TextDrawHideForPlayer(playerid,TimeText);
	return 1;
}
forward SetTimeDate();
public SetTimeDate()
{
	new string[128],
	// You can change the world time like GMT+2 GMT+3, etc
	year,month,day,hours,minutes,seconds;
    getdate(year, month, day), gettime(hours, minutes, seconds);
    SetWorldTime(hours+2);
    format(string, sizeof string, "%d/%s%d/%s%d", day, ((month < 10) ? ("0") : ("")), month, (year < 10) ? ("0") : (""), year);
    TextDrawSetString(DateText, string);
    format(string, sizeof string, "%s%d:%s%d", (hours < 10) ? ("0") : (""), hours, (minutes < 10) ? ("0") : (""), minutes);
    TextDrawSetString(TimeText, string);
}
public OnPlayerSpawn(playerid)
{
	TextDrawShowForPlayer(playerid,DateText);
	TextDrawShowForPlayer(playerid,TimeText);
	return 1;
}



Re: Date & Time Textdraw [First Release] - Freaksken - 27.12.2017




Re: Date & Time Textdraw [First Release] - Barnwell - 27.12.2017

Quote:
Originally Posted by Freaksken
View Post
  • You don't initialize your textdraws. See section 1.2.1.2 from this tutorial to see why that's important.
  • Why 2 textdraws? You can just use ~n~ to do a linebreak.
  • You don't destroy the textdraws and reset the variables in OnFilterScriptExit.
  • The main-function is not needed in filterscripts.
  • Why are you starting the timer in OnPlayerConnect? Isn't this a global textdraw?
  • Don't use a random large enough array size. The first textdraw only uses 10 characters, the second only 5.
This is my first filterscript
So i am not a professional scripter or something.
also yes it is a global textdraw.


Re: Date & Time Textdraw [First Release] - Castiel17 - 27.12.2017

Nice Work


Re: Date & Time Textdraw [First Release] - Freaksken - 27.12.2017

Quote:
Originally Posted by Barnwell
View Post
This is my first filterscript
So i am not a professional scripter or something.
Then take my critique as feedback and improve your script by fixing the things I listed.

Quote:
Originally Posted by Barnwell
View Post
also yes it is a global textdraw.
Then don't start the timer in OnPlayerConnect.


Re: Date & Time Textdraw [First Release] - RedRex - 27.12.2017

good work!


Re: Date & Time Textdraw [First Release] - Ritzy2K - 27.12.2017

Quote:
Originally Posted by Freaksken
View Post
  • You don't initialize your textdraws. See section 1.2.1.2 from this tutorial to see why that's important.
  • Why 2 textdraws? You can just use ~n~ to do a linebreak.
  • You don't destroy the textdraws and reset the variables in OnFilterScriptExit.
  • The main-function is not needed in filterscripts.
  • Why are you starting the timer in OnPlayerConnect? Isn't this a global textdraw?
  • Don't use a random large enough array size. The first textdraw only uses 10 characters, the second only 5.
https://sampforum.blast.hk/showthread.php?tid=578091


Re: Date & Time Textdraw [First Release] - Freaksken - 27.12.2017

Quote:
Originally Posted by Ritzy
View Post
You need to destroy the textdraws and reset the variables in a gamemode in OnGameModeExit, so that when restarting the server the currently in use textdraw IDs can be used again later.

You need to destroy the textdraws and reset the variables in a filterscript in OnFilterScriptExit, so that when restarting the filterscript the currently in use textdraw IDs can be used again later.


Re: Date & Time Textdraw [First Release] - rfr - 27.12.2017

good for your first fs


Re: Date & Time Textdraw [First Release] - Barnwell - 27.12.2017

Okay i will add it.


Re: Date & Time Textdraw [First Release] - Freaksken - 27.12.2017

How are people still saying this is good, when he hasn't even tried fixing the problems. Either people are doing it to increase their postcount, get some rep, or they just haven't even looked at the code at all. He said it took him 15 minutes to create this, well fixing the script doesn't even take that long. Saying a thing is good when it is clearly not, is giving a false impression of what is considered a good script. And no, it's not because it's his first script you can not criticize. Because if that's the standard we're going with, people will never learn how to make a proper script, since they're surrounded by yes-men.

My first reply is definitely constructive criticism. I showed you what was wrong and even how to improve it, but instead of taking the feedback seriously, you just say that you're inexperienced. Yeah that approach is never going to work elsewhere: "Oh officer I know I ran the red light, but I'm inexperienced. Well tough luck, you'll still get the fine." Either show that you're willing to learn by taking the feedback seriously, or get defensive and don't post scripts at all.

EDIT:
Quote:
Originally Posted by Barnwell
View Post
Okay i will add it.
I was still typing when you replied. My point still stands though.


Re: Date & Time Textdraw [First Release] - RogueDrifter - 27.12.2017

a suggestion, set a variable to the timer, kill the timer onplayerdisconnect and hide the textdraws as well onplayerdiisconnect or destroy them if you're creating them each time a player connects.


Re: Date & Time Textdraw [First Release] - Freaksken - 27.12.2017

Quote:
Originally Posted by RogueDrifter
View Post
a suggestion, set a variable to the timer, kill the timer onplayerdisconnect and hide the textdraws as well onplayerdiisconnect or destroy them if you're creating them each time a player connects.
The timer shouldn't even be under OnPlayerConnect.


Re: Date & Time Textdraw [First Release] - SonnyGamer - 27.12.2017

You never made this system e.e You just copied from
Original: https://sampforum.blast.hk/showthread.php?tid=70445


Re: Date & Time Textdraw [First Release] - Barnwell - 27.12.2017

nope i made it from scratch you can check the codes.


Updated.


Re: Date & Time Textdraw [First Release] - rfr - 27.12.2017

Quote:
Originally Posted by Freaksken
View Post
The timer shouldn't even be under OnPlayerConnect.
Should be OnPlayerSpawn right


Re: Date & Time Textdraw [First Release] - SonnyGamer - 27.12.2017

Quote:
Originally Posted by Barnwell
View Post
nope i made it from scratch you can check the codes.


Updated.
For me it looks like edited version of that system. Could atleast give him credits for making version 1


Re: Date & Time Textdraw [First Release] - Daniielk - 27.12.2017

Excelent work


Re: Date & Time Textdraw [First Release] - Freaksken - 28.12.2017

Quote:
Originally Posted by Daniielk
View Post
Excelent work
Seriously, stop saying that.

Quote:
Originally Posted by rfr
View Post
Should be OnPlayerSpawn right
What? No!

Quote:
Originally Posted by Barnwell
View Post
nope i made it from scratch you can check the codes.
Updated.
The only thing you did was move the timer to where it's supposed to be. You didn't address any of the other things I mentioned.