Author Topic: gotoloc system  (Read 3131 times)

0 Members and 1 Guest are viewing this topic.

Offline Mariu22S

  • Wiseguy
  • **
  • Posts: 78
  • VC-MP Maniac
    • View Profile
gotoloc system
« on: September 28, 2014, 05:09:19 pm »
Gotoloc System

Add to onScirptsLoad()

Code: [Select]
QuerySQL( youdatabase, "CREATE TABLE IF NOT EXISTS teleporty ( Nick VARCHAR(32), Nazwa VARCHAR(32), Loc VARCHAR(32) )" );This command add teleport
Code: [Select]
else if ( cmd == "addloc" )
{
    if ( stats[ player.ID ].Login )
    {
        if ( stats[ player.ID ].Level >= 9 )
            {
    QuerySQL( youdatabase, "INSERT INTO teleporty ( Nick,Nazwa, Loc ) values ( '" + player.Name + "', '" + text + "', '" + player.Pos.x + "," + player.Pos.y + "," + player.Pos.z + "' )");
    MessagePlayer( "[#00ff00]You've added locations named " + text + "  to database", player );
            }
        else MessagePlayer( "[#00ff00]You must heve [9] level to use this command. " , player );
}
else MessagePlayer( "[#ffffff][INFO][#00ff00]Please login." , player );
        return 1;
}

Command /gotoloc < loc name >
Code: [Select]
else if ( cmd == "gotoloc" )
{
    if ( stats[ player.ID ].Login )
    {
     if ( text )
    {
    local q = QuerySQL( youdatabase, "SELECT Nick, Nazwa, Loc FROM teleporty WHERE Nazwa LIKE '%" + text + "%'" );
    if ( GetSQLColumnData( q, 2 ) != null )
    {
local pos = split( GetSQLColumnData( q, 2 ), "," );
player.Pos = Vector( pos[0].tofloat(), pos[1].tofloat(), pos[2].tofloat() );
MessagePlayer( "[#00ff00]--- > Teleport to the location [ [#ffffff]" + text + "[#00ff00] ] Created by [ [#ffffff]" + GetSQLColumnData( q, 0 ) + "[#00ff00] ]" , player );
    }
    else MessagePlayer( "[#00ff00]Given location is not in the database", player );
    }
    else MessagePlayer( "[#00ff00]Enter a location name", player );
}
else MessagePlayer( "[#ffffff][INFO][#FD0F0F] Please login. " , player );
}

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: gotoloc system
« Reply #1 on: September 28, 2014, 06:05:50 pm »
1. Could've at least made the name of the columns English
2. Don't save positions in a string, save the x y z as floats separately.

Also, I don't think stats[ player.ID ].Login is a bit script specific. Might be nicer to remove all custom things, like the level.

Offline Flockshot

  • Street Thug
  • *
  • Posts: 29
    • View Profile
Re: gotoloc system
« Reply #2 on: September 28, 2014, 06:19:27 pm »
2. Don't save positions in a string, save the x y z as floats separately.
I agree with sving the x y z as floats but we can also add them in only one column . and we can use the split function.Saving saperatly will make 3 extra column in database

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: gotoloc system
« Reply #3 on: September 28, 2014, 07:03:41 pm »
2. Don't save positions in a string, save the x y z as floats separately.
I agree with sving the x y z as floats but we can also add them in only one column . and we can use the split function.Saving saperatly will make 3 extra column in database
The more operations you would need to get the coordinates out of the database, the more time it will take and the more lag it will create.
SQLite is made for proper saving, so having 3 different columns with x, y, z is going to be more efficient then saving them all in one.

This will allow to have funky calculations as well. Like list all positions within a certain radius. Or list all positions near the player. Very useful for admins.