Where to put the code??

Started by umar4911, Sep 26, 2017, 09:50 AM

Previous topic - Next topic

umar4911

I made a spawnloc system. It contain a easy error which was fixed.
Spawnloc system
ok I need to know how to make the person spawn at his saved position.
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

DizzasTeR

I see you made a spawnloc system. It contained a easy error which was fixed.

ok I need to know how did you script that if you can't make the player spawn at his saved position.

umar4911

Quote from: Doom_Kill3R on Sep 26, 2017, 10:19 AMI see you made a spawnloc system. It contained a easy error which was fixed.

ok I need to know how did you script that if you can't make the player spawn at his saved position.
Good Question. Now listen the details.
I was making a spawnloc system. First I just made a basic script in which the player's location is saved into database using the cmd setspawnloc and change the value of autospawn to true or false using the cmd spawnloc
[b]
 
 else if(cmd == "setspawnloc")
 {
  local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
  if(!q)
  {
   QuerySQL(tele, "INSERT INTO spawn ( Name, Autospawn, xaxis, yaxis, zaxis ) VALUES ( '" + player.Name + "' , 'true' , '" + player.Pos.x + "' , '" + player.Pos.y + "' , '" + player.Pos.z + "') ");
  }
  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")
 {
  // arguments = arguments.tolower();
  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);
   }
  }
 }
 
 
 [/b]
Then I wanted to that on spawn, the person is transported to it's saved location but I didn't know how can I make the person spawn. I checked the blank main.nut to find any type of function related to it. I saw 2 functions.

1 with onPlayerSpawn and onPlayerRequestSpawn. Then I again made a code to teleport him to its location.

the onPlayerSpawn
function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
if(q)
{
local
autosp = GetSQLColumnData(q, 1),
xspawn = GetSQLColumnData(q, 2),
yspawn = GetSQLColumnData(q, 3),
zspawn = GetSQLColumnData(q, 4);


if(autosp == "true")
{

Vector(xspawn, yspawn, zspawn);
MessagePlayer("You are spawned");
}
}
else MessagePlayer("You are spawned");
}

OnPlayerRequestSpawn

function onPlayerRequestSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
if(q)
{
local
autosp = GetSQLColumnData(q, 1),
xspawn = GetSQLColumnData(q, 2),
yspawn = GetSQLColumnData(q, 3),
zspawn = GetSQLColumnData(q, 4);


if(autosp == "true")
{

Vector(xspawn, yspawn, zspawn);
MessagePlayer("You are spawned");
}
}
else MessagePlayer("You are spawned");
}


I checked with both. In the onPlayerRequestSpawn, nothing happens while in onPlayerSpawn, the person doesn't spawn. Means it only stays, the person doesn't spawn.


Now my question arrives. What is wrong in my code which is not making the person spawn. If I am using a wrong snippet then which is the correct??
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

!

#3
Quote from: umar4911 on Sep 29, 2017, 02:33 PMfunction onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
if(q)
{
local
autosp = GetSQLColumnData(q, 1),
xspawn = GetSQLColumnData(q, 2),
yspawn = GetSQLColumnData(q, 3),
zspawn = GetSQLColumnData(q, 4);


if(autosp == "true")
{

Vector(xspawn, yspawn, zspawn);
MessagePlayer("You are spawned");
}
}
else MessagePlayer("You are spawned");
}

.

GetSQLColumnData starts from 0 not from 1.
function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name LIKE '"+player.Name+"'");
if( q && GetSQLColumnData(q, 0) == "true" ) Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
MessagePlayer("You are spawned");
}

Discord: zeus#5155

umar4911

Quote from: zeus on Sep 29, 2017, 04:37 PM
Quote from: umar4911 on Sep 29, 2017, 02:33 PMfunction onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name = '" + player.Name + "'");
if(q)
{
local
autosp = GetSQLColumnData(q, 1),
xspawn = GetSQLColumnData(q, 2),
yspawn = GetSQLColumnData(q, 3),
zspawn = GetSQLColumnData(q, 4);


if(autosp == "true")
{

Vector(xspawn, yspawn, zspawn);
MessagePlayer("You are spawned");
}
}
else MessagePlayer("You are spawned");
}

.

GetSQLColumnData starts from 0 not from 1.
function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name LIKE '"+player.Name+"'");
if( q && GetSQLColumnData(q, 0) == "true" ) Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
MessagePlayer("You are spawned");
}
I modified the code as there were some small errors
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();

Vector(xspawn, yspawn, zspawn);
MessagePlayer("Spawnloc", player);
}
else
MessagePlayer("You are spawned", player);
}
It shows message spawnloc but the players doesnot teleport to its saved locations.

I changed the database sequence and also in all scripts making order:
Autospawn
xaxis
yaxis
zaxis
Name
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

DizzasTeR

There is a well known issue of teleportation at onPlayerSpawn, try using a timer of say 1 second before setting player's position at onPlayerSpawn using player.Pos = Vector(...)

!

Quote from: zeus on Sep 29, 2017, 04:37 PMGetSQLColumnData starts from 0 not from 1.
function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name LIKE '"+player.Name+"'");
if( q && GetSQLColumnData(q, 0) == "true" ) Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
MessagePlayer("You are spawned");
}
Change
Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
to
player.Pos = Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );

Discord: zeus#5155

Aesir

You mean .tofloat(), not .tointeger()

Wont be so accurate if you use integer.
#fuckvcmpcommunity
#lovevccoop
#kewun

umar4911

Quote from: zeus on Sep 30, 2017, 09:20 AM
Quote from: zeus on Sep 29, 2017, 04:37 PMGetSQLColumnData starts from 0 not from 1.
function onPlayerSpawn(player)
{
local q = QuerySQL(tele, "SELECT * FROM spawn WHERE Name LIKE '"+player.Name+"'");
if( q && GetSQLColumnData(q, 0) == "true" ) Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
MessagePlayer("You are spawned");
}
Change
Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
to
player.Pos = Vector( GetSQLColumnData(q, 1).tointeger(), GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger() );
it worked. thanks
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter