Spawnloc system by gamingpro

Started by gamingpro, Mar 28, 2023, 06:55 PM

Previous topic - Next topic

gamingpro

function onScriptLoad()
[noae]
SpawnLoc <- ConnectSQL("Spawnloc.db");
QuerySQL(SpawnLoc, "CREATE TABLE IF NOT EXISTS Spawnloc(player TEXT, PX FLOAT, PY FLOAT, PZ FLOAT)");
print("Spawnloc system has been loaded successfully by gamingpro...");
[/noae]
function onPlayerSpawn( player )
[noae]
local q = QuerySQL(SpawnLoc, "SELECT * FROM Spawnloc WHERE player='"+player.Name+"'");
if(q){
local PX = GetSQLColumnData(q,1),
PY = GetSQLColumnData(q,2),
PZ = GetSQLColumnData(q,3);
MessagePlayer("[#00FF00][SPAWN LOC]: [#FFFFFF]You've spawned with your spawn location.",player);
player.Pos = Vector( PX.tofloat(), PY.tofloat(), PZ.tofloat() );
}
[/noae]
function onPlayerCommand( player, command, text )
[noae]
local cmd;
cmd = command.tolower();
if(cmd == "spawnloc"){
if(!text) MessagePlayer("[#FF0000]Error: [#FFFFFF]Correct Syntax /"+cmd+" <on/off>",player);
else {
if(text == "off"){
local q = QuerySQL(SpawnLoc, "SELECT * FROM Spawnloc WHERE player='"+player.Name+"'");
if(!q) MessagePlayer("[#FF0000]Error: [#FFFFFF]Your spawn location is already disabled.",player);
else {
QuerySQL(SpawnLoc, "DELETE FROM Spawnloc WHERE player='"+player.Name+"'");
MessagePlayer("[#00FF00][SPAWN LOC]: [#FFFFFF]You've successfully disabled your spawn location",player);
}
}
else if(text == "on"){
local q = QuerySQL(SpawnLoc, "SELECT * FROM Spawnloc WHERE player='"+player.Name+"'");
if(q) MessagePlayer("[#FF0000]Error: [#FFFFFF]Your spawn location is already enabled.",player);
else {
QuerySQL(SpawnLoc, "INSERT INTO Spawnloc(player, PX, PY, PZ) VALUES('"+player.Name+"', '"+player.Pos.x.tofloat()+"', '"+player.Pos.y.tofloat()+"', '"+player.Pos.z.tofloat()+"')");
MessagePlayer("[#00FF00][SPAWN LOC]: [#FFFFFF]Your spawn location has been enabled on!.",player);
}
}
else MessagePlayer("[#FF0000]Error: [#FFFFFF]Use /"+cmd+" <on/off>",player);
}
}
[/noae]

H.a.S.a.N