Ankris question
It seems it is very useful to add certain functions in side of the constructor/class ..
Reasons of why
Less locals and in general it's easier to script. Any good fair warnings as to scripting alot here ?
*I just removed the old post to refresh with this one.
(Old post)
FIXED THANKS!!!
This was just a test script i don't intend to create exploits like cash levels etc
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 );
}
}
}