VC:MP 0.4 (Beta) > Script Releases

gotoloc system

(1/1)

Mariu22S:
Gotoloc System

Add to onScirptsLoad()


--- Code: ---QuerySQL( youdatabase, "CREATE TABLE IF NOT EXISTS teleporty ( Nick VARCHAR(32), Nazwa VARCHAR(32), Loc VARCHAR(32) )" );
--- End code ---
This command add teleport

--- Code: --- 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;
}
--- End code ---

Command /gotoloc < loc name >

--- Code: --- 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 );
}
--- End code ---

thijn:
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.

Flockshot:

--- Quote from: thijn on September 28, 2014, 06:05:50 pm ---2. Don't save positions in a string, save the x y z as floats separately.

--- End quote ---
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

thijn:

--- Quote from: Flockshot on September 28, 2014, 06:19:27 pm ---
--- Quote from: thijn on September 28, 2014, 06:05:50 pm ---2. Don't save positions in a string, save the x y z as floats separately.

--- End quote ---
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

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version