Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - vcmptr

#46
I'm trying to create scheduled tasks. 
function tasks()
{
NewTimer("tasks",60000,1);
local now = date()
if(now.hour.tointeger() == 00)
{
SetWeather( 7 );
}
if(now.hour.tointeger() == 06)
{
OffCarLights();
}
if(now.hour.tointeger() == 18)
{
SetWeather( 5 );
}
if(now.hour.tointeger() == 20)
{
OpenCarLights();
}

}

But its not useful.  Example I can't schedule task from week to week. How can I make like Cron Job?
#47
Quote from: Sk on Mar 13, 2015, 03:06 PMyou can use date() function.it returns a table with few index like day wday etc.
To use it do something like this
local t = time()+86400; // added one day.
local d = date(t).day; // day is name of index inside table date().
print("Today date is "+date().day+"Tomorrow the date will be "+d);
Note if you dont use any parameter/arguments for date() then the default time time() will be used.
and to know about all index in table date() you can use foreach like this.
local d = date();
foreach(index_name,value in d) print(index_name+" = "+value);
hope this helps.
Quote from: S.L.C on Mar 13, 2015, 03:27 PMUsage is above. Specifications are bellow.

date([time], [format]);returns a table containing a date/time splitted in the slots:

sec Seconds after minute (0 - 59).
min Minutes after hour (0 - 59). 
hour Hours since midnight (0 - 23).
day Day of month (1 - 31). 
month Month (0 - 11; January = 0). 
year Year (current year). 
wday Day of week (0 - 6; Sunday = 0). 
yday Day of year (0 - 365; January 1 = 0). 

if time is omitted the current time is used.
if format can be 'l' local time or 'u' UTC time, if omitted is defaulted as 'l'(local time).


time();
returns the number of seconds elapsed since midnight 00:00:00, January 1, 1970.

the result of this function can be formatted through the function date().

No longer I will record times with time() funtion. Thanks! :)
#48
I need unix time to date and date to unix time. How can i do?
#49
Quote from: S.L.C on Mar 12, 2015, 11:51 AM
Quote from: vcmptr on Mar 12, 2015, 08:48 AMNow I need check is player in game.  :)

Something that simple? A database would be the easiest and most simple way. An even simple and easier way if you don't know how to use databases would be .ini files. Anything other than calling Squirrel from PHP would be better.
I just wondered It's possible. I thought call this functions:
function gplayer(name)
{
local player = FindPlayer(name);
if(player)
{
return [player.ID, player.Name, player.IP, player.UniqueID, player.Skin, player.Score, status[ player.ID ].KillingSpree]
}
else return 0;
}
or this:
function rld()
{
ReloadScripts();
print("Script reloaded from website!");
}

But I give up use reload function for now. I decided to use Query Mechanism and MySQL.

Thanks all for helping. :)
#50
Quote from: stormeus on Mar 11, 2015, 07:53 PMThe above posts answer your question. Personally I'm of the opinion that if you think you need to do this, you don't, and going forward with it would be a terrible idea.

More refined help would be available if you explained what you're actually trying to accomplish using this feature.
Now I need check is player in game.  :)
#51
Thanks S.L.C and Thijn. I will try this ways.
#52
I wonder can I call squirrel function with PHP?
#53
Acknowledged Bug Reports / Re: Print Function
Mar 07, 2015, 05:19 PM
Thank you S.L.C, Kratos, Gudio and Sk. :) And Beztone.
 I will wait fix.
#54
Acknowledged Bug Reports / Re: Print Function
Mar 07, 2015, 08:27 AM
Yes I need 512 characters for errors. I'm using this. In some cases errors can be longer than 512 characters.
#55
If print() length greater than 514 characters server crashes.
I have try this:
print("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eie");
#56
Snippet Showroom / Re: [MySQL] Error Logger
Mar 04, 2015, 05:19 AM
Quote from: Thijn on Mar 02, 2015, 07:01 PMYou're doing the same loop 3 times, calling getstackinfos 2 times in one loop, and compare int's with nulls.

You should be able to combine all 3 loops into one, cleanup some more variables, and combine it all into much less code like so:
function errorlog( str )
{
local stackinfo, stacktrace = "\n[Error]"+str+"\n Functions:\n", locals = "Locals:\n";
for(local i = 2; (stackinfo = getstackinfos(i)); i++)
{
stacktrace += "["+stackinfo["func"]+"()] "+stackinfo["src"]+" ["+stackinfo["line"]+"]\n";
foreach(idx,val in stackinfo["locals"])
{
locals += "["+stackinfo["func"]+"]"+idx+", Value="+val+"\n";
}
}
print( stacktrace + locals );
mysql_query( YOUR_DB, "INSERT INTO errors (`error`, `date`) VALUES ( '" + mysql_escape_string(YOUR_DB, stacktrace + locals) + "', CURDATE() );" );
print( "Error saved as ID: " + mysql_insert_id(YOUR_DB) );
}

If you're saving a date, you should use the format that's made for it. You don't save a datetime in a textfield...
CREATE TABLE IF NOT EXISTS `errors` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `error` text NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`)
)
Wow only 1 loop :o. Thanks Thijn.
#57
General Discussion / MySQL or SQLite?
Mar 02, 2015, 05:38 AM
Which do you use?
#58
Snippet Showroom / [MySQL] Error Logger
Mar 02, 2015, 02:20 AM
This script logging errors to MySQL DB.
function errorlog( str )
{
local hata = "\n[Error]"+str+"\n Functions:\n"
local cs = {};
local now = date();

 
 for(local i = 2; i != null; i++)
 {
 if(getstackinfos( i ))
 {
 local fnad = getstackinfos( i );
 hata = hata+"["+fnad["func"]+"()] "+fnad["src"]+" ["+fnad["line"]+"]\n";
 }
else break;
 }
 
 for(local i = 2; i != null; i++)
 {
 if(getstackinfos( i ))
 {
foreach(idx,val in getstackinfos( i ))
cs[idx+i] <- val;
 }
else break;
 }
 
hata = hata + "Locals:\n"
 for(local i = 2; i != null; i++)
 {
 if(getstackinfos( i ))
 {
 local fnad = getstackinfos( i );
 foreach(idx,val in cs["locals"+i])
 hata = hata+"["+fnad["func"]+"]"+idx+", Value="+val+"\n";
}
else break;
}
print(hata);
mysql_query( YOUR_DB, "INSERT INTO errors (`error`, `date`) VALUES ( '" + mysql_escape_string(YOUR_DB, hata) + "', '" + (now.day + "/" + (now.month.tointeger() + 1) + "/" + now.year + " " + now.hour + ":" + now.min + ":" + now.sec) + "')" );
print( mysql_insert_id(YOUR_DB)+" error saved with this number." );
}
seterrorhandler( errorlog );


DB Create Table Query:
CREATE TABLE IF NOT EXISTS `errors` (
  `error` text NOT NULL,
  `date` text NOT NULL
);
ALTER TABLE errors ADD id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; 
#59
Thanks its very nice. :)
#60
Support / Re: Notepad++ syntax highlight
Dec 21, 2014, 01:54 PM
It's very nice. Thanks. :)