Spawnloc System

Started by umar4911, Oct 06, 2017, 05:32 PM

Previous topic - Next topic

umar4911

I made a spawnloc system. My friend also wanted it so I thought to post it.

add this onScriptLoad()
[spoiler]tele <- ConnectSQL( "databases/teleport.db" );
QuerySQL( tele, "CREATE TABLE IF NOT EXISTS spawn ( Autospawn TEXT, xaxis VARCHAR(25), yaxis VARCHAR(25), zaxis VARCHAR(25), Name VARCHAR(32) )" );

[/spoiler]



function onPlayerCommand(player, command, arguments)
[spoiler]if(cmd == "setspawnloc")
 {
  local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
  if(!q)
  {
   QuerySQL(tele, "INSERT INTO spawn ( Autospawn, xaxis, yaxis, zaxis, Name ) VALUES ( 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "', '" + player.Name + "' ) ");
  }
  else
  {
   QuerySQL(tele, "UPDATE spawn SET xaxis = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(tele, "UPDATE spawn SET yaxis = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(tele, "UPDATE spawn SET zaxis = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(tele, "UPDATE spawn SET Autospawn = 'true' WHERE Name = '" + player.Name + "'");
   MessagePlayer("Your spawnloc is updated and set to true. To disable it, use /spawnloc false", player);

  }
 }
 
 else if(cmd == "spawnloc")
 {
  if(!arguments) MessagePlayer("Error Unknown Syntax. Use /" + cmd + " <true/false>", player);
  local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
  if(!q)
  {
   MessagePlayer("You didnot set any spawn location. Use /setspawnloc to set spawn location.", player);
  }
  else
  {
   if(arguments == "true")
   {
    QuerySQL(tele, "UPDATE spawn SET Autospawn = 'true' WHERE Name = '" + player.Name + "'");
   }
   if(arguments == "false")
   {
    QuerySQL(tele, "UPDATE spawn SET Autospawn = 'false' WHERE Name = '" + player.Name + "'");
   }
   // if(!arguments == "true", "false")
   else {
    MessagePlayer("Error Unknown Syntax. Use /" + cmd + " <true/false>", player);
   }
  }
 }
 
[/spoiler]



function onPlayerSpawn(player)
[spoiler]function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
if( q && GetSQLColumnData(q, 0) == "true" )
{
local
xspawn = GetSQLColumnData(q, 1).tointeger(),
yspawn = GetSQLColumnData(q, 2).tointeger(),
zspawn = GetSQLColumnData(q, 3).tointeger();

player.Pos = Vector(xspawn, yspawn, zspawn);
MessagePlayer("You are Spawned at your saved location", player);
}
else
MessagePlayer("You are spawned", player);
}
[/spoiler]
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

Mahmoud Tornado

#1
K Nice :D

Cool


.

#3
tele <- ConnectSQL( "databases/teleport.db" );
QuerySQL( tele, ...

Why am I seeing plural? Please tell me you can make the difference between tables and databases.
.

umar4911

Quote from: . on Oct 07, 2017, 01:07 PMtele <- ConnectSQL( "databases/teleport.db" );
QuerySQL( tele, ...

Why am I seeing plural? Please tell me you can make the difference between tables and databases.
I didnot understand the question
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

!

Quote from: umar4911 on Oct 16, 2017, 11:08 AM
Quote from: . on Oct 07, 2017, 01:07 PMtele <- ConnectSQL( "databases/teleport.db" );
QuerySQL( tele, ...

Why am I seeing plural? Please tell me you can make the difference between tables and databases.
I didnot understand the question

Discord: zeus#5155

umar4911

Quote from: zeus on Oct 16, 2017, 01:41 PM
Quote from: umar4911 on Oct 16, 2017, 11:08 AM
Quote from: . on Oct 07, 2017, 01:07 PMtele <- ConnectSQL( "databases/teleport.db" );
QuerySQL( tele, ...

Why am I seeing plural? Please tell me you can make the difference between tables and databases.
I didnot understand the question
I just made a folder as it has more than 1 database
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter