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

Topics - Rocky

#1
Its been a while since i coded. :/
local i=0.000000000000000000000000000001;
Calc = format("%.30f", i );
print( Calc );

OUTPUT: 0.000000000000000000000000000001

However this doesn't work:

local i=0.001000000000000000000000000001;
Calc = format("%.30f", i );
print( Calc );

OUTPUT: 0.0010000000474974513000000000

Don't ask me why i need to use these high numbers. I just need to :X


#2
I'm trying to set real life time in the game world. (not completely accurate through).
function SetWorldTime()
{
   SetTimeRate( 60000 );
   SetTime( date()["hour"], date()["minute"] );
}

I've set my time rate at 60000 (60 secs) so the time changes like in real life. Problem is minute doesn't exist in date() only hour does. I've used GetFullTime() and splitted it to get minute and hour out of it.

function getTimefromFunc( hour )
{
   local text = GetFullTime(), time = split( text, "," )[ 3 ], time_table = split(time,":");
   if( hour == true ) return time_table[0]; //returns hour
   else return time_table[1]; //returns minute
}

It works fine but i keep getting this "GetFullTime is depreciated and may be removed in the future." on console each time i use this function. So, is there any alternative function which allow me to get minute?
#3
Tutorials / [Tutorial] Setting up MYSQL.
Apr 08, 2015, 01:54 PM
How to set up mySQL database for your vc-mp 0.4 server.

After eight - nine months away from vc-mp, I am back here on my first day trying out vc-mp 0.4. I see lot of people haven't been using MYSQL because they don't know how to set it up. So i thought i'd start my first day on 0.4 doing a tutorial on it. Before i start let me clear some questions regarding it.

1. Why use mySQL? Why not stick to sqlite?

mySQL databases can be written by more than one connection at the same time. ie, information stored in the database can be accessed or overwritten by another website/server at the same time whereas sqlite databases can only be written/edited one at a time. Another reason is web statistics even though it is possible on sqlite, If you have your server and website in different hosts you will need to update the database every time on the website's directory (yup that sucks, That's what PureDM server used to do).

2. Is mySQL faster than sqlite?


MySQL is way faster inserting records, but loses that advantage when selecting a lot of rows one after another.
SQLite does it completely the other way around. Slow with inserting (needs a lot of IO operations), but faster with selecting.
I think this is to do with the memory loading SQLite does. It keeps parts of it database in memory, so selecting rows from there is pretty quick.
Below is the benchmark results done by Thijin.

Quote[SCRIPT]  MySQL Benchmark
[SCRIPT]  Start: 0.091
[SCRIPT]  Connection made 0.098
[SCRIPT]  Table made 0.121
[SCRIPT]  10.000 records inserted: 3.569
[SCRIPT]  10.000 records selected: 55.287
[SCRIPT]  MySQL finished.

Quote[SCRIPT]  SQLite Benchmark
[SCRIPT]  Start: 0.093
[SCRIPT]  Connection made: 0.094
[SCRIPT]  Table made: 0.1
[SCRIPT]  10.000 records inserted: 44.053
[SCRIPT]  10.000 records selected: 48.065
[SCRIPT]  SQLite finished.

function sqlite()
{
print( "SQLite Benchmark" );
print( "Start: " + clock() );
local DB = ConnectSQL("test.sqlite");
print( "Connection made: " + clock() );
QuerySQL(DB, "CREATE TABLE IF NOT EXISTS `benchmark` (`testInt` INTEGER, `testChar` TEXT, `testFloat` REAL)");
print( "Table made: " + clock() );
for( local i = 0; i < 10000; i++ )
{
QuerySQL(DB, "INSERT INTO `benchmark` (testInt, testChar, testFloat) VALUES(" + i + ", 'test string omfg', 123456.789);");
}
print( "10.000 records inserted: " + clock() );
for( local i = 0; i < 10000; i++ )
{
local res = QuerySQL(DB, "SELECT * FROM `benchmark` WHERE `testInt` = " + i);
}
print( "10.000 records selected: " + clock() );
print( "SQLite finished." );
}

function mysql()
{
print( "MySQL Benchmark" );
print( "Start: " + clock() );
local my = mysql_connect("localhost", "test", "uwotm8", "test");
print( "Connection made " + clock() );
mysql_query(my, "CREATE TABLE IF NOT EXISTS `benchmark` (`testInt` int(10) NOT NULL, `testChar` varchar(255) NOT NULL, `testFloat` float NOT NULL);");
print( "Table made " + clock() );
for( local i = 0; i < 10000; i++ )
{
mysql_query(my, "INSERT INTO `benchmark` (testInt, testChar, testFloat) VALUES(" + i + ", 'test string omfg', 123456.789);");
}
print( "10.000 records inserted: " + clock() );
for( local i = 0; i < 10000; i++ )
{
local res = mysql_query(my, "SELECT * FROM `benchmark` WHERE `testInt` = " + i);
}
print( "10.000 records selected: " + clock() );
print( "MySQL finished." );
}
//mysql();
//sqlite();




That's all that came up on my mind but feel free to ask questions here. So lets get started.

1. First, download and install mysql. Best thing to do is download a package such as wamp or EasyPHP. The package contains mysql, php, phpmyadmin, apache server and all stuffs you will need in future and go ahead and install it.

2. Now, Start up the package (easyphp or wamp or any you are using) and open up phpmyadmin (type localhost/phpmyadmin in browser; dir may vary according to package installed) and type in a name and create a new database then click on that database go to privileges -> add user and type in username and password and check all grant access. then click ok.

3. load the mysql and squirrel plugin to your vc-mp server. open up your gamemode .nut file and add these lines.


Do not store mysql details in plain global variable like i did in here. This is made for tutorial purposes only.

mysql_hostname <- "localhost";
mysql_database <- " ";
mysql_username <- " ";
mysql_password <- " ";

function onScriptLoad()
{
   mysqlDB <- mysql_connect( mysql_hostname, mysql_username, mysql_password, mysql_database);
   if( mysqlDB ) print( "[SERVER] Connection to mySQL database successful." );
   else print( "[SERVER] Connection to mySQL failed." );
}

Type in the database name, user name and password that you used to create database in phpmyadmin in variable fields respectively.

4. That's it. Here are the functions and their syntax now start coding your scripts.

mysql_connect( szHost, szUsername, szPassword, szDatabase, iPort )
mysql_close( pConnection )
mysql_query( pConnection, szQuery )
mysql_num_rows( pResult )
mysql_num_fields( pResult )
mysql_fetch_row( pResult )
mysql_fetch_assoc( pResult )
mysql_fetch_lengths( pResult )
mysql_free_result( pResult )
mysql_errno( pConnection )
mysql_error( pConnection )
mysql_ping( pConnection )
mysql_escape_string( pConnection, szString )
mysql_select_db( pConnection, szDatabase )
mysql_change_user( pConnection, szUser, szPassword )
mysql_warning_count( pConnection )
mysql_affected_rows( pConnection )
mysql_insert_id( pConnection )
mysql_info( pConnection )

Please do reply here if you have questions regarding mysql. I will try my best to figure them out. I will be writing each and function and their uses soon here.