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 - Rocky

#1
Quote from: . on Aug 23, 2016, 12:57 PM
Quote from: EK.CrystalBlue on Aug 23, 2016, 12:33 PM...

Wrong link. This is not an overflow. That's just how floating point numbers work.

Any way i can counter this in squirrel or i don't really have to use squirrel to do what i am doing right now since its a bit unrelated to vc-mp (some experiments).  So, Just wondering if this issue is present in all languages such as C, Java etc as well.



Quote from: EK.CrystalBlue on Aug 23, 2016, 12:33 PMhttps://en.wikipedia.org/wiki/Arithmetic_overflow

If i'm right Arithmetic overflow generally refers to when trying to store some value that is too large to be represented within the available storage space of a certain variable. (I've lost touch so i'm not completely sure about these terms.)
#2
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


#3
Looks very promising shady. Please don't drop it man. Good luck :)
#4
Quote from: Finch on Apr 17, 2015, 02:58 AMwhen i ban my self and join with anther nick hing happens he was unban on new nick and console give error on wrong number of paramettes

Which line does the error show, show me your kick function and one more thing, your function only checks if player's name is banned not its IP like i mentioned before. Even after you fix the parameter error player can join with another nick.
#5
Yes it is doing like you coded it to. your CheckBan( player ) function kicks only if player's name is banned not by its IP. Try checking IP or check both IP and nickname. I'm assuming you have stored IP in your column for storing IP Address. try using this:
function CheckBan( player )
{
  local query = QuerySQL( sqliteDB, "SELECT * FROM Bans WHERE IP='" + player.IP + "'" ); //Check by IP.
 if( GetSQLColumnData( query, 0 ) ) return 1;
 else return 0;
 FreeSQLQuery( query );
}

You can code the same to check nickname and check if both statements are true using if statement or do it in a single query.

PS: next time use code tag.
#6
Thanks gudio, never knew date() could be used like that. :)
#7
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?
#8
Quote from: Doom_Killer on Apr 12, 2015, 04:08 PMSetVehicleRespawnTimer( vehicleid, time );

I can see that format, the arguments are self explanatory, so try it.


He is referring to SetVehicleIdleRespawnTimer. If the vehicle is unused for a certain amount of time then he wants it to be re spawned at its orginal position whereas SetVehicleRespawnTimer respawns only when the vehicle is destroyed. I'm not sure this function really exists. If it doesn't then you should create a function that checks if the vehicle's position is within the position of the orginal spawn radius if not then manually respawn it, doing this might lag a bit lot since the only way to do that is with timers i guess.
#9
Tutorials / Re: [Tutorial] Setting up MYSQL.
Apr 10, 2015, 04:23 AM
Quote from: S.L.C on Apr 09, 2015, 11:11 PM
Quote from: Gudio on Apr 09, 2015, 08:42 PMI wouldn't recommend nginx to people who have no clue how to configure it with PHP or who want to use random tutorial.

To be honest, I find NGINX to be more easy to configure than Apache. I'm guessing it depends on the preferences.

I found apache easy myself. I could easily set it up in a go when I first found it. Like I have written in the tutorial people can user any they want.
Quote from: S.L.C on Apr 09, 2015, 03:55 PM

I meant to say if the server and website  using it are in different hosts then mysql is useful. I am really bad when typing in mobile so by the time I type a sentence I forget what to type next. :)
#10
Tutorials / Re: [Tutorial] Setting up MYSQL.
Apr 09, 2015, 12:11 PM
Quote from: NE.CrystalBlue on Apr 09, 2015, 08:00 AMWhy dont you use MySQLite (MySQL without server)? ☻☺☻

Well the main reason to use mysql is to php access database to be used in web applications. The package includes phpmyadmin, apache server, php and all tools necessary to run or create or test php codes etc. Like I mentioned you may use any you want but I will be using easyphp for this tutorial. :)
#11
Tutorials / Re: [Tutorial] Setting up MYSQL.
Apr 09, 2015, 04:22 AM
Quote from: Thijn on Apr 08, 2015, 05:56 PM...

Added to main post. Thanks for the benchmarks, Now that's one less thing to worry about. :P

Quote from: S.L.C on Apr 08, 2015, 06:46 PM...

Is it just me or is that link to discussion broken for everyone?
#12
Tutorials / Re: [Tutorial] Setting up MYSQL.
Apr 08, 2015, 04:40 PM
Quote from: Thijn on Apr 08, 2015, 04:34 PMPutting the username, password etc. in "global" variables isn't a good idea. If you happen to have an exploit in your server the login details may leak.

Aside from VCMP / Squirrel, SQLite is slower then MySQL because of threading. Like you said, SQLite can only read/write once at a time. This basically means every query needs to finish before it processes the next one. MySQL can do multiple things at once.

The only "but" here is the way the squirrel plugin is made. The MySQL plugin doesn't really support multi-threading. So the advantage is basically gone.
While I haven't done any benchmarking, I think MySQL is still faster then SQLite but I will do some testing later.

Thanks for the information. Those variables were only made for tutorial purposes. When you have time feel free to edit the post and add benchmark details here. Thanks :)
#13
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.