SA-MP Forums Archive
[Include] [BETA] users.inc - Fast and EASY user system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] [BETA] users.inc - Fast and EASY user system (/showthread.php?tid=311773)



[BETA] users.inc - Fast and EASY user system - Slice - 18.01.2012

This is my 1000th post, so I figured I might as well make it interesting.

Just like bacon, this user system is awesome and easy to deal with! One of the main features of this is it will auto-magically load from and save data into variables!

Brief, fully-working example on what I mean:
pawn Код:
new g_LogInCount[MAX_PLAYERS];

public OnGameModeInit() {
    // This will make the variable automatically load and save for all players
    BindUserVar("login-count", g_LogInCount);
}

public OnPlayerLogIn(playerid) {
    // Increase by 1
    g_LogInCount[playerid] += 1;

    new buf[128];

    format(buf, sizeof(buf), "* Welcome! You have logged in %d time(s).", g_LogInCount[playerid]);

    SendClientMessage(playerid, 0xFFFFFFFF, buf);
}
You can use many different kinds of variables; supported structures: Example of how you do that:
pawn Код:
new
             g_Array[MAX_PLAYERS],
             g_CharArray[MAX_PLAYERS char],
    BitArray:g_y_bitArray<MAX_PLAYERS>,
       Bit16:g_rBitsArray<MAX_PLAYERS>,
             g_StringArray[MAX_PLAYERS][64],
             g_2dArray[MAX_PLAYERS][10]
;

public OnGameModeInit() {
    // The 1st argument is the name of the user var; it can be pretty much anything.
    BindUserVar("array"      , g_Array);
    BindUserVar("char-array" , g_CharArray);
    BindUserVar("bit-array"  , g_y_bitArray);
    BindUserVar("16bit-array", g_rBitsArray);
    BindUserVarString("string-array", g_StringArray);
    BindUserVarArray ("2d-array"    , g_2dArray);
}
That's right, there's nothing else you need to do! Those arrays would now be saved&loaded for each player, and new players will have them filled with 0.

Fully working example script
This script will save and load weapons, score, and playtime! It also has dialogs for log-in and registration.
Download: http://pastebin.com/LyXtkM7S

Functions
pawn Код:
// Self-explanatory
 bool:IsPlayerLoggedIn(playerid)
 bool:IsPlayerRegistered(playerid)

// Fires the callback OnPlayerLogIn or OnPlayerFailLogIn when done
      AuthPlayer(playerid, password[])

// Fires the callbacks OnPlayerRegister then OnPlayerLogIn when done
      RegisterPlayer(playerid, password[])

// This is called automatically when a player disconnects
// but you might want to save the data more often (in case of a crash).
      SavePlayerUserData(playerid)

//    BindUserVar*
      BindUserVar(key[], variable[])
      BindUserVarArray(key[], variable[MAX_PLAYERS][])
      BindUserVarString(key[], variable[MAX_PLAYERS][])

//    GetUserVar*
      GetUserVarArrayInt(playerid, key[], index)
Float:GetUserVarArrayFloat(playerid, key[], index)
      GetUserVarInt(playerid, key[])
Float:GetUserVarFloat(playerid, key[])
      GetUserVarString(playerid, key[], output[], output_size = sizeof(output))

//    SetUserVar*
      SetUserVar(playerid, key[], value)
      SetUserVarArray(playerid, key[], iIndex, {_, Float}:xValue)
      SetUserVarFloat(playerid, key[], Float:fValue)
      SetUserVarInt(playerid, key[], iValue)
      SetUserVarString(playerid, key[], /*const*/ szValue[])
Callbacks
pawn Код:
// This is called when a player's name info is loaded (almost right after OnPlayerConnect).
public OnPlayerNameInfoLoad(playerid, bool:is_registered, bool:is_logged_in)

// This is called when a player was successfully registered.
public OnPlayerRegister(playerid)

// This is called when a player logs in (also called after a player registers).
public OnPlayerLogIn(playerid)

// This is called when a player enters the wrong password.
public OnPlayerFailLogIn(playerid)

// This is called right before the user data will be saved.
public OnPlayerUserDataSave(playerid)
Download
Note: This include requires Whirlpool (get it here).

Do you understand that this is a beta and that it requires whirlpool? Yes / No.


Re: [BETA] users.inc - Fast and EASY user system - CyNiC - 18.01.2012

Quote:
Originally Posted by Slice
Посмотреть сообщение
This is my 1000th post, so I figured I might as well make it interesting.
There is a EPIC FAIL but also a good contribution for the community, great.


Re: [BETA] users.inc - Fast and EASY user system - iZN - 18.01.2012

Great work there Slice, as always. Two includes releases in same day


Re: [BETA] users.inc - Fast and EASY user system - Michael@Belgium - 18.01.2012

Quote:

This is my 1000th post, so I figured I might as well make it interesting.

Nah
Quote:

Posts: 999



And nice work Slice !


Re: [BETA] users.inc - Fast and EASY user system - Psymetrix - 18.01.2012

Lmao, leekspin xD

Nice include.


Re: [BETA] users.inc - Fast and EASY user system - TheArcher - 18.01.2012

What kind of saving is available?


Re: [BETA] users.inc - Fast and EASY user system - Slice - 18.01.2012

Quote:
Originally Posted by CyNiC
Посмотреть сообщение
There is a EPIC FAIL but also a good contribution for the community, great.
Oh, well I thought the 1st post in a topic would count as well. Apparently it doesn't.

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
What kind of saving is available?
Currently it saves into a SQLite database. I'm working on MySQL support.


Re: [BETA] users.inc - Fast and EASY user system - Konstantinos - 18.01.2012

Very nice Job Slice!
I like the total time a lot.
By the way, is important the hashed password be
pawn Код:
[ 128 ]
Because I use it with 129.


Re: [BETA] users.inc - Fast and EASY user system - Slice - 18.01.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Very nice Job Slice!
I like the total time a lot.
By the way, is important the hashed password be
pawn Код:
[ 128 ]
Because I use it with 129.
The passwords will get hashed with Whirlpool and stored as binary objects, causing them to only take up around 70 bytes.
So in short, no, you should give that function unhashed passwords.


Re: [BETA] users.inc - Fast and EASY user system - Konstantinos - 18.01.2012

Quote:
Originally Posted by Slice
Посмотреть сообщение
The passwords will get hashed with Whirlpool and stored as binary objects, causing them to only take up around 70 bytes.
So in short, no, you should give that function unhashed passwords.
Alright
Thanks for the information.