Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Mötley on Apr 30, 2016, 05:56 PM

Title: [the index 'ID' does not exist]
Post by: Mötley on Apr 30, 2016, 05:56 PM
AN ERROR HAS OCCURED [the index 'ID' does not exist]

function Login( player, Password )
{
if ( Password )
{
Account[ player.ID ].Kills = Stats.Get( player.Name + " Kills" );
Account[ player.ID ].Deaths = Stats.Get( player.Name + " Deaths" );
Account[ player.ID ].Joins = Stats.Get( player.Name + " Joins" );
Account[ player.ID ].Headshots = Stats.Get( player.Name + " Headshots" );
Account[ player.ID ].Cash = Stats.Get( player.Name + " Cash" );
Account[ player.ID ].Level = Stats.Get( player.Name + " Level" );                   

Account[ player.ID ].Joins++;

player.Score += Account[ player.ID ].Kills;

Account[player.ID].Logged = true;

local AC_Hashes = Account[ player.ID ];

MessagePlayer ( "Account loaded with " + AC_Hashes.Kills + " Kills, " + AC_Hashes.Deaths + " Deaths, " + AC_Hashes.Headshots + " Headshots, $" + AC_Hashes.Cash + " Cash", player );

}
}
[LU] but more people are hear, I have done this recently and no issue but now there is :o
Title: Re: [the index 'ID' does not exist]
Post by: . on Apr 30, 2016, 05:58 PM
Which line?
Title: Re: [the index 'ID' does not exist]
Post by: Mötley on Apr 30, 2016, 06:01 PM
Anything related to player.ID, no mater what I do. if i remove one line it does it to the rest

if i do PlayerStats().Kills = Stats.Get( player.Name + " Kills" ); its inaccurate but does not throw the error
Title: Re: [the index 'ID' does not exist]
Post by: . on Apr 30, 2016, 06:03 PM
What does print(typeof(player)); give?
Title: Re: [the index 'ID' does not exist]
Post by: Mötley on Apr 30, 2016, 06:07 PM
Care to explain better? I am lost as I have gotten myself too confused with this strange error,.

the register function works perfect

function Register( Player, Password )
{
Stats.Add( Player.Name + " Password", MD5( Password ) );
Stats.Add( Player.Name + " IP", Player.IP );
Stats.Add( Player.Name + " Kills", Account[ Player.ID ].Kills );
Stats.Add( Player.Name + " Deaths", Account[ Player.ID ].Deaths );
Stats.Add( Player.Name + " Headshots", Account[ Player.ID ].Headshots );
Stats.Add( Player.Name + " Level", 1 );
Stats.Add( Player.Name + " Skin", Account[ Player.ID ].Skin );
Stats.Add( Player.Name + " Cash", Account[ Player.ID ].Cash );
Stats.Add( Player.Name + " Joins", Account[ Player.ID ].Joins );

Stats.Add( Player.Name + " UID", Player.LUID );
SaveHashes();

Account [ Player.ID ].Logged = true;

}

Hear is the log

AN ERROR HAS OCCURED [the index 'ID' does not exist]

<30/04/2016 - 13:53:56>
CALLSTACK

<30/04/2016 - 13:53:56> *FUNCTION [Login()] Scripts/Main/main.txt line [135]

<30/04/2016 - 13:53:56> *FUNCTION [onPlayerCommand()] Scripts/Main/main.txt line [80]

<30/04/2016 - 13:53:56>
LOCALS

<30/04/2016 - 13:53:56> [Password] "1a1dc91c907325c69271ddf0c944bc72"

<30/04/2016 - 13:53:56> [player] CLASS

<30/04/2016 - 13:53:56> [this] TABLE

<30/04/2016 - 13:53:56> [plrStats] INSTANCE

<30/04/2016 - 13:53:56> [Password] "1a1dc91c907325c69271ddf0c944bc72"

<30/04/2016 - 13:53:56> [Level] 1

<30/04/2016 - 13:53:56> [text] "pass"

<30/04/2016 - 13:53:56> [cmd] "login"

<30/04/2016 - 13:53:56> [player] INSTANCE

<30/04/2016 - 13:53:56> [this] TABLE
Title: Re: [the index 'ID' does not exist]
Post by: . on Apr 30, 2016, 06:15 PM
I simply asked you to tell me what does the print(typeof(player)); output in that Login function. Execute it first before any error gets a chance to show up and tell me what does it say.
Title: Re: [the index 'ID' does not exist]
Post by: Mötley on Apr 30, 2016, 06:32 PM
I am going to just rebuild the entire function later as I am just way to find FD to understand anything at all right now.

Update: FIXED

Reason; The Player stats where not correctly connected to the player class.
As well as I should of made sure to keep functions out of commands
Example:

else if ( cmd == "login" )
{
if ( !text ) MessagePlayer( "Correct way is. /login <password>", player );
else if ( Level == 0 ) MessagePlayer( "You are not registered with us.", player );
else if (( Account[ player.ID ].Logged ) == true ) MessagePlayer( "You are already logged in.", player );
else if ( MD5( text ) != Password ) MessagePlayer( "Invalid Password.", player );
else
{
MessagePlayer( "You have successfully logged in!", player );
Login( player );
}
}
}

The command should be

else if ( cmd == "login" )
{
    Login( player );
}

And place the checks in the function not in the command, this helps to keep things more clean in the command system.

If you have encountered this error in general something is not properly connected, In my situation the Class. Always double check other places as I had this happen in a position database in the past. and that as well was due to a miss type for the name of a array,
Title: Re: [the index 'ID' does not exist]
Post by: ysc3839 on May 01, 2016, 02:40 AM
I think you shouldn't use MD5. I use SHA256+salt.
Title: Re: [the index 'ID' does not exist]
Post by: KAKAN on May 01, 2016, 03:49 AM
Quote from: ysc3839 on May 01, 2016, 02:40 AMI think you shouldn't use MD5. I use SHA256+salt.
WHIRLPOOL + Salt is better. Though, I still prefer SHA256
Title: Re: [the index 'ID' does not exist]
Post by: Mötley on May 01, 2016, 04:29 AM
I prefer WHIRLPOOL in general, Its Just when I build an account system its simpler to type Three letters MD5 it is to simple.I might salt, but at this time i prefer not to so I can view the data to ensure everything is correct.

Topic Is now locked.