#include <a_samp>
#include <Bud>
#define DIALOG_LOGIN 1
#define DIALOG_REGISTER 2
#define COLOR_WHITE 0xFFFFFFAA
new
iMoney,
iKills,
iDeaths,
iAdmin,
iRespect
;
new pMoney[MAX_PLAYERS];
new pKills[MAX_PLAYERS];
new pDeaths[MAX_PLAYERS];
new pAdmin[MAX_PLAYERS];
new pRespect[MAX_PLAYERS];
main()
{
print("\n----------------------------------");
print("You Game Mode Name");
print("----------------------------------\n");
}
public OnGameModeInit()
{
BUD::Setting( opt.Database, "server.db" ); // The name of the database to create/use.
BUD::Setting( opt.Asynchronous, true ); // true - faster, but if your computer gets stuck by ligntning when it's doing something with the database it could end up corrupted! :D
BUD::Setting( opt.KeepAliveTime, 3000 ); // The database will be kept open for 3000ms each time it's being used; this is to save performance.
BUD::Setting( opt.CheckForUpdates, true ); // Check for BUD updates! This is set to true by default.
BUD::Initialize( ); // Initialize the system; this has to be called before using any functions besides BUD::Setting.
BUD::VerifyColumn( "Money", BUD::TYPE_NUMBER );
BUD::VerifyColumn( "Kills", BUD::TYPE_NUMBER ); // By using these functions, the script will make sure the columns exist if the database; if not, it create them.
BUD::VerifyColumn( "Deaths", BUD::TYPE_NUMBER );
BUD::VerifyColumn( "Admin", BUD::TYPE_NUMBER );
BUD::VerifyColumn( "Respect", BUD::TYPE_NUMBER );
AddPlayerClass(179,-357.3307,1727.1892,42.7340,145.5829,0,0,0,0,0,0);
// The last argument is the default value; it's optional. If no default value is specified, numbers will be set to 0, and strings empty.
return 1;
}
public OnGameModeExit()
{
BUD::Exit( );
return 1;
}
public OnPlayerConnect(playerid)
{
new name[24];
GetPlayerName(playerid, name, sizeof(name));
SetPVarInt(playerid, "Logged", 0);
if(BUD::IsNameRegistered( name) == true)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", " You are registered please login to continue", "Ok", "Cancel");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Login", " You are not registered\r\n Please type a password below", "Ok", "Cancel");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_LOGIN:
{
if(response) // Checks if the player selected "Ok"
{
new name[24], userid;//creates a variable to store the players name and unique userid.
GetPlayerName(playerid, name, sizeof(name)); //gets name
if(BUD::CheckAuth( name, inputtext) == false)// if the player enters a wrong password
{
SendClientMessage(playerid, COLOR_WHITE, " You have entered a wrong password!");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", " You are registered please login to continue", "Ok", "Cancel");
}
else
{
userid = BUD::GetNameUID(name);
BUD::MultiGet(userid, "iiiii", "Money", iMoney, "Kills", iKills,"Deaths", iDeaths,"Admin", iAdmin,"Respect", iRespect);
printf( " BUD::MultiGet returned:\n money: %d\n kills: %d\n deaths: %d\n res: %i",iMoney, iKills, iDeaths, iRespect );
GivePlayerMoney(playerid, iMoney);
SetPVarInt(playerid, "Logged", 1);
pMoney[playerid] = iMoney;
pKills[playerid] = iKills;
pDeaths[playerid] = iDeaths;
pAdmin[playerid] = iAdmin;
pRespect[playerid] = iRespect;
}
}
else return Kick(playerid); // Kick the player if he selected 'Cancel'
}
case DIALOG_REGISTER:
{
new name[24], userid;//creates a variable to store the players name and unique userid.
GetPlayerName(playerid, name, sizeof(name)); //gets name
if(response)//checks if the player selected "ok"
{
BUD::RegisterName( name, inputtext );//registers the user
userid = BUD::GetNameUID( name);
BUD::MultiSet( userid, "iiiii", // integer, integer, integer, integer, integer.
"Money", 5000, // gives the player who just registered 5000 dollars.
"Kills", 0,//sets the players kills to 0
"Deaths", 0,
"Admin", 0,
"Respect", 0
);
pMoney[playerid] = iMoney;
pKills[playerid] = iKills;
pDeaths[playerid] = iDeaths;
pAdmin[playerid] = iAdmin;
pRespect[playerid] = iRespect;
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(GetPVarInt(playerid, "Logged") == 1)
{
new name[24], userid;
GetPlayerName(playerid, name,sizeof(name));
userid = BUD::GetNameUID(name);
BUD::MultiSet(userid, "iiiii", "Money", GetPlayerMoney(playerid), "Kills", pKills[playerid],"Deaths", pDeaths[playerid],"Admin", pAdmin[playerid],"Respect", pRespect[playerid]);
}
return 1;
}
BUD::MultiSet( userid, "s[32]iiif", // string, integer, integer, integer, float
"CarName", "pCar",// saves the persons car name to a string to the database
"money"GetPlayerMoney(playerid),
"kills", pKills,
"deaths",pDeaths,
"exp", pExp,
);
BUD::Setting( setting[], value )
bool BUD::Initialize( )
bool BUD::Exit( )
BUD::VerifyColumn( column[], type[, default value ] )
bool BUD::IsNameRegistered( name[] )
bool BUD::RegisterName( name[], password[] )
BUD::UnregisterName( name[] )
bool BUD::CheckAuth( name[], password[] )
BUD::GetNameUID( name[] )
Float BUD::GetFloatEntry( uid, entry[] )
BUD::GetIntEntry( uid, entry[] )
BUD::GetStringEntry( uid, entry[], &value[][, size ] )
bool BUD::MultiGet( uid, type definitions, ( entry, &variable )... )
bool BUD::MultiSet( uid, type definitions, ( entry, value )... )
bool BUD::SetIntEntry( uid, entry[], value )
bool BUD::SetFloatEntry( uid, entry[], Float:value )
bool BUD::SetStringEntry( uid, entry[], value[][, size ] )
How about savings strings when player disconnects? Can you give us an example? Also, for floats, booleans too.
Anyway, not very well explained, but enough for a average scripter. Good work anyhow. |