Dini question (Maybe...)
#1

Hello guys.
I am makeing a GM with a login/register system using Dini.
I make the script save everything in the "OnPlayerUpdate" callback.
Something seems to crash the server. Is it because Dini is too slow to keep up with the "OnPlayerUpdate"?

Hope someone can help me. Thanks.
Reply
#2

OnPlayerUpdate is not a good place to save user data to files.

It gets called too often.
Reply
#3

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
OnPlayerUpdate is not a good place to save user data to files.

It gets called too often.
Ok, but i used to do it in "OnPlayerDisconnect, but that callback doesnt get called when the server restarts.
What do you prefer i should do?
Reply
#4

Make a new function, for example 'SavePlayer' and save user data there.

Then use SavePlayer(playerid); in your script where user data changes, like when player gets new score or money or etc.
Reply
#5

look here :

pawn Код:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2

#include <a_samp>
#include <dini>

public OnPlayerConnect(playerid)
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    if(dini_Exists(String))
    {
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
    }
    else
    {
        ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
    }
        return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
            if(dialogid==DIALOG_LOGIN)
    {
        if(response==0)
        {
            SendClientMessage(playerid,BLUE,"You have been kicked for not loging in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))

            {
                SendClientMessage(playerid,RED,"This password is too short");
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
                return 1;
            }
            else
            {
                Login(playerid,inputtext);
                PlayerPlaySound(playerid,1057,0,0,0);
                return 1;
            }
        }
    }
    if(dialogid==DIALOG_REGISTER)
    {
        if(response==0)
        {
            SendClientMessage(playerid,BLUE,"You have been kicked for not registering in.");
            Kick(playerid);
            return 1;
        }
        if(response==1)
        {
            if(!strlen(inputtext))
            {
                SendClientMessage(playerid,BLUE,"This password is too short");
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
                return 1;
            }
            else
            {
                Register(playerid,inputtext);
                return 1;
            }
        }
    }
        return 1;
}

stock Register(playerid,key[])
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    dini_Create(String);
    dini_Set(String,"Password",key);
    SendClientMessage(playerid,BLUE,"Successfully registered");
    dini_IntSet(String,"Level",0);
    return 1;
}

stock Login(playerid,key[])
{
    new String[64];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(String,sizeof(String),"/Accounts/PlNm.txt",name);
    if(!strcmp(key,dini_Get(String,"Password"),false))
    {
        SetPlayerScore(playerid,dini_Int(String,"Level"));
        SendClientMessage(playerid,BLUE,"Successfully logged");
        return 1;
    }
    else
    {
        SendClientMessage(playerid,RED,"Wrong password.");
        PlayerPlaySound(playerid,1055,0,0,0);
        ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
        return 1;
    }
   
}
I hope this helped you a lot :P
Reply
#6

call OnPlayerDisconnect in OnGameModeExit.
Reply
#7

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Make a new function, for example 'SavePlayer' and save user data there.

Then use SavePlayer(playerid); in your script where user data changes, like when player gets new score or money or etc.
By the way;
This system also saves position (so you will spawn where you logged out) and is also saves weapons and ammo.
Where do you want me to call the SavePlayer function there?

Thank you very much
Reply
#8

Quote:
Originally Posted by xDeadlyBoy
Посмотреть сообщение
call OnPlayerDisconnect in OnGameModeExit.
Hmm, yea, but you cant use "playerid" in OnGameModeExit.
Reply
#9

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Hmm, yea, but you cant use "playerid" in OnGameModeExit.
Yeah U can

PHP код:

for(new i=0i<MAX_PLAYERSi++)
{
    
CallLocalFunction("OnPlayerDisconnect""%d"i);

Reply
#10

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
By the way;
This system also saves position (so you will spawn where you logged out) and is also saves weapons and ammo.
Where do you want me to call the SavePlayer function there?

Thank you very much
You can use SavePlayer in OnPlayerDisconnect too.

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Hmm, yea, but you cant use "playerid" in OnGameModeExit.
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
{
    SavePlayer(i);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)