17.02.2013, 08:44
(
Последний раз редактировалось Rock; 20.12.2013 в 15:47.
)
Part 2:
In this part we will learn how to:
- Verify if the player have an account on the server and if not, create one
- How to save score, money, rank, level and others
First we will beggin with player account.
Before we start you will need this stock inside your scrip:
If it is already in your script it's even better.
Now, we go to OnPlayerConnect and add this inside the brackets.
This function will verify if the new connected player has an account on your server and if not you can show a dialog for register and send a message to let him know.
(You will see an example at the end of the post)
Ok, now under !BUD::IsNameRegistered add this:
This is the opposite of function used above. (see that "else") which means if player has an account.
This is an example how it should look like right now:
IMPORTANT!
When you do the register code, you need to use this function, otherways account will not be registered.
Inside brackets of BUD::RegisterName add:
BUD::GetNameUID will get player unique ID which will be stored also in the database.(It's like playerid)
Under GetNameUID add:
Which will save the password inside the database.
ATTENTION: Use BUD::MultiSet ONLY in this function and to save player stats and no more elsewhere.
Ok, now that you've learned how to verify if a player has an account or not let's beggin with saving stats.
To beggin go to OnPlayerDisconnect and add again GetNameUID to get player unique id from the database.
(In the database unique id's are saved beggining with 1, 2, 3.., .., 101..)
Under that add:
This will save data on the column you created in the first part of this tutorial.
If you know how sscanf works you will know that "i" means integrer, "s" string, "f" float and I used "iis" because the first two things to save are integrers(Money and Score), the third one is a string and las is an integrer again.
ATTENTION: Name you used in MultiSet needs to be exactly the same name as your columns in your database.
In my case Money, Score, Rank and Level.
Wonder how to extract and set dates when player connects and login?
Go to OnDialogResponse and inside the login dialog add:
inputtext - Text which player will type in login dialog(DIALOG_STYLE_INPUT), in our case, password.
So this means it will compare the password from the database with password you or other player typed.
Now in the brackets of CheckAuth add:
Unique ID again and variables to store data from database.
Under that add:
MultiGet will extract data from the database and store into variables you created above.
I think you see above that I used lenght [20] in "s". In MultiGet it's needed to set string lenght.(like sscanf)
Now to set value to variables you use in your script under MultiGet simply add:
Or other variables you use, this is just an example.
Now if you follow all the steps from the beginning you are ready to create your own register/login system!
Here is an example of how it should look like
REMEMBER! It's just an example, you will get errors if you try to compile it.
In this part we will learn how to:
- Verify if the player have an account on the server and if not, create one
- How to save score, money, rank, level and others
First we will beggin with player account.
Before we start you will need this stock inside your scrip:
pawn Код:
stock GetName( playerid )
{
new _RocKzSk[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, _RocKzSk, sizeof _RocKzSk );
return ( _RocKzSk );
}
Now, we go to OnPlayerConnect and add this inside the brackets.
pawn Код:
if( !BUD::IsNameRegistered( GetName( playerid ) ) )
{
// Register code, dialogs, client messages, ..., ...
}
(You will see an example at the end of the post)
Ok, now under !BUD::IsNameRegistered add this:
pawn Код:
else
{
// login code
}
This is an example how it should look like right now:
pawn Код:
new _rK[ 128 ];
if( !BUD::IsNameRegistered( GetName( playerid ) ) )
{
format( _rK, sizeof( _rK ), "Welcome %s\nYou need an account to play on this server.", GetName( playerid ) );
ShowPlayerDialog( playerid, Register_D1, DIALOG_STYLE_MSGBOX, "New Account", _rK, "Register", "Kick" );
}
else
{
format( _rK, sizeof( _rK ), "Welcome %s\nThis account is already registered.\nLogin now.", GetName( playerid ) );
ShowPlayerDialog( playerid, Login_D1, DIALOG_STYLE_MSGBOX, "Login", _rK, "Login", "Kick" );
}
When you do the register code, you need to use this function, otherways account will not be registered.
pawn Код:
if ( BUD::RegisterName( GetName( playerid ), inputtext ) )
{
// Code..code..code
}
pawn Код:
new
iUID = BUD::GetNameUID( GetName( playerid ) )
;
Under GetNameUID add:
pawn Код:
BUD::MultiSet( iUID, "s", "Password", inputtext );
ATTENTION: Use BUD::MultiSet ONLY in this function and to save player stats and no more elsewhere.
Ok, now that you've learned how to verify if a player has an account or not let's beggin with saving stats.
To beggin go to OnPlayerDisconnect and add again GetNameUID to get player unique id from the database.
pawn Код:
new
iUID = BUD::GetNameUID( GetName( playerid ) )
;
Under that add:
pawn Код:
BUD::MultiSet( iUID, "iisi",
"Money", GetPlayerMoney( playerid ),
"Score", GetPlayerScore( playerid ),
"Rank", ROCK_PDATA[ playerid ][ rK_Rank ],
"Level", ROCK_PDATA[ playerid][ rK_Level]
);
If you know how sscanf works you will know that "i" means integrer, "s" string, "f" float and I used "iis" because the first two things to save are integrers(Money and Score), the third one is a string and las is an integrer again.
ATTENTION: Name you used in MultiSet needs to be exactly the same name as your columns in your database.
In my case Money, Score, Rank and Level.
Wonder how to extract and set dates when player connects and login?
Go to OnDialogResponse and inside the login dialog add:
pawn Код:
if( BUD::CheckAuth( GetName( playerid ), inputtext )
{
}
So this means it will compare the password from the database with password you or other player typed.
Now in the brackets of CheckAuth add:
pawn Код:
new
_Money, _Score, _Rank, _Level,
iUID = BUD::GetNameUID( GetName( playerid ) )
;
Under that add:
pawn Код:
BUD::MultiGet( iUID, "iis[20]i",
"Money", _Money,
"Score", _Score,
"Rank" , _Rank,
"Level", _Level
);
I think you see above that I used lenght [20] in "s". In MultiGet it's needed to set string lenght.(like sscanf)
Now to set value to variables you use in your script under MultiGet simply add:
pawn Код:
GivePlayerMoney( playerid, _Score );
SetPlayerScore( playerid, _Money );
ROCK_PDATA[ playerid ][ rK_Rank ] = _Rank;
ROCK_PDATA[ playerid ][ rK_Level ] = _Level;
Now if you follow all the steps from the beginning you are ready to create your own register/login system!
Here is an example of how it should look like
REMEMBER! It's just an example, you will get errors if you try to compile it.