Flaws while reading from a string
#1

So I'm giving a random number upon registering. After the player registers and spawns - Code's value is "0". After the player relogs with already registered account, then the code appears, so basically why is it not appearing already after registering? (I'm using easydialogs.inc, but that's not the case)

There's the code:

pawn Код:
public OnPlayerSpawn(playerid)
{
    new
        str[32];
    format(str, sizeof(str), "Code: %i", PlayerInfo[playerid][pCode]);
    playertext[playerid] = Create3DTextLabel(str, Orange, 30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(playertext[playerid], playerid, 0.0, 0.0, 0.4);
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    Delete3DTextLabel(playertext[playerid]);
    SaveData(playerid);
    return 1;
}
pawn Код:
Dialog:Register(playerid, response, listitem, inputtext[])
{
    if (!response) return Kick(playerid);
    if (response)
    {
        if(!strlen(inputtext))
        {
// show dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {
            INI_WriteString("Password", inputtext);
            INI_WriteInt("Money",       5000);
            INI_WriteInt("AdminLevel",  0);
            INI_WriteInt("Code",        random(500));
            INI_Save();
            INI_Close();
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
        }
    }
    return 1;
}
pawn Код:
Dialog:Login(playerid, response, listitem, inputtext[])
{
    if (!response) return Kick(playerid);
    if(response)
    {
        if(!strlen(inputtext))
        {
// show dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {
            INI_ReadString(PlayerInfo[playerid][pPassword], "Password", 20);
            if(strcmp(inputtext, PlayerInfo[playerid][pPassword], false))
            {
// show dialog stuff
            }
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid, INI_ReadInt("Money"));
            PlayerInfo[playerid][pAdminLevel] = INI_ReadInt("AdminLevel");
            PlayerInfo[playerid][pCode] = INI_ReadInt("Code");
            INI_Close();
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
        }
    }
    return 1;
}
pawn Код:
stock SaveData(playerid)
{
    if(INI_Open(getINI(playerid)))
    {
        INI_WriteInt("Money",           INI_ReadInt("Money"));
        INI_WriteInt("AdminLevel",      INI_ReadInt("AdminLevel"));
        INI_WriteInt("Code",            INI_ReadInt("Code"));
        INI_Save();
        INI_Close();
    }
}
Reply
#2

Any ideas?
Reply
#3

Your not setting the random value when they register your only saving it to file.

Also.... don't do this

if (!response) return Kick(playerid);
if (response)

do this

if(!reponse) Kick(playerid);
else
{
}

no need for two ifs here.
Reply
#4

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Your not setting the random value when they register your only saving it to file.

Also.... don't do this

if (!response) return Kick(playerid);
if (response)

do this

if(!reponse) Kick(playerid);
else
{
}

no need for two ifs here.
Thank you for tips! I don't quite understand the part of setting that random value as I'm going to generate it only once, so a unique value to every player, just I haven't made any checks for that yet. Basically, when they register they receive their value and when they spawn, it appears.
Reply
#5

Ya you need to set that value to the variable it would be loaded from when they log in so basically your doing this when the register this way their array has the value set after registering and it is also saved in file when they log in I hope this clears things up.

PlayerInfo[playerid][pCode] = random(500);
INI_WriteInt("Code", PlayerInfo[playerid][pCode]);
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Ya you need to set that value to the variable it would be loaded from when they log in so basically your doing this when the register this way their array has the value set after registering and it is also saved in file when they log in I hope this clears things up.

PlayerInfo[playerid][pCode] = random(500);
INI_WriteInt("Code", PlayerInfo[playerid][pCode]);
Oh, so when they login, they receive their random code? If I'm giving them codes on both register and login won't it mess up?
Reply
#7

Why? Your saving the code then reloading it when they login unless they get a new code each time then there would be no need to save it.
Reply
#8

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Why? Your saving the code then reloading it when they login unless they get a new code each time then there would be no need to save it.
Well, I just checked and now it gives me a new code every time I reconnect.

pawn Код:
/* -------------------------------------------------------------------------- */
Dialog:Register(playerid, response, listitem, inputtext[])
{
    if(!response) Kick(playerid);
    else
    {
        if(!strlen(inputtext))
        {
// dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {
            INI_WriteString("Password", inputtext);
            INI_WriteInt("Money",       5000);
            INI_WriteInt("AdminLevel",  0);
            INI_WriteInt("Code",        random(500));
            INI_Save();
            INI_Close();
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
            PlayerPlaySound(playerid, 1057 ,0.0, 0.0, 0.0);
        }
    }
    return 1;
}
/* -------------------------------------------------------------------------- */
Dialog:Login(playerid, response, listitem, inputtext[])
{
    if (!response) Kick(playerid);
    else
    {
        if(!strlen(inputtext))
        {
// dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {
            INI_ReadString(PlayerInfo[playerid][pPassword], "Password", 20);
            if(strcmp(inputtext, PlayerInfo[playerid][pPassword], false))
            {
// dialog stuff
            }
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid, INI_ReadInt("Money"));
            PlayerInfo[playerid][pAdminLevel] = INI_ReadInt("AdminLevel");
            PlayerInfo[playerid][pCode] = random(500);
            INI_WriteInt("Code", PlayerInfo[playerid][pCode]);
            INI_Close();
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
        }
    }
    return 1;
}
Reply
#9

You're going about doing this the wrong way, you were assigning the player a new code whenever they logged in, and you were just saving the code to a file upon registration and not assigning it to the player enum.

pawn Код:
/* -------------------------------------------------------------------------- */
Dialog:Register(playerid, response, listitem, inputtext[])
{
    if(!response) Kick(playerid);
    else
    {
        if(!strlen(inputtext))
        {
            // dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {  
            PlayerInfo[playerid][pCode] = random(500);
           
            INI_WriteString("Password", inputtext);
            INI_WriteInt("Money",       5000);
            INI_WriteInt("AdminLevel",  0);
            INI_WriteInt("Code",        PlayerInfo[playerid][pCode]);
           
            INI_Save();
            INI_Close();
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
            PlayerPlaySound(playerid, 1057 ,0.0, 0.0, 0.0);
        }
    }
    return 1;
}
/* -------------------------------------------------------------------------- */
Dialog:Login(playerid, response, listitem, inputtext[])
{
    if (!response) Kick(playerid);
    else
    {
        if(!strlen(inputtext))
        {
            // dialog stuff
        }
        if(INI_Open(getINI(playerid)))
        {
            INI_ReadString(PlayerInfo[playerid][pPassword], "Password", 20);
            if(strcmp(inputtext, PlayerInfo[playerid][pPassword], false))
            {
                // dialog stuff
            }
           
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid, INI_ReadInt("Money"));
           
            PlayerInfo[playerid][pAdminLevel] = INI_ReadInt("AdminLevel");
            PlayerInfo[playerid][pCode] = ReadInt("Code");
           
            INI_Close();
           
            SetSpawnInfo(playerid, 0, 6, 1772.3214, -1908.2968, 13.5531, 271.5665, 0, 0, 0, 0, 0, 0);
            SpawnPlayer(playerid);
        }
    }
    return 1;
}
Try this.
Reply
#10

Quote:
Originally Posted by DanLore
Посмотреть сообщение
Try this.
Seems working. Thanks a bunch!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)