Need Some help With this Login system ++REP
#1

Problem 1:

How to make the player can't see other player if they not /login [pass] or /register [pass] ?

Problem 2:

How to make the script store the player's score? I'M TOTALLY NOOB! So..HELP ME!

I took the script from this (https://sampforum.blast.hk/showthread.php?tid=70583) -Thanks to Oxside!

THE CODE:


Код:
new logged[MAX_PLAYERS];
new adminlevel[MAX_PLAYERS];
new money[MAX_PLAYERS];
new playername[MAX_PLAYER_NAME];
OnPlayerConnected

Код:
public OnPlayerConnect(playerid)
{
    logged[playerid] = 0;
    return 1;
}
OnPlayerDisconnected

Код:
public OnPlayerDisconnect(playerid, reason)
{
    money[playerid] = GetPlayerMoney(playerid);
    dini_IntSet(udb_encode(playername), "money", money[playerid]);
    dini_IntSet(udb_encode(playername), "adminlevel", adminlevel[playerid]);
    logged[playerid] = 0;
    return 1;
}
OnPlayerSpawn

Код:
public OnPlayerSpawn(playerid)
{
    if(logged[playerid] == 0)
    {
        SendClientMessage(playerid, COLOR_RED, "You are not logged in! Use /login [password]!");
    }
    return 1;
}
OnPlayerCommandText

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256],tmp[256], tmp2[256];
    new idx;
    new string[256];
    cmd = strtok(cmdtext, idx);
    GetPlayerName(playerid, playername, sizeof(playername));
    if(strcmp(cmd, "/register", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /register (password)");
        }
        else
        {
            if (!dini_Exists(udb_encode(playername)))
            {
                dini_Create(udb_encode(playername));
                dini_IntSet(udb_encode(playername), "password", udb_hash(tmp));
                dini_IntSet(udb_encode(playername), "adminlevel", 0);
                dini_IntSet(udb_encode(playername), "money", 0);
                format(string, sizeof(string), "Account %s created! You can now login with /login %s", playername, tmp);
                SendClientMessage(playerid, COLOR_YELLOW, string);
            }
            else
            {
                format(string, sizeof(string), "%s is already registered.", playername,tmp);
                SendClientMessage(playerid, COLOR_RED, string);
            }
        }
        return 1;
    }


    if(strcmp(cmd, "/login", true) == 0)
    {
        if(logged[playerid] == 1)
        {
            SendClientMessage(playerid, COLOR_RED, "You are already logged in!");
            return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /login [password]");
        }
        else
        {
            if (dini_Exists(udb_encode(playername)))
            {
                tmp2 = dini_Get(udb_encode(playername), "password");
                if (udb_hash(tmp) != strval(tmp2))
                {
                    SendClientMessage(playerid, COLOR_RED, "Wrong/Invalid Password!");
                }
                else
                {
                    logged[playerid] = 1;
                    money[playerid] = dini_Int(udb_encode(playername), "money");
                    adminlevel[playerid] = dini_Int(udb_encode(playername), "adminlevel");
                    format(string, sizeof(string), "%s, you are now logged in . You got admin level %d and have %d dollar", playername, adminlevel[playerid], money[playerid]);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                    GivePlayerMoney(playerid, money[playerid]);
                }
            }
            else
            {
                format(string, sizeof(string), "You are not registerid Type /register [password] to create an account!", playername);
                SendClientMessage(playerid, COLOR_RED, string);
            }
        }
        return 1;
    }

    if(strcmp(cmd, "/makemeadmin", true) == 0)
    {
        if(IsPlayerAdmin(playerid))
        {
            if(logged[playerid] == 1)
            {
                if(adminlevel[playerid] != 3)
                {
                    adminlevel[playerid] = 5;
                    SendClientMessage(playerid, COLOR_GREEN, "You are now maxlevel admin!");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_RED, "You are already maxlevel admin!");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "Please, first login: /login [password]");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "You must first login with rcon! (/rcon login [rcon-pass])");
        }
        return 1;
    }
    return 0;
}
Reply
#2

Hello!

Write it so, it should work:
PHP код:
public OnPlayerConnect(playerid)
{
    
SetPlayerVirtualWorld(playerid,playerid+1);
    
logged[playerid] = 0;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
money[playerid] = GetPlayerMoney(playerid);
    
dini_IntSet(udb_encode(playername), "money"money[playerid]);
    
dini_IntSet(udb_encode(playername), "adminlevel"adminlevel[playerid]);
    
dini_IntSet(udb_encode(playername), "level"GetPlayerScore(playerid));
    
logged[playerid] = 0;
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[256],tmp[256], tmp2[256];
    new 
idx;
    new 
string[256];
    
cmd strtok(cmdtextidx);
    
GetPlayerName(playeridplayernamesizeof(playername));
    if(
strcmp(cmd"/register"true) == 0)
    {
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_YELLOW"USAGE: /register (password)");
        }
        else
        {
            if (!
dini_Exists(udb_encode(playername)))
            {
                
dini_Create(udb_encode(playername));
                
dini_IntSet(udb_encode(playername), "password"udb_hash(tmp));
                
dini_IntSet(udb_encode(playername), "adminlevel"0);
                
dini_IntSet(udb_encode(playername), "money"0);
                
format(stringsizeof(string), "Account %s created! You can now login with /login %s"playernametmp);
                
SendClientMessage(playeridCOLOR_YELLOWstring);
            }
            else
            {
                
format(stringsizeof(string), "%s is already registered."playername,tmp);
                
SendClientMessage(playeridCOLOR_REDstring);
            }
        }
        return 
1;
    }
    if(
strcmp(cmd"/login"true) == 0)
    {
        if(
logged[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_RED"You are already logged in!");
            return 
1;
        }
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_YELLOW"USAGE: /login [password]");
        }
        else
        {
            if (
dini_Exists(udb_encode(playername)))
            {
                
tmp2 dini_Get(udb_encode(playername), "password");
                if (
udb_hash(tmp) != strval(tmp2))
                {
                    
SendClientMessage(playeridCOLOR_RED"Wrong/Invalid Password!");
                }
                else
                {
                    
logged[playerid] = 1;
                    
money[playerid] = dini_Int(udb_encode(playername), "money");
                    
adminlevel[playerid] = dini_Int(udb_encode(playername), "adminlevel");
                    
format(stringsizeof(string), "%s, you are now logged in . You got admin level %d and have %d dollar"playernameadminlevel[playerid], money[playerid]);
                    
SendClientMessage(playeridCOLOR_GREENstring);
                    
GivePlayerMoney(playeridmoney[playerid]);
                    
SetPlayerVirtualWorld(playerid,0);
                }
            }
            else
            {
                
format(stringsizeof(string), "You are not registerid Type /register [password] to create an account!"playername);
                
SendClientMessage(playeridCOLOR_REDstring);
            }
        }
        return 
1;
    }
    if(
strcmp(cmd"/makemeadmin"true) == 0)
    {
        if(
IsPlayerAdmin(playerid))
        {
            if(
logged[playerid] == 1)
            {
                if(
adminlevel[playerid] != 3)
                {
                    
adminlevel[playerid] = 5;
                    
SendClientMessage(playeridCOLOR_GREEN"You are now maxlevel admin!");
                }
                else
                {
                    
SendClientMessage(playeridCOLOR_RED"You are already maxlevel admin!");
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_RED"Please, first login: /login [password]");
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"You must first login with rcon! (/rcon login [rcon-pass])");
        }
        return 
1;
    }
    return 
0;

Mencent
Reply
#3

The first thing you need to do is learn how to use dini. dini is an include file while is used to store data into text files (thus savng the player account)

Here are the dini functions, you can use that to work out what yu doing within. Try making some test scripts and stuf..

https://sampwiki.blast.hk/wiki/Useful_Fu....28Dini.inc.29

Then you use that code above (im asuming you know basic pawn al?) and store the player data (like player name and default values for money/deathcount/killcount) into text files....

When you login you will then read the text file (probably named Player_Name.inc) and check the password the user enters on the server to the password in Player_Name.inc
Reply
#4

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

Write it so, it should work:
PHP код:
public OnPlayerConnect(playerid)
{
    
SetPlayerVirtualWorld(playerid,playerid+1);
    
logged[playerid] = 0;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
money[playerid] = GetPlayerMoney(playerid);
    
dini_IntSet(udb_encode(playername), "money"money[playerid]);
    
dini_IntSet(udb_encode(playername), "adminlevel"adminlevel[playerid]);
    
dini_IntSet(udb_encode(playername), "level"GetPlayerScore(playerid));
    
logged[playerid] = 0;
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[256],tmp[256], tmp2[256];
    new 
idx;
    new 
string[256];
    
cmd strtok(cmdtextidx);
    
GetPlayerName(playeridplayernamesizeof(playername));
    if(
strcmp(cmd"/register"true) == 0)
    {
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_YELLOW"USAGE: /register (password)");
        }
        else
        {
            if (!
dini_Exists(udb_encode(playername)))
            {
                
dini_Create(udb_encode(playername));
                
dini_IntSet(udb_encode(playername), "password"udb_hash(tmp));
                
dini_IntSet(udb_encode(playername), "adminlevel"0);
                
dini_IntSet(udb_encode(playername), "money"0);
                
format(stringsizeof(string), "Account %s created! You can now login with /login %s"playernametmp);
                
SendClientMessage(playeridCOLOR_YELLOWstring);
            }
            else
            {
                
format(stringsizeof(string), "%s is already registered."playername,tmp);
                
SendClientMessage(playeridCOLOR_REDstring);
            }
        }
        return 
1;
    }
    if(
strcmp(cmd"/login"true) == 0)
    {
        if(
logged[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_RED"You are already logged in!");
            return 
1;
        }
        
tmp strtok(cmdtextidx);
        if(!
strlen(tmp))
        {
            
SendClientMessage(playeridCOLOR_YELLOW"USAGE: /login [password]");
        }
        else
        {
            if (
dini_Exists(udb_encode(playername)))
            {
                
tmp2 dini_Get(udb_encode(playername), "password");
                if (
udb_hash(tmp) != strval(tmp2))
                {
                    
SendClientMessage(playeridCOLOR_RED"Wrong/Invalid Password!");
                }
                else
                {
                    
logged[playerid] = 1;
                    
money[playerid] = dini_Int(udb_encode(playername), "money");
                    
adminlevel[playerid] = dini_Int(udb_encode(playername), "adminlevel");
                    
format(stringsizeof(string), "%s, you are now logged in . You got admin level %d and have %d dollar"playernameadminlevel[playerid], money[playerid]);
                    
SendClientMessage(playeridCOLOR_GREENstring);
                    
GivePlayerMoney(playeridmoney[playerid]);
                    
SetPlayerVirtualWorld(playerid,0);
                }
            }
            else
            {
                
format(stringsizeof(string), "You are not registerid Type /register [password] to create an account!"playername);
                
SendClientMessage(playeridCOLOR_REDstring);
            }
        }
        return 
1;
    }
    if(
strcmp(cmd"/makemeadmin"true) == 0)
    {
        if(
IsPlayerAdmin(playerid))
        {
            if(
logged[playerid] == 1)
            {
                if(
adminlevel[playerid] != 3)
                {
                    
adminlevel[playerid] = 5;
                    
SendClientMessage(playeridCOLOR_GREEN"You are now maxlevel admin!");
                }
                else
                {
                    
SendClientMessage(playeridCOLOR_RED"You are already maxlevel admin!");
                }
            }
            else
            {
                
SendClientMessage(playeridCOLOR_RED"Please, first login: /login [password]");
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"You must first login with rcon! (/rcon login [rcon-pass])");
        }
        return 
1;
    }
    return 
0;

Mencent
Thanks for the script, Dude! now can you hep me with save player score? i want the system save player score too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)