Won't Load Money/Score.
#1

Saves it fine, saves the account. But when I reconnect it sets my money and score to 0.

Full code.
pawn Код:
#include    <a_samp>
#include    < zcmd >
#include    < YDB  >
#include < YSI\y_ini >

#define DIRECTORY       "Accounts/%s.ini"
//Colors//
#define COLOR_SYSTEM    (0xEFEFF7AA)
#define green           (0x33FF33AA)
#define blue            (0x00FFFFAA)
#define red             (0xFF0000AA)
#define StartMoney 150000


forward Pass( playerid, name[ ], value[ ] );
forward LoadpUser( playerid, name[ ], value[ ] );

enum pLog
{
    pPass,
    pCash,
    pScore
}

public OnFilterScriptInit( )
{
    print( "\n--------------------------------------" );
    print( "Account System                          " );
    print( "--------------------------------------\n" );
    return ( 1 );
}

public OnPlayerRequestSpawn( playerid )
{
    if( INI_Exist ( pName( playerid ) ) )
    {
        if( GetPVarInt( playerid, "pLog" ) == 0 )
        {
            SendClientMessage( playerid, green, "This name is already registered. Please /login password to login to this account. ");
            return ( 0 );
        }
    }
        else { SystemMsg( playerid, "Please register this account before spawning." ); return 0; }
    return 1;
}

public OnPlayerDisconnect( playerid )
{
    if( GetPVarInt( playerid, "pLog" ) == 1 )
    {
        new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
        new INI:PlayerAcc = INI_Open( file );
        INI_WriteInt( PlayerAcc, "Money", GetPlayerMoney( playerid ) );
        INI_WriteInt( PlayerAcc, "Score", GetPlayerScore( playerid ) );
        INI_Close( PlayerAcc );
        SetPVarInt( playerid, "pLog", 0 );
    }
    return ( 1 );
}

public OnPlayerConnect( playerid )
{
   
    if( GetPVarInt( playerid, "pLog" ) == 0 )
    {
        if( INI_Exist ( pName( playerid ) ) )
        {

            SystemMsg( playerid, "This name is already registered. Please /login [password] to login." );
        }
        else SystemMsg( playerid, "This name is not registered. /register password for free $150,000!" );
       
    }
    return ( 1 );
}

stock SystemMsg( playerid, msg[ ] )
{
   if( ( IsPlayerConnected ( playerid ) ) && ( strlen ( msg ) > 0 ) ) SendClientMessage( playerid, red, msg );
   return ( 1 );
}

stock pName( playerid )
{
    new name[ MAX_PLAYER_NAME ];
    GetPlayerName( playerid, name, sizeof name );
    return name;
}

CMD:register( playerid, params[ ] )
{
   
    new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
    new INI:PlayerAcc = INI_Open( file );
    if( GetPVarInt( playerid, "pLog" ) == 1 ) return SystemMsg( playerid, "You already have an account." );
    if( INI_Exist( pName( playerid ) ) ) return SystemMsg( playerid, "You already have an account, /login [password] to login." );
    if( strlen ( params ) == 0 ) return SystemMsg( playerid, "Usage: /register [password]" );
    SystemMsg( playerid, "You have successfully created your account. Please /login [password] to login." );
    GivePlayerMoney(playerid, StartMoney);
    INI_WriteString( PlayerAcc, "Name", pName( playerid ) );
    INI_WriteString( PlayerAcc, "Password", params );
    INI_Close( PlayerAcc );
    return ( 1 );
}

CMD:login( playerid, params[ ] )
{
    new file[ 256 ], Passw[ 500 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
    INI_ParseFile(file, "Pass", false, true, playerid);
    GetPVarString( playerid, "pPass", Passw, sizeof Passw );
    if( GetPVarInt( playerid, "pLog" ) == 1 ) return SystemMsg( playerid, "You have already logged-in." );
    if( !INI_Exist ( pName( playerid ) ) ) return SystemMsg( playerid, "This name is not registered. /register password for free $150,000!" );
    if( isnull ( params ) ) return SystemMsg( playerid, "Usage: /login [password]" );
    if( strcmp ( Passw, params, false ) == 0 )
    {
        SetPVarInt( playerid, "pLog", 1 );
        GivePlayerMoney( playerid, GetPVarInt( playerid, "pCash" ) );
        SetPlayerScore( playerid, GetPVarInt( playerid, "pScore" ) );
        SystemMsg( playerid, "You have successfully logged-in." );
    }else SystemMsg( playerid, "Wrong Credentials!" );
    return ( 1 );
}

public Pass( playerid, name[ ], value[ ] )
{
    if( !strcmp ( name, "Password" ) )
    {
        SetPVarString( playerid, "pPass", value );
    }
}

public LoadpUser( playerid, name[ ], value[ ] )
{
    if( !strcmp ( name, "Money" ) )
    {
        SetPVarInt( playerid, "pCash", strval( value ) );
    }
    if( !strcmp ( name, "Score" ) )
    {
        SetPVarInt( playerid, "pScore", strval( value ) );
    }
}
Reply
#2

pawn Код:
public OnPlayerDisconnect( playerid )
{
   if(playerid!=INVALID_PLAYER_ID)
 {
    if( GetPVarInt( playerid, "pLog" ) == 1 )
    {
        new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
        new INI:PlayerAcc = INI_Open( file );
        INI_WriteInt( PlayerAcc, "Money", GetPlayerMoney( playerid ) );
        INI_WriteInt( PlayerAcc, "Score", GetPlayerScore( playerid ) );
        INI_Close( PlayerAcc );
        SetPVarInt( playerid, "pLog", 0 );
    }
   }
    return ( 1 );
}
Try this ....
Reply
#3

Quote:
Originally Posted by Rittik
Посмотреть сообщение
pawn Код:
public OnPlayerDisconnect( playerid )
{
   if(playerid!=INVALID_PLAYER_ID)
 {
    if( GetPVarInt( playerid, "pLog" ) == 1 )
    {
        new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
        new INI:PlayerAcc = INI_Open( file );
        INI_WriteInt( PlayerAcc, "Money", GetPlayerMoney( playerid ) );
        INI_WriteInt( PlayerAcc, "Score", GetPlayerScore( playerid ) );
        INI_Close( PlayerAcc );
        SetPVarInt( playerid, "pLog", 0 );
    }
   }
    return ( 1 );
}
Try this ....
Negative.
Seems the score and money get reset before I connect
Reply
#4

Try storing the values in a variable.
pawn Код:
new money,score;
money=GetPlayerMoney(playerid);
score=GetPlayerScore(playerid);
Reply
#5

replace under the login section with this.

You are setting the PlayerVariable when you want to retrieve it then set. Im only spit balling though, Hope this helps ya

Код:
GetPVarInt( playerid, "pLog", 1 );
        GivePlayerMoney( playerid, GetPVarInt( playerid, "pCash" ) );
        SetPlayerScore( playerid, GetPVarInt( playerid, "pScore" ) );
Reply
#6

Quote:
Originally Posted by Rittik
Посмотреть сообщение
Try storing the values in a variable.
pawn Код:
new money,score;
money=GetPlayerMoney(playerid);
score=GetPlayerScore(playerid);
error 010: invalid function or declaration
warning 203: symbol is never used: "money"
warning 203: symbol is never used: "score"
Reply
#7

pawn Код:
public OnPlayerDisconnect( playerid )
{
   if(playerid!=INVALID_PLAYER_ID)
 {
    if( GetPVarInt( playerid, "pLog" ) == 1 )
    {
        new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
        new money,score;
        money=GetPlayerMoney(playerid);
        score=GetPlayerScore(playerid);
        new INI:PlayerAcc = INI_Open( file );
        INI_WriteInt( PlayerAcc, "Money", money );
        INI_WriteInt( PlayerAcc, "Score", score);
        INI_Close( PlayerAcc );
        SetPVarInt( playerid, "pLog", 0 );
    }
   }
    return ( 1 );
}
Reply
#8

Quote:
Originally Posted by Ciandlah
Посмотреть сообщение
replace under the login section with this.

You are setting the PlayerVariable when you want to retrieve it then set. Im only spit balling though, Hope this helps ya

Код:
GetPVarInt( playerid, "pLog", 1 );
        GivePlayerMoney( playerid, GetPVarInt( playerid, "pCash" ) );
        SetPlayerScore( playerid, GetPVarInt( playerid, "pScore" ) );
warning 202: number of arguments does not match definition
On this line
pawn Код:
GetPVarInt( playerid, "pLog", 1 );
And it still set score to 0. Don't know about money cause after I /login, it says Ive successfully logged in, then says the account is registered already and that I need to login So i cant spawn
Reply
#9

Quote:
Originally Posted by Rittik
Посмотреть сообщение
pawn Код:
public OnPlayerDisconnect( playerid )
{
   if(playerid!=INVALID_PLAYER_ID)
 {
    if( GetPVarInt( playerid, "pLog" ) == 1 )
    {
        new file[ 256 ]; format( file, sizeof file, DIRECTORY, pName( playerid ) );
        new money,score;
        money=GetPlayerMoney(playerid);
        score=GetPlayerScore(playerid);
        new INI:PlayerAcc = INI_Open( file );
        INI_WriteInt( PlayerAcc, "Money", money );
        INI_WriteInt( PlayerAcc, "Score", score);
        INI_Close( PlayerAcc );
        SetPVarInt( playerid, "pLog", 0 );
    }
   }
    return ( 1 );
}
No errors/warnings. Still not workin.
Reply
#10

Use kush's reg/log system with Y_ini and dialogs.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)