Spawnloc system

Started by AroliS^, Nov 18, 2018, 06:46 PM

Previous topic - Next topic

AroliS^

I modify this system : https://forum.vc-mp.org/?topic=5189.msg37267#msg37267
::MSN = MessagePlayer
::SMS = MessagePlayer
::PM = MessagePlayer
EROS = "/"

onScriptLoad()
[spoiler]
locs <- ConnectSQL( "datas/locs.db" );
QuerySQL( locs, "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]else if ( cmd == "spawnloc" )
{
if ( check( player, null ) ) return 0;
else if ( player.Vehicle ) ::MSN( "[#cccccc]You are on a vehicle.", player );
else if ( !player.IsSpawned ) ::MSN("[#ff0000]Choose a skin before use it", player );
local q = QuerySQL( locs, "SELECT Autospawn FROM spawn WHERE Name='" + player.Name + "'");
if ( !text ) ::SMS( "/" + cmd + " <on/off>", player );
else
{
if ( text == "on" )
{
if ( GetSQLColumnData(q, 0 ) == "true" ) ::MSN( "You already did.", player );
else
{
pstatus[ player.ID ].SpawnLoc = true;
QuerySQL(locs, "UPDATE spawn SET Autospawn = 'true' WHERE Name = '" + player.Name + "'");
::PM( "Activate! to choose a place. "+azul+"Use /spawnloc set.", player );
}
}
else if ( text == "off" )
{
if ( GetSQLColumnData(q, 0 ) == "false" ) ::MSN( "You already did.", player );
else
{
pstatus[ player.ID ].SpawnLoc = false;
QuerySQL(locs, "UPDATE spawn SET Autospawn = 'false' WHERE Name = '" + player.Name + "'");
::PM( "Spawnloc desactivate!", player );
}
}
else if ( text == "set" )
{
if ( pstatus[ player.ID ].SpawnLoc == false ) ::MSN("Your spawnloc is "+azul+"[ "+ GetSQLColumnData(q, 0 ) +" ],"+blanco+" Use /spawnloc on!!.", player );
else
{
 local q = QuerySQL(locs, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
  if(!q)
  {
   QuerySQL(locs, "INSERT INTO spawn ( Autospawn, xaxis, yaxis, zaxis, Name ) VALUES ( 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "', '" + player.Name + "' ) ");
  }
  else
  {
   QuerySQL(locs, "UPDATE spawn SET xaxis = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(locs, "UPDATE spawn SET yaxis = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(locs, "UPDATE spawn SET zaxis = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'");
   QuerySQL(locs, "UPDATE spawn SET Autospawn = 'true' WHERE Name = '" + player.Name + "'");
   ::PM("You are going to spawn here."+azul+" To disable it,"+blanco+" use /spawnloc", player);
}
}
}
else ::SMS( EROS + cmd + " <on/off/set>", player );
}
}[/spoiler]


function onPlayerSpawn(player)
[spoiler] local q = QuerySQL(locs, "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);
 }[/spoiler]
Lemme love ya