Spawnloc - 2 Ways 2 Commands.

Started by Mahmoud Tornado, Jul 10, 2018, 02:19 AM

Previous topic - Next topic

Mahmoud Tornado

Hello, dear VC-MP community.
Still friends requests for making system and now a lot of newbie scripters asked me for spawnloc but they don't wanna the same system,
So i made all of them here.

2 Ways
First way is with PlayerClass mean that when you leave the server it will delete the vectors.
Second way is with database it will save the vectors for every time when player getting in the server.

2 Commands
First cmd is with /setspawnloc that mean you must use it first to save your spawnloc location.
Seconed cmd is only /spawnloc <on, off> the vectors is saving when you type on.


First way - Stats

PlayerClass
Spawnloc = false; // Using to make the spawnloc settings.
VectorX = 0; // spawnloc Vector X.
VectorY = 0; // spawnloc Vector Y.
VectorZ = 0; // spawnloc Vector Z.

onScriptLoad()
Stats <- array(GetMaxPlayers(), null); // Loading stats..

onPlayerJoin( player )
Stats[ player.ID ] = PlayerClass();

onPlayerSpawn( player )
if ( Stats[ player.ID ].Spawnloc ) player.Pos = Vector( Stats[ player.ID ].VectorX, Stats[ player.ID ].VectorY, Stats[ player.ID ].VectorZ ); //Making player spawn in his saved location if his spawnloc is on.

Commands
First Commands - With Setspawnloc
if ( cmd == "setspawnloc" )
{
 Stats[ player.ID ].VectorX = player.Pos.x.tofloat(); //Saving Vector X of player to his stats
 Stats[ player.ID ].VectorY = player.Pos.y.tofloat(); //Saving Vector Y of player to his stats
 Stats[ player.ID ].VectorZ = player.Pos.z.tofloat(); //Saving Vector Z of player to his stats
 MessagePlayer( "[#ffbb00]now use /spawnloc to make it on or off", player );
Announce( "~t~You has set your spawnloc here", player , 0 );
}

else if ( cmd == "spawnloc" )
{
 if ( !text ) MessagePlayer( "[#ffbb00]/" + cmd + " <on/off>", player );
 else {
 if ( text == "on" )
{
 Stats[ player.ID ].Spawnloc = true; //Making the spawnloc ready to use
Announce( "~t~Spawnloc Enabled", player , 0 );
 }
 else if ( text == "off" )
{
 Stats[ player.ID ].Spawnloc = false; //Changing the spawnloc to false
Announce( "~y~Spawnloc Disabled", player , 0 );
 }
 }
 }

Second Command - Setting when truring on
if ( cmd == "spawnloc" )
{
 if ( !text ) MessagePlayer( "[#ffbb00]/" + cmd + " <on/off>", player );
 else {
 if ( text == "on" )
{
 Stats[ player.ID ].VectorX = player.Pos.x.tofloat(); //Saving Vector X of player to his stats
 Stats[ player.ID ].VectorY = player.Pos.y.tofloat(); //Saving Vector Y of player to his stats
 Stats[ player.ID ].VectorZ = player.Pos.z.tofloat(); //Saving Vector Z of player to his stats
 Stats[ player.ID ].Spawnloc = true;  //Making the spawnloc ready to use
 MessagePlayer( "[#ffbb00]You has set your spawnloc here.", player );
Announce( "~t~Spawnloc Enabled", player , 0 );
 }
 else if ( text == "off" )
{
 Stats[ player.ID ].Spawnloc = false;  //Changing the spawnloc to false
Announce( "~y~Spawnloc Disabled", player , 0 );
 }
 }
 }



Second way - Database
onScriptLoad()
Spawnloc <- ConnectSQL( "SpawnLocations.db" ); //Making new database
QuerySQL( Spawnloc, "CREATE TABLE IF NOT EXISTS Accounts ( Name VARCHAR(32), VectorX VARCHAR(25), VectorY VARCHAR(25), VectorZ VARCHAR(25), Spawnloc TEXT )" ); //Creating tables

onPlayerSpawn(player)
local q = QuerySQL(Spawnloc, "SELECT * FROM Accounts WHERE Name = '" + player.Name + "'"); //Checking player name
if( q && GetSQLColumnData(q, 4) == "on" ) // if player has spawnloc on
{
local ppy = GetSQLColumnData(q, 2).tointeger(), //Making local for player Y which saved before in db
ppx = GetSQLColumnData(q, 1).tointeger(),  //Making local for player X which saved before in db
ppz = GetSQLColumnData(q, 3).tointeger();  //Making local for player Z which saved before in db
player.Pos = Vector( ppx, ppy, ppz); //Setting player place in spawnloc <saved> place.
}

Commands
First Commands - With Setspawnloc
if(cmd == "setspawnloc")
{
local q = QuerySQL(Spawnloc, "SELECT * FROM Accounts WHERE Name = '" + player.Name + "'"); //Getting player name from db
if(!q) QuerySQL(Spawnloc, "INSERT INTO Accounts ( Name, VectorX, VectorY, VectorZ, Spawnloc ) VALUES ( '" + player.Name + "', '0' , '0' , '0','null' ) "); // if player not in db make an place for him
else{
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorX = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'"); //Saving X
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorY = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'"); //Saving Y
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorZ = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'"); //Saving Z
MessagePlayer( "[#ffbb00]You has set your spawnloc here.", player );
Announce( "~t~Spawnloc Enabled", player , 0 );
}
}
 
else if(cmd == "spawnloc")
{
if(!text) MessagePlayer("[#ff0000]/" + cmd + " <on/off>", player);
local q = QuerySQL(Spawnloc, "SELECT * FROM Accounts WHERE Name = '" + player.Name + "'"); //Getting player from db
if(!q) MessagePlayer("[#ffbb00]you didn't set your spawnloc yet, use /setspawnloc.", player); // if player didn't set his location
else
{
if(text == "on")
{
QuerySQL(Spawnloc, "UPDATE Accounts SET Spawnloc = 'on' WHERE Name = '" + player.Name + "'"); //Setting the spawnloc on
Announce( "~t~Spawnloc Enabled", player , 0 );
}
if(text == "off")
{
QuerySQL(Spawnloc, "UPDATE Accounts SET Spawnloc = 'off' WHERE Name = '" + player.Name + "'"); //Setting the spawnloc off
Announce( "~y~Spawnloc Disabled", player , 0 );
}
}
}

Second Command - All in /spawnloc
else if(cmd == "spawnloc")
{
if(!text) MessagePlayer("[#ff0000]/" + cmd + " <on/off>", player);
local q = QuerySQL(Spawnloc, "SELECT * FROM Accounts WHERE Name = '" + player.Name + "'"); //Getting player name from db
if(!q) QuerySQL(Spawnloc, "INSERT INTO Accounts ( Name, VectorX, VectorY, VectorZ, Spawnloc ) VALUES ( '" + player.Name + "', '0' , '0' , '0','null' ) "); // if player not in db make an place for him
else
{
if(text == "on")
{
QuerySQL(Spawnloc, "UPDATE Accounts SET Spawnloc = 'on' WHERE Name = '" + player.Name + "'"); //Spawnloc on
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorX = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'"); //Saving X
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorY = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'"); //Saving Y
QuerySQL(Spawnloc, "UPDATE Accounts SET VectorZ = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'"); //Saving Z
Announce( "~t~Spawnloc Enabled", player , 0 );
}
if(text == "off")
{
QuerySQL(Spawnloc, "UPDATE Accounts SET Spawnloc = 'off' WHERE Name = '" + player.Name + "'"); //Changing the Spawnloc to off
Announce( "~y~Spawnloc Disabled", player , 0 );
}
}
}

Hope it make my friends happy, Hope it make anyone happy, Hope it make you happy.
Have a nice day, love you all, yours...
Mahmoud Ashraf

Xmair

Stats[ player.ID ] = PlayerClass(); //Making an loop with PlayerClass and Stats.That's not a loop.

Credits to Boystang!

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

Mahmoud Tornado

Quote from: Xmair on Jul 10, 2018, 07:41 AMStats[ player.ID ] = PlayerClass(); //Making an loop with PlayerClass and Stats.That's not a loop.
Just word to explain.

Xmair

You're guiding people wrong with that "word".

Credits to Boystang!

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

Mahmoud Tornado


=RK=MarineForce

bro setspawnloc is bad

i have a suggest . change it to when player leave server database will save him pos loc and when i spawn i will spawn where i leave

and can u give me buy weps from ammunation @Xmair and  tornado any
Try to UnderStand ME!