Y_ini register system
#1

i made a register system from a tutorial but it wasnt as i want cause it only saves stats when player leaves and register any player who joins. The one i want is made by a /register cmd and players can register if they want , anybody have a tutorial for that ?

Thank you
Reply
#2

I remember a cool feature I heard of all over the forums called the search button it's a magician that can find any tutorial you need, you should use it, IT'S FREE!
Reply
#3

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
I remember a cool feature I heard of all over the forums called the search button it's a magician that can find any tutorial you need, you should use it, IT'S FREE!
do you think i'd even bother to post if i found it ? i didnt find the type i need which is registering with a /register [password] command
Reply
#4

Quote:
Originally Posted by YoussefHammad
Посмотреть сообщение
do you think i'd even bother to post if i found it ? i didnt find the type i need which is registering with a /register [password] command
There are plenty of tutorials that are covering the exact thing you want and there are plenty of filterscripts, if you have already searched it means you haven't searched hard enough. look at the Useful Tutorials thread and do a little bit more research.
Reply
#5

Poof, magic!

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <YSI\y_ini>

// NATIVES:

// WHIRLPOOL:

native WP_Hash(buffer[], len, const str[]);

// DEFINES:

// FUNCTIONS:

#define function%0(%1) forward%0(%1); public%0(%1)

// DATABASE:

#define USER_TAG "player_data"
#define USER_PASSWORD "password"
#define USER_SCORE "score"
#define USER_CASH "cash"
#define USER_KILLS "kills"
#define USER_DEATHS "deaths"
#define USER_VIP_LEVEL "vip_level"
#define USER_ADMIN_LEVEL "admin_level"

// ARRAYS AND ENUMERATORS:

enum eUserInfo
{
    user_password[129],
    user_score,
    user_cash,
    user_kills,
    user_deaths,
    user_vip_level,
    user_admin_level
}

new aUserInfo[MAX_PLAYERS][eUserInfo];

// VARIABLES:

// STATES:

new bool:sSignedIn[MAX_PLAYERS] = false;

// MAIN:

main()
{
    print("Development Mode: cmd_ini_login_system.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(IsPlayerSignedIn(playerid))
    {
        new INI:file = INI_Open(UserPath(playerid));
        INI_SetTag(file, USER_TAG);
        INI_WriteInt(file, USER_SCORE, GetPlayerScore(playerid));
        INI_WriteInt(file, USER_CASH, GetPlayerMoney(playerid));
        INI_WriteInt(file, USER_KILLS, aUserInfo[playerid][user_kills]);
        INI_WriteInt(file, USER_DEATHS, aUserInfo[playerid][user_deaths]);
        INI_WriteInt(file, USER_VIP_LEVEL, aUserInfo[playerid][user_vip_level]);
        INI_WriteInt(file, USER_ADMIN_LEVEL, aUserInfo[playerid][user_admin_level]);
        INI_Close(file);
    }

    ResetPlayerVariables(playerid);
    return 1;
}

// COMMANDS:

CMD:register(playerid, params[])
{
    if(IsPlayerSignedIn(playerid)) return SendClientMessage(playerid, -1, "You are already registered and logged in.");
    if(fexist(UserPath(playerid))) return SendClientMessage(playerid, -1, "This account is already registered, please log in instead.");

    new password[128];
    if(sscanf(params, "s[128]", password)) return SendClientMessage(playerid, -1, "Usage: /register (password).");

    new hash[129];
    WP_Hash(hash, sizeof(hash), password);

    new INI:file = INI_Open(UserPath(playerid));
    INI_SetTag(file, USER_TAG);
    INI_WriteString(file, USER_PASSWORD, hash);
    INI_WriteInt(file, USER_SCORE, 0);
    INI_WriteInt(file, USER_CASH, 0);
    INI_WriteInt(file, USER_KILLS, 0);
    INI_WriteInt(file, USER_DEATHS, 0);
    INI_WriteInt(file, USER_VIP_LEVEL, 0);
    INI_WriteInt(file, USER_ADMIN_LEVEL, 0);
    INI_Close(file);

    sSignedIn[playerid] = true;

    SendClientMessage(playerid, -1, "You have successfully registered an account.");
    return 1;
}

CMD:login(playerid, params[])
{
    if(IsPlayerSignedIn(playerid)) return SendClientMessage(playerid, -1, "You are already registered and logged in.");
    if(!fexist(UserPath(playerid))) return SendClientMessage(playerid, -1, "This account doesn't exist, please register it first.");

    new password[128];
    if(sscanf(params, "s[128]", password)) return SendClientMessage(playerid, -1, "Usage: /login (password).");

    new hash[129];
    WP_Hash(hash, sizeof(hash), password);

    INI_ParseFile(UserPath(playerid), "LoadUserData", .bExtra = true, .extra = playerid);
   
    if(strcmp(aUserInfo[playerid][user_password], hash, false) == 0)
    {
        INI_ParseFile(UserPath(playerid), "LoadUserData", .bExtra = true, .extra = playerid);
        SetPlayerScore(playerid, aUserInfo[playerid][user_score]);
        GivePlayerMoney(playerid, aUserInfo[playerid][user_cash]);

        sSignedIn[playerid] = true;

        SendClientMessage(playerid, -1, "You have successfully logged into your account.");
    }
    else SendClientMessage(playerid, -1, "Oops, you have entered an incorrect password.");
    return 1;
}

// FUNCTIONS:

stock ResetPlayerVariables(playerid)
{
    // ARRAYS AND ENUMERATORS:

    aUserInfo[playerid][user_password] = EOS;
    aUserInfo[playerid][user_score] = 0;
    aUserInfo[playerid][user_cash] = 0;
    aUserInfo[playerid][user_kills] = 0;
    aUserInfo[playerid][user_deaths] = 0;
    aUserInfo[playerid][user_vip_level] = 0;
    aUserInfo[playerid][user_admin_level] = 0;

    // PER-PLAYER VARIABLES:

    // STATES:

    sSignedIn[playerid] = false;
    return 1;
}

function LoadUserData(playerid, name[], value[])
{
    INI_String(USER_PASSWORD, aUserInfo[playerid][user_password], 129);
    INI_Int(USER_SCORE, aUserInfo[playerid][user_score]);
    INI_Int(USER_CASH, aUserInfo[playerid][user_cash]);
    INI_Int(USER_KILLS, aUserInfo[playerid][user_kills]);
    INI_Int(USER_DEATHS, aUserInfo[playerid][user_deaths]);
    INI_Int(USER_VIP_LEVEL, aUserInfo[playerid][user_vip_level]);
    INI_Int(USER_ADMIN_LEVEL, aUserInfo[playerid][user_admin_level]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "/Users/%s.ini", name);
    return string;
}

function bool:IsPlayerSignedIn(playerid) return sSignedIn[playerid];
Reply
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Poof, magic!

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <YSI\y_ini>

// NATIVES:

// WHIRLPOOL:

native WP_Hash(buffer[], len, const str[]);

// DEFINES:

// FUNCTIONS:

#define function%0(%1) forward%0(%1); public%0(%1)

// DATABASE:

#define USER_TAG "player_data"
#define USER_PASSWORD "password"
#define USER_SCORE "score"
#define USER_CASH "cash"
#define USER_KILLS "kills"
#define USER_DEATHS "deaths"
#define USER_VIP_LEVEL "vip_level"
#define USER_ADMIN_LEVEL "admin_level"

// ARRAYS AND ENUMERATORS:

enum eUserInfo
{
    user_password[129],
    user_score,
    user_cash,
    user_kills,
    user_deaths,
    user_vip_level,
    user_admin_level
}

new aUserInfo[MAX_PLAYERS][eUserInfo];

// VARIABLES:

// STATES:

new bool:sSignedIn[MAX_PLAYERS] = false;

// MAIN:

main()
{
    print("Development Mode: cmd_ini_login_system.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(IsPlayerSignedIn(playerid))
    {
        new INI:file = INI_Open(UserPath(playerid));
        INI_SetTag(file, USER_TAG);
        INI_WriteInt(file, USER_SCORE, GetPlayerScore(playerid));
        INI_WriteInt(file, USER_CASH, GetPlayerMoney(playerid));
        INI_WriteInt(file, USER_KILLS, aUserInfo[playerid][user_kills]);
        INI_WriteInt(file, USER_DEATHS, aUserInfo[playerid][user_deaths]);
        INI_WriteInt(file, USER_VIP_LEVEL, aUserInfo[playerid][user_vip_level]);
        INI_WriteInt(file, USER_ADMIN_LEVEL, aUserInfo[playerid][user_admin_level]);
        INI_Close(file);
    }

    ResetPlayerVariables(playerid);
    return 1;
}

// COMMANDS:

CMD:register(playerid, params[])
{
    if(IsPlayerSignedIn(playerid)) return SendClientMessage(playerid, -1, "You are already registered and logged in.");
    if(fexist(UserPath(playerid))) return SendClientMessage(playerid, -1, "This account is already registered, please log in instead.");

    new password[128];
    if(sscanf(params, "s[128]", password)) return SendClientMessage(playerid, -1, "Usage: /register (password).");

    new hash[129];
    WP_Hash(hash, sizeof(hash), password);

    new INI:file = INI_Open(UserPath(playerid));
    INI_SetTag(file, USER_TAG);
    INI_WriteString(file, USER_PASSWORD, hash);
    INI_WriteInt(file, USER_SCORE, 0);
    INI_WriteInt(file, USER_CASH, 0);
    INI_WriteInt(file, USER_KILLS, 0);
    INI_WriteInt(file, USER_DEATHS, 0);
    INI_WriteInt(file, USER_VIP_LEVEL, 0);
    INI_WriteInt(file, USER_ADMIN_LEVEL, 0);
    INI_Close(file);

    sSignedIn[playerid] = true;

    SendClientMessage(playerid, -1, "You have successfully registered an account.");
    return 1;
}

CMD:login(playerid, params[])
{
    if(IsPlayerSignedIn(playerid)) return SendClientMessage(playerid, -1, "You are already registered and logged in.");
    if(!fexist(UserPath(playerid))) return SendClientMessage(playerid, -1, "This account doesn't exist, please register it first.");

    new password[128];
    if(sscanf(params, "s[128]", password)) return SendClientMessage(playerid, -1, "Usage: /login (password).");

    new hash[129];
    WP_Hash(hash, sizeof(hash), password);

    INI_ParseFile(UserPath(playerid), "LoadUserData", .bExtra = true, .extra = playerid);
   
    if(strcmp(aUserInfo[playerid][user_password], hash, false) == 0)
    {
        INI_ParseFile(UserPath(playerid), "LoadUserData", .bExtra = true, .extra = playerid);
        SetPlayerScore(playerid, aUserInfo[playerid][user_score]);
        GivePlayerMoney(playerid, aUserInfo[playerid][user_cash]);

        sSignedIn[playerid] = true;

        SendClientMessage(playerid, -1, "You have successfully logged into your account.");
    }
    else SendClientMessage(playerid, -1, "Oops, you have entered an incorrect password.");
    return 1;
}

// FUNCTIONS:

stock ResetPlayerVariables(playerid)
{
    // ARRAYS AND ENUMERATORS:

    aUserInfo[playerid][user_password] = EOS;
    aUserInfo[playerid][user_score] = 0;
    aUserInfo[playerid][user_cash] = 0;
    aUserInfo[playerid][user_kills] = 0;
    aUserInfo[playerid][user_deaths] = 0;
    aUserInfo[playerid][user_vip_level] = 0;
    aUserInfo[playerid][user_admin_level] = 0;

    // PER-PLAYER VARIABLES:

    // STATES:

    sSignedIn[playerid] = false;
    return 1;
}

function LoadUserData(playerid, name[], value[])
{
    INI_String(USER_PASSWORD, aUserInfo[playerid][user_password], 129);
    INI_Int(USER_SCORE, aUserInfo[playerid][user_score]);
    INI_Int(USER_CASH, aUserInfo[playerid][user_cash]);
    INI_Int(USER_KILLS, aUserInfo[playerid][user_kills]);
    INI_Int(USER_DEATHS, aUserInfo[playerid][user_deaths]);
    INI_Int(USER_VIP_LEVEL, aUserInfo[playerid][user_vip_level]);
    INI_Int(USER_ADMIN_LEVEL, aUserInfo[playerid][user_admin_level]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "/Users/%s.ini", name);
    return string;
}

function bool:IsPlayerSignedIn(playerid) return sSignedIn[playerid];
thanks thats what i wanted but ........ can u make that instead of /login , it checks if player account exists or no and if exists it shows a dialog in OnPlayerConnect telling him to write the pass ?
Reply
#7

Quote:
Originally Posted by YoussefHammad
Посмотреть сообщение
thanks thats what i wanted but ........ can u make that instead of /login , it checks if player account exists or no and if exists it shows a dialog in OnPlayerConnect telling him to write the pass ?
Nope.

Reply
#8

alright thanks anyway . Repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)