Sonmez

  • Newbie
  • Yo! It's time to play the fair game!
  • Posts: 15
Basic Auto Spawn, Last Pos, Last Skin system
«  »
Code: [Select]
function onScriptLoad()
{
 LpDataBase <- ConnectSQL("LpDataBase.db");
QuerySQL(LpDataBase, "create table if not exists LastposTable ( Name TEXT, X NUMERIC DEFAULT 0, Y NUMERIC DEFAULT 0, Z NUMERIC DEFAULT 0, LastSkin NUMERIC DEFAULT 0, AutoSpawn NUMERIC DEFAULT 0) ");
lastpos <- array(GetMaxPlayers(), null);
print("AutoSpawn system by Sonmez loaded...");
}

class LastPos
{
 X = 0;
 Y = 0;
 Z = 0;
 LastSkin = 0;
 AutoSpawn = 0;
}
function onPlayerJoin( player )
{
lastpos[ player.ID ] = LastPos();
GetLastPosInfo(player);
}
function GetLastPosInfo(player)
{
 local q = QuerySQL(LpDataBase, "SELECT * FROM LastposTable WHERE Name = '" + escapeSQLString(player.Name) + "'");
 if (q)
 {
  lastpos[ player.ID ].X = GetSQLColumnData(q, 1);
  lastpos[ player.ID ].Y = GetSQLColumnData(q, 2);
  lastpos[ player.ID ].Z = GetSQLColumnData(q, 3);
  lastpos[ player.ID ].LastSkin = GetSQLColumnData(q, 4);
  lastpos[ player.ID ].AutoSpawn = GetSQLColumnData(q, 5);
 }
 else
 {
  QuerySQL( LpDataBase, "INSERT INTO LastposTable ( Name, X, Y, Z, LastSkin, AutoSpawn ) VALUES ( '" + escapeSQLString(player.Name) + "','" +0+ "', '" +0+ "', '" +0+ "', '" + 0 + "', '" + 0 + "' )" );
  lastpos[ player.ID ].X = 0;
  lastpos[ player.ID ].Y = 0;
  lastpos[ player.ID ].Z = 0;
  lastpos[player.ID].LastSkin = 0;
  lastpos[ player.ID ].AutoSpawn = 0;
  }
}

function SaveLastPos(player)
{
QuerySQL( LpDataBase, "UPDATE LastposTable SET X='"+lastpos[player.ID].X+"', Y='"+lastpos[player.ID].Y+"', Z='"+lastpos[player.ID].Z+"', LastSkin='"+lastpos[ player.ID ].LastSkin+"', AutoSpawn='"+lastpos[ player.ID ].AutoSpawn+"' WHERE Name LIKE '" + player.Name + "'" );
}
function onPlayerPart( player, reason )
{
  lastpos[ player.ID ].X = player.Pos.x;
  lastpos[ player.ID ].Y = player.Pos.y;
  lastpos[ player.ID ].Z = player.Pos.z;
  lastpos[player.ID].LastSkin = player.Skin;
SaveLastPos(player);
}

function onPlayerRequestClass( player, classID, team, skin )
{
if (lastpos[player.ID].AutoSpawn == 1 ) {player.Spawn();}
else {
    return 1;
}
}

function onPlayerSpawn( player )
{
if (lastpos[player.ID].AutoSpawn == 1 ) {player.Skin = lastpos[player.ID].LastSkin; player.Pos = Vector(lastpos[player.ID].X,lastpos[player.ID].Y,lastpos[player.ID].Z);}
if (lastpos[player.ID].AutoSpawn == 0 )
{
return 1;
}
}

function onPlayerCommand( player, cmd, text )
{
if (cmd == "autospawn")
{
if (text == "on")
{
MessagePlayer("[#ffffff]** AutoSpawn enabled.", player);
lastpos[player.ID].AutoSpawn = 1;
}
else if (text == "off")
{
MessagePlayer("[#ffffff]** AutoSpawn disabled.", player);
lastpos[player.ID].AutoSpawn = 0;
}
else MessagePlayer("[#ff0000][ERROR] [#ffffff]Use, /"+cmd+" <on/off>", player);
}
}
if (!perfect) createAgain();

Alecu Madalin

  • Jr. Member
  • Posts: 92
Re: Basic Auto Spawn, Last Pos, Last Skin system
« Reply #1,  »
Quote from Sonmez on June 4th, 01:11 PM
Code: [Select]
function onScriptLoad()
{
 LpDataBase <- ConnectSQL("LpDataBase.db");
QuerySQL(LpDataBase, "create table if not exists LastposTable ( Name TEXT, X NUMERIC DEFAULT 0, Y NUMERIC DEFAULT 0, Z NUMERIC DEFAULT 0, LastSkin NUMERIC DEFAULT 0, AutoSpawn NUMERIC DEFAULT 0) ");
lastpos <- array(GetMaxPlayers(), null);
print("AutoSpawn system by Sonmez loaded...");
}

class LastPos
{
 X = 0;
 Y = 0;
 Z = 0;
 LastSkin = 0;
 AutoSpawn = 0;
}
function onPlayerJoin( player )
{
lastpos[ player.ID ] = LastPos();
GetLastPosInfo(player);
}
function GetLastPosInfo(player)
{
 local q = QuerySQL(LpDataBase, "SELECT * FROM LastposTable WHERE Name = '" + escapeSQLString(player.Name) + "'");
 if (q)
 {
  lastpos[ player.ID ].X = GetSQLColumnData(q, 1);
  lastpos[ player.ID ].Y = GetSQLColumnData(q, 2);
  lastpos[ player.ID ].Z = GetSQLColumnData(q, 3);
  lastpos[ player.ID ].LastSkin = GetSQLColumnData(q, 4);
  lastpos[ player.ID ].AutoSpawn = GetSQLColumnData(q, 5);
 }
 else
 {
  QuerySQL( LpDataBase, "INSERT INTO LastposTable ( Name, X, Y, Z, LastSkin, AutoSpawn ) VALUES ( '" + escapeSQLString(player.Name) + "','" +0+ "', '" +0+ "', '" +0+ "', '" + 0 + "', '" + 0 + "' )" );
  lastpos[ player.ID ].X = 0;
  lastpos[ player.ID ].Y = 0;
  lastpos[ player.ID ].Z = 0;
  lastpos[player.ID].LastSkin = 0;
  lastpos[ player.ID ].AutoSpawn = 0;
  }
}

function SaveLastPos(player)
{
QuerySQL( LpDataBase, "UPDATE LastposTable SET X='"+lastpos[player.ID].X+"', Y='"+lastpos[player.ID].Y+"', Z='"+lastpos[player.ID].Z+"', LastSkin='"+lastpos[ player.ID ].LastSkin+"', AutoSpawn='"+lastpos[ player.ID ].AutoSpawn+"' WHERE Name LIKE '" + player.Name + "'" );
}
function onPlayerPart( player, reason )
{
  lastpos[ player.ID ].X = player.Pos.x;
  lastpos[ player.ID ].Y = player.Pos.y;
  lastpos[ player.ID ].Z = player.Pos.z;
  lastpos[player.ID].LastSkin = player.Skin;
SaveLastPos(player);
}

function onPlayerRequestClass( player, classID, team, skin )
{
if (lastpos[player.ID].AutoSpawn == 1 ) {player.Spawn();}
else {
    return 1;
}
}

function onPlayerSpawn( player )
{
if (lastpos[player.ID].AutoSpawn == 1 ) {player.Skin = lastpos[player.ID].LastSkin; player.Pos = Vector(lastpos[player.ID].X,lastpos[player.ID].Y,lastpos[player.ID].Z);}
if (lastpos[player.ID].AutoSpawn == 0 )
{
return 1;
}
}

function onPlayerCommand( player, cmd, text )
{
if (cmd == "autospawn")
{
if (text == "on")
{
MessagePlayer("[#ffffff]** AutoSpawn enabled.", player);
lastpos[player.ID].AutoSpawn = 1;
}
else if (text == "off")
{
MessagePlayer("[#ffffff]** AutoSpawn disabled.", player);
lastpos[player.ID].AutoSpawn = 0;
}
else MessagePlayer("[#ff0000][ERROR] [#ffffff]Use, /"+cmd+" <on/off>", player);
}
}
Basic but it works

dracc

  • Jr. Member
  • Posts: 84
Re: Basic Auto Spawn, Last Pos, Last Skin system
« Reply #2,  »
You don't escape the characters of the name when updating them into the database but you do so when saving and fetching them.
Many names will not be found correctly.