Easy error fix!

Started by umar4911, Sep 22, 2017, 09:33 AM

Previous topic - Next topic

umar4911

I was making spawnloc and setspawnloc cmds with database. I know there is  a simple error but I am unable to find that.
onscript load

sploc <- ConnectSQL("databases/spawnloc.db");
QuerySQL( sploc, "CREATE TABLE IF NOT EXISTS spawn ( Name VARCHAR(32), Autospawn TEXT, xaxis VARCHAR(25), yaxis VARCHAR(25), zaxis VARCHAR(25) )" );
 print("spawnloc system loaded");

playercmds
if(cmd == "setspawnloc")
{
local q = QuerySQL(sploc, "SELECT * FROM spawn WHERE Name = '" + player.name + "'");
if(!q)
{
QuerySQL(sploc, "INSERT INTO spawn ( Name, Autospawn, xaxis, yaxis, zaxis ) VALUES ( '" + player.name + "' , 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "') ");
}
else
{
QuerySQL(sploc, "UPDATE spawn SET xaxis = '" + player.Pos.x + "' WHERE Name = '" + player.name + "'");
QuerySQL(sploc, "UPDATE spawn SET yaxis = '" + player.Pos.y + "' WHERE Name = '" + player.name + "'");
QuerySQL(sploc, "UPDATE spawn SET zaxis = '" + player.Pos.z + "' WHERE Name = '" + player.name + "'");
QuerySQL(sploc, "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);

}
}
 
if(cmd == "spawnloc")
{
// arguments = arguments.tolower();
if(!arguments) MessagePlayer("Error Unknown Syntax. Use /" + cmd + " <true/false>", player);
local q = QuerySQL(sploc, "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(sploc, "UPDATE spawn SET autospawn = 'true' WHERE Name = '" + player.name + "'");
}
if(arguments == "false")
{
QuerySQL(sploc, "UPDATE spawn SET autospawn = 'true' WHERE Name = '" + player.name + "'");
}
/* if(!arguments == "true", "false")
{
MessagePlayer("Error Unknown Syntax. Use /" + cmd + " <true/false>", player);
} */
}
}
 
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

!

Change player.name to player.Name in all places.
P.S: post error details

Discord: zeus#5155

Xmair

#2
wtf why 4 queries
use
QuerySQL(sploc, "UPDATE spawn SET xaxis = '" + player.Pos.x + "', yaxis = '" + player.Pos.y + "',
zaxis = '" + player.Pos.z + "', autospawn = 'true' WHERE Name = '" + player.Name + "'");
Also this code seriously isn't making any sense.
local q = QuerySQL(sploc, "SELECT * FROM spawn WHERE Name = '" + player.name + "'");
  if(!q)
  {
   QuerySQL(sploc, "INSERT INTO spawn ( Name, Autospawn, xaxis, yaxis, zaxis ) VALUES ( '" + player.name + "' , 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "') ");
  }
  else
  {
   QuerySQL(sploc, "UPDATE spawn SET xaxis = '" + player.Pos.x + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET yaxis = '" + player.Pos.y + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET zaxis = '" + player.Pos.z + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET autospawn = 'true' WHERE Name = '" + player.name + "'");
Why do this when you're already inserting the exact same pos?

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

umar4911

#3
Quote from: Xmair on Sep 22, 2017, 10:54 AMwtf why 4 queries
use
QuerySQL(sploc, "UPDATE spawn SET xaxis = '" + player.Pos.x + "', yaxis = '" + player.Pos.y + "',
zaxis = '" + player.Pos.z + "', autospawn = 'true' WHERE Name = '" + player.Name + "'");
Also this code seriously isn't making any sense.
local q = QuerySQL(sploc, "SELECT * FROM spawn WHERE Name = '" + player.name + "'");
  if(!q)
  {
   QuerySQL(sploc, "INSERT INTO spawn ( Name, Autospawn, xaxis, yaxis, zaxis ) VALUES ( '" + player.name + "' , 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "') ");
  }
  else
  {
   QuerySQL(sploc, "UPDATE spawn SET xaxis = '" + player.Pos.x + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET yaxis = '" + player.Pos.y + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET zaxis = '" + player.Pos.z + "' WHERE Name = '" + player.name + "'");
   QuerySQL(sploc, "UPDATE spawn SET autospawn = 'true' WHERE Name = '" + player.name + "'");
Why do this when you're already inserting the exact same pos?
I always used it. Now learned
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

umar4911

RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter