Fixed
For those that would like to do this and keep functions out of commands when Referring to a constructor/class
Hear is the Fixed version
class PlayerClass
{
// ------------------------------------------------------------------- //
IP = "0.0.0.0";
Cash = 0;
Bank = 0;
Kills = 0;
Deaths = 0;
Level = 0;
Password = null;
Logged = false;
// ------------------------------------------------------------------- //
constructor( player )
{
IP = Accounts.Get( player + " IP" );
Cash = Accounts.Get( player + " Cash" );
Bank = Accounts.Get( player + " Bank" );
Kills = Accounts.Get( player + " Kills" );
Deaths = Accounts.Get( player + " Deaths" );
Level = Accounts.Get( player + " Level" );
Password = Accounts.Get( player + " Password" );
Logged = false;
}
function Join( player )
{
if( !Level ){
::MessagePlayer( "Register before spawning! /login <password>", player );
}
else if ( Password )
{
// If they are registered, ask for them to login
if ( Level >= 1 )
{
::MessagePlayer( "Login before spawning! /login <password>", player );
}
}
else{
::MessagePlayer( "Login before spawning! /login <password>", player );
}
}
// This function is used to register a player with the server
// First we will add that players main account information
function Register( player, text )
{
if ( Level >= 1 )
{
::MessagePlayer( "Error - You are already registered.", player );
return 1;
}
else
{
// Otherwise they have logged in succesfully!
Accounts.Add( player.Name + " Password", ::SHA1(text) );
Accounts.Add( player.Name + " Level", 1 );
Accounts.Add( player.Name + " IP", player.IP );
Accounts.Add( player.Name + " GOTO", "off" );
// Then we will add their kills/deaths and cash/bank
Accounts.Add( player.Name + " Cash", 0 );
Accounts.Add( player.Name + " Bank", 0 );
Accounts.Add( player.Name + " Kills", 0 );
Accounts.Add( player.Name + " Deaths", 0 );
// Then finally log that player in
Account[ player.ID ].Logged = true;
::MessagePlayer( "To login to this account type: /login <password>", player );
::MessagePlayer( "You have successfully registered with us!", player );
// And save the hash files
SaveHashes();
}
}
function LoginPlayer( player, text )
{
if ( Level == 0 )
{
// Player hasn't registered so tell them to do so
::MessagePlayer( "// Error: You do not have an account, register with /register <password>", player );
return 1;
}
if ( Account[ player.ID ].Logged == true )
{
// Player has already logged in
::MessagePlayer( "// Error: You are already logged in to your account.", player );
return 1;
}
if ( ::SHA1(text) != Password )
{
// Player has entered wrong password
::MessagePlayer( "Error - Invalid Password.", player );
return 1;
}
else
{
// Otherwise they have logged in succesfully!
Account[ player.ID ].Logged = true;
Account[ player.ID ].Cash = Accounts.Get( player.Name + " Cash" );
Account[ player.ID ].Bank = Accounts.Get( player.Name + " Bank" );
Account[ player.ID ].Kills = Accounts.Get( player.Name + " Kills" );
Account[ player.ID ].Deaths = Accounts.Get( player.Name + " Deaths" );
Account[ player.ID ].Level = Accounts.Get( player.Name + " Level" );
player.Cash = Account[ player.ID ].Cash;
::MessagePlayer( "You have successfully logged in!", player );
}
}
}
Quote from: Vortrex on Apr 15, 2016, 12:30 AMSorry for the late response on this. Didn't realize your replied.
For these two questions:
I thought so, so basically i can run Many functions in the class?
custom functions etc?
Yes, you can add functions to a class, however I believe they use the local scope of the class, so if you need anything global then you'll probably have to add a double colon before whatever it is you need to use (i.e. ::FindVehicle ).
As for the rest, you can add and remove these features yourself, as they aren't hardcoded into LU. For a login and register system, I recommend using one of the base scripts provided by members of the LU community found in the 'Script Releases' section
Quote from: Mötley on May 04, 2016, 01:04 PMFixed
Hear is the Fixed version
how i can hear fixed version here is no audio
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FzuEm514.jpg&hash=56919739e10d4f4c5392077ea92f57a8abeb7553)
Sometime's I wonder about the type of post people make.
Locked due to SPAM!