Gotoloc And Saveloc With Database

Started by Mahmoud Tornado, Sep 10, 2017, 01:51 PM

Previous topic - Next topic

Mahmoud Tornado

Hi All I Was Searching About Gotoloc And Saveloc System
But I Didn't Found Any One So I Uploaded My System. Enjoy!
Added With Words Color!

Follow The Steps

Step 1: Add In: function onScriptLoad()
TimeGotoloc <- array( GetMaxPlayers(), false );
db <- ConnectSQL( "DataBase.db" );
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Locations ( Name VARCHAR(32), Pos VARCHAR(25), Creator TEXT )" );

Step 2: Add In: function onScriptUnload()
DisconnectSQL( db );

Step 3: Add In: Function.nut    // If You Don't Have One You Can Add It In Main
function CheckLoc( name )
{
local loc = GetSQLColumnData( QuerySQL( db, "SELECT Name FROM Locations WHERE Name='" + name + "'" ), 0 );
if ( loc ) return loc;
else return 0;
}

function GetLocPos( loc )
{
if ( CheckLoc( loc ) )
{
local coords = GetSQLColumnData( QuerySQL( db, "SELECT Pos FROM Locations WHERE Name='" + loc + "'" ), 0 );
if ( coords ) return coords;
else return 0;
}
}

function SaveLoc( player, name )
{
local LocPos = format("%.3f %.3f %.3f", player.Pos.x, player.Pos.y, player.Pos.z );
QuerySQL( db, "INSERT INTO Locations (Name, Pos, Creator) VALUES ( '" + name + "', '" + LocPos + "', '" + player.Name + "' )" );
MessagePlayer( "[#ffbb00]Location Name: "+name+" .", player );
Announce( "Location Saved!", player, 0 );
}

function GotoLoc(pid,name)
{
local player = FindPlayer(pid);
if(player) {
if ( ( TimeGotoloc[ player.ID ] == true ) && ( player.IsSpawned ) )
{
if ( CheckLoc( name ) )
{
local pos = GetLocPos( name );
if ( pos )
{
local param = split( pos, " " );
player.Pos = Vector( param[ 0 ].tofloat(), param[ 1 ].tofloat(), param[ 2 ].tofloat() );
TimeGotoloc[ player.ID ] = false;
player.IsFrozen = false;
MessagePlayer( "[#ffbb00]Teleported Done To Location: "+name+" .", player );
Announce( "Teleport Success!", player, 0 );
}
else {
TimeGotoloc[ player.ID ] = false;
GotoPlr.Delete();
}
}
}
}
}

Step 4: Add In: function onPlayerCommand( player, cmd, text ) Or In Commands.nut
if ( cmd == "gotoloc" )
{
local q = QuerySQL(db, "SELECT * FROM Locations WHERE Name='" + text + "'");
if ( !player.IsSpawned ) MessagePlayer( "[#ff0000]Error: You Must Spawn First.", player );
else {
if ( !text ) MessagePlayer( "[#ff0000]Usage: /" + cmd + " <Location>", player );
else if ( !CheckLoc( text ) ) MessagePlayer( "[#ff0000]Error: Can't Find This Location: " + text + " !", player );
else {
TimeGotoloc[ player.ID ] = true;
player.IsFrozen = true;
GotoPlr <- NewTimer( "GotoLoc", 3000, 1, player.ID,text );
MessagePlayer( "[#ffbb00]Teleporting To Location: "+text+". Saved By: "+GetSQLColumnData( q, 2 )+".", player );
Announce( "Teleporting...", player , 0 );
}
}
}

else if ( cmd == "saveloc" )
{
if ( !player.IsSpawned ) MessagePlayer( "[#ff0000]Error: You Must Spawn First.", player );
else if ( !text ) MessagePlayer( "[#ff0000]Usage: /" + cmd + " <Location>.", player );
else {
if ( CheckLoc( text ) ) MessagePlayer( "[#ff0000]Error:This Location: " + text + " Is Already Exist!.", player );
else {
SaveLoc( player, text );
}
}
}
Enjoy!
Made By MahmoudTornado



Mohamed Boubekri

Not Working For me MahmoudTornado
all commands its work database create automatique all niiicebut
But i am do /saveloc parkour and do /gotoloc parkour........ Unknow loc lol ;v
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

VK.Jona83Killer

Maybe it's because you do not know how to add it to your server

D4rkR420R

Quote from: [MCO]We3da on Oct 17, 2017, 06:42 PMNot Working For me MahmoudTornado
all commands its work database create automatique all niiicebut
But i am do /saveloc parkour and do /gotoloc parkour........ Unknow loc lol ;v

Probably either your gotoloc function doesn't read the positions, from the database, correctly or your saveloc doesn't store the positions properly.

Mohamed Boubekri

Quote from: KuRiMi on Oct 18, 2017, 11:34 AM
Quote from: [MCO]We3da on Oct 17, 2017, 06:42 PMNot Working For me MahmoudTornado
all commands its work database create automatique all niiicebut
But i am do /saveloc parkour and do /gotoloc parkour........ Unknow loc lol ;v

Probably either your gotoloc function doesn't read the positions, from the database, correctly or your saveloc doesn't store the positions properly.
Thanks Bro KuRiMi Problem Solved.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Bninin...


umar4911

Quote from: Bninin.. on Dec 09, 2017, 03:01 PMplz how to download [nb]?[/nb]
it is a copy paste code. Copy the code and paste in the respective function
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

Mötley

So are you using a database or ini?

Also there are more players hear.. I would run a check when saving a position. Get there Distance to the nearest saved vector. If distance is less than 3 or something let them know, tell them the name of the save, and don't save it.

Reason I say this is because I have watched players constantly type /saveloc. And thats all ;)

Bninin...

im not knowed plz can you make a vedio or image for tell me ?

Xenon

Quote from: Bninin.. on Dec 20, 2017, 12:39 AMim not knowed plz can you make a vedio or image for tell me ?
Are you kidding...?

Humzasajjad


Magneto

Quote from: Humzasajjad on Aug 29, 2018, 07:08 PMWhere to paste this script?

.-.  Mahmoud Tornado Already explained.

MatheuS

Quote from: Xenon on Dec 20, 2017, 02:23 AM
Quote from: Bninin.. on Dec 20, 2017, 12:39 AMim not knowed plz can you make a vedio or image for tell me ?
Are you kidding...?

Please come to my home and add it for me.

HAHAHHAHAHA
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.