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.

Messages - vcmptr
46
Scripting and Server Management / Scheduled Tasks
« on March 13th, 2015, 06:03 PM »
I'm trying to create scheduled tasks. 
Code: [Select]
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
Scripting and Server Management / Re: Unix Time to Date
« on March 13th, 2015, 05:48 PM »
Quote from Sk on March 13th, 2015, 03:06 PM
you can use date() function.it returns a table with few index like day wday etc.
To use it do something like this
Code: [Select]
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.
Code: [Select]
local d = date();
foreach(index_name,value in d) print(index_name+" = "+value);
hope this helps.
Quote from S.L.C on March 13th, 2015, 03:27 PM
Usage is above. Specifications are bellow.

Code: [Select]
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).


Code: [Select]
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
Scripting and Server Management / Unix Time to Date
« on March 13th, 2015, 01:45 PM »
I need unix time to date and date to unix time. How can i do?
49
General Discussion / Re: Can I Call Function with PHP
« on March 12th, 2015, 12:32 PM »
Quote from S.L.C on March 12th, 2015, 11:51 AM
Quote from vcmptr on March 12th, 2015, 08:48 AM
Now 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:
Code: [Select]
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:
Code: [Select]
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
General Discussion / Re: Can I Call Function with PHP
« on March 12th, 2015, 08:48 AM »
Quote from stormeus on March 11th, 2015, 07:53 PM
The 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
General Discussion / Re: Can I Call Function with PHP
« on March 11th, 2015, 06:54 PM »
Thanks S.L.C and Thijn. I will try this ways.
52
General Discussion / Can I Call Function with PHP
« on March 11th, 2015, 05:44 PM »
I wonder can I call squirrel function with PHP?
53
Acknowledged Bug Reports / Re: Print Function
« on March 7th, 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
« on March 7th, 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:
Code: [Select]
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 / [MySQL] Re: Error Logger
« on March 4th, 2015, 05:19 AM »
Quote from Thijn on March 2nd, 2015, 07:01 PM
You'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:
Code: [Select]
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...
Code: [Select]
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?
« on March 2nd, 2015, 05:38 AM »
Which do you use?
58
Snippet Showroom / [MySQL] Error Logger
« on March 2nd, 2015, 02:20 AM »
This script logging errors to MySQL DB.
Code: [Select]
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:
Code: [Select]
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
Script Showroom / [ FilterScript ] Re: Custom Menu System v2.0 ( released )
« on March 1st, 2015, 03:30 AM »
Thanks its very nice. :)
60
Support / Re: Notepad++ syntax highlight
« on December 21st, 2014, 01:54 PM »
It's very nice. Thanks. :)