04.08.2015, 21:14
Ok, My Names and password's won't save into the database but it will load them perfectly, Code for registering.
It works fine but when I log out and back in, it says the account doesn't exist.
Code:
forward OnPlayerRegister(playerid, password[]);
public OnPlayerRegister(playerid, password[])
{
new query[240];
if(IsPlayerConnected(playerid))
{
if(GetPVarInt(playerid, "AccountExist") == 0)
{
new hashpass[129];
WP_Hash(hashpass, sizeof(hashpass), password);
//mysql_format(handlesql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Pass`) VALUES ('%e', '%e')", PlayerInfo[playerid][pUsername], password);
format(query, sizeof(query), "INSERT INTO accounts (Name,Pass) VALUES ('%e', '%e')", PlayerInfo[playerid][pUsername], password);
mysql_function_query(handlesql, query, false, "SendQuery", "");
//==========//
SetPVarInt(playerid, "Cash", 500);
SetPVarInt(playerid, "Bank", 0);
SetPVarInt(playerid, "Model", 26);
SetPVarInt(playerid, "Interior", 0);
SetPVarInt(playerid, "World", 0);
SetPVarInt(playerid, "Tut", 0);
SetPVarInt(playerid, "Age", 14);
SetPVarInt(playerid, "Sex", 1);
SetPVarFloat(playerid, "PosX", 1642.7285);
SetPVarFloat(playerid, "PosY", -2240.5591);
SetPVarFloat(playerid, "PosZ", 13.4945);
SetPVarFloat(playerid, "Health", 50.0);
SetPVarFloat(playerid, "Armour", 0.0);
//==========//
SetPVarInt(playerid, "AccountExist", 1);
OnAccountLoad(playerid, 0);
}
else KickPlayer(playerid, "Unable to register, account exists!");
}
return 1;
}
public OnAccountLoad(playerid, type)
{
printf("OnAccountLoad is called [ID %i]", playerid);
// LOAD ACCOUNT DATA //
if(type == 0)
{
new query[256], emailv[64];
SetPVarInt(playerid, "Cash", cache_get_field_content_int(0, "Cash"));
SetPVarInt(playerid, "Bank", cache_get_field_content_int(0, "Bank"));
SetPVarInt(playerid, "Model", cache_get_field_content_int(0, "Model"));
SetPVarInt(playerid, "Interior", cache_get_field_content_int(0, "Interior"));
SetPVarInt(playerid, "World", cache_get_field_content_int(0, "World"));
SetPVarInt(playerid, "Tut", cache_get_field_content_int(0, "Tut"));
SetPVarInt(playerid, "Age", cache_get_field_content_int(0, "Age"));
SetPVarInt(playerid, "Sex", cache_get_field_content_int(0, "Sex"));
SetPVarFloat(playerid, "PosX", cache_get_field_content_float(0, "PosX"));
SetPVarFloat(playerid, "PosY", cache_get_field_content_float(0, "PosY"));
SetPVarFloat(playerid, "PosZ", cache_get_field_content_float(0, "PosZ"));
SetPVarFloat(playerid, "Health", cache_get_field_content_float(0, "Health"));
SetPVarFloat(playerid, "Armour", cache_get_field_content_float(0, "Armour"));
SetPVarInt(playerid, "Admin", cache_get_field_content_int(0, "Admin"));
SetPVarInt(playerid, "Helper", cache_get_field_content_int(0, "Helper"));
SetPVarInt(playerid, "Jailed", cache_get_field_content_int(0, "Jailed"));
SetPVarInt(playerid, "Jailtime", cache_get_field_content_int(0, "Jailtime"));
SetPVarInt(playerid, "ConnectTime", cache_get_field_content_int(0, "ConnectTime"));
SetPVarInt(playerid, "DriveLic", cache_get_field_content_int(0, "DriveLic"));
SetPVarInt(playerid, "GunLic", cache_get_field_content_int(0, "GunLic"));
SetPVarInt(playerid, "helpmes", cache_get_field_content_int(0, "helpme"));
SetPVarInt(playerid, "Member", cache_get_field_content_int(0, "Member"));
SetPVarInt(playerid, "Rank", cache_get_field_content_int(0, "Rank"));
SetPVarInt(playerid, "LockerRights", cache_get_field_content_int(0, "LockerRights"));
SetPVarInt(playerid, "JobReduce", cache_get_field_content_int(0, "JobReduce"));
SetPVarInt(playerid, "Job", cache_get_field_content_int(0, "JobID"));
SetPVarInt(playerid, "DonateRank", cache_get_field_content_int(0, "DonateRank"));
SetPVarInt(playerid, "Fightstyle", cache_get_field_content_int(0, "Fightstyle"));
SetPVarInt(playerid, "HouseKey", cache_get_field_content_int(0, "HouseKey"));
SetPVarInt(playerid, "BizKey", cache_get_field_content_int(0, "BizKey"));
SetPVarInt(playerid, "RentKey", cache_get_field_content_int(0, "RentKey"));
SetPVarInt(playerid, "WalkieFreq", cache_get_field_content_int(0, "WalkieFreq"));
SetPVarInt(playerid, "PhoneNum", cache_get_field_content_int(0, "PhoneNum"));
SetPVarInt(playerid, "PayDay", cache_get_field_content_int(0, "PayDay"));
SetPVarInt(playerid, "PayCheck", cache_get_field_content_int(0, "PayCheck"));
SetPVarInt(playerid, "CheckEarn", cache_get_field_content_int(0, "CheckEarn"));
SetPVarInt(playerid, "CarTicket", cache_get_field_content_int(0, "CarTicket"));
SetPVarInt(playerid, "Changes", cache_get_field_content_int(0, "Changes"));
SetPVarInt(playerid, "ChatStyle", cache_get_field_content_int(0, "ChatStyle"));
SetPVarInt(playerid, "MaskID", cache_get_field_content_int(0, "MaskID"));
SetPVarInt(playerid, "Dead", cache_get_field_content_int(0, "Dead"));
SetPVarInt(playerid, "PaidRent", cache_get_field_content_int(0, "PaidRent"));
SetPVarInt(playerid, "LicTime", cache_get_field_content_int(0, "LicTime"));
SetPVarInt(playerid, "LicGuns", cache_get_field_content_int(0, "LicGuns"));
SetPVarInt(playerid, "MonthDon", cache_get_field_content_int(0, "MonthDon"));
SetPVarInt(playerid, "MonthDonT", cache_get_field_content_int(0, "MonthDonT"));
SetPVarInt(playerid, "DrugTime", cache_get_field_content_int(0, "DrugTime"));
SetPVarInt(playerid, "DrugHigh", cache_get_field_content_int(0, "DrugHigh"));
SetPVarInt(playerid, "Addiction", cache_get_field_content_int(0, "Addiction"));
SetPVarInt(playerid, "AddictionID", cache_get_field_content_int(0, "AddictionID"));
SetPVarInt(playerid, "AutoReload", cache_get_field_content_int(0, "AutoReload"));
SetPVarInt(playerid, "AudioT", cache_get_field_content_int(0, "AudioT"));
SetPVarInt(playerid, "Frights", cache_get_field_content_int(0, "Frights"));
SetPVarInt(playerid, "HudCol", cache_get_field_content_int(0, "HudCol"));
SetPVarInt(playerid, "PrimHol", cache_get_field_content_int(0, "PrimHol"));
SetPVarInt(playerid, "SecHol", cache_get_field_content_int(0, "SecHol"));
SetPVarInt(playerid, "Bonus", cache_get_field_content_int(0, "Bonus"));
SetPVarInt(playerid, "SpawnLocation", cache_get_field_content_int(0, "SpawnLocation"));
SetPVarInt(playerid, "HouseEnter", cache_get_field_content_int(0, "HouseEnter"));
SetPVarInt(playerid, "BizEnter", cache_get_field_content_int(0, "BizEnter"));
SetPVarInt(playerid, "IntEnter", cache_get_field_content_int(0, "IntEnter"));
SetPVarInt(playerid, "GarageEnter", cache_get_field_content_int(0, "GarageEnter"));
SetPVarInt(playerid, "PaintUse", cache_get_field_content_int(0, "PaintUse"));
SetPVarInt(playerid, "WepSerial", cache_get_field_content_int(0, "WepSerial"));
SetPVarInt(playerid, "Wound_T", cache_get_field_content_int(0, "Wound_T"));
SetPVarInt(playerid, "Wound_A", cache_get_field_content_int(0, "Wound_A"));
SetPVarInt(playerid, "Wound_L", cache_get_field_content_int(0, "Wound_L"));
SetPVarInt(playerid, "Kills", cache_get_field_content_int(0, "Kills"));
SetPVarInt(playerid, "Deaths", cache_get_field_content_int(0, "Deaths"));
SetPVarInt(playerid, "UpgDelay", cache_get_field_content_int(0, "UpgDelay"));
SetPVarInt(playerid, "Forbid", cache_get_field_content_int(0, "Forbid"));
SetPVarInt(playerid, "Suspend", cache_get_field_content_int(0, "Suspend"));
SetPVarInt(playerid, "TogUnhol", cache_get_field_content_int(0, "TogUnhol"));
PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
PlayerInfo[playerid][pPlayerWeapon] = cache_get_field_content_int(0, "PlayerWeapon");
PlayerInfo[playerid][pPlayerAmmo] = cache_get_field_content_int(0, "PlayerAmmo");
PlayerInfo[playerid][pPlayerSerial] = cache_get_field_content_int(0, "PlayerSerial");
new fetch[128];
cache_get_field_content(0, "Describe1", fetch);
format(PlayerInfo[playerid][pDescribe], 128, "%s", fetch);
cache_get_field_content(0, "Describe2", fetch);
format(PlayerInfo[playerid][pDescribe2], 128, "%s", fetch);
cache_get_field_content(0, "email", fetch);
format(emailv, 128, "%s", fetch);
cache_get_field_content(0, "MarriedTo", fetch);
format(PlayerInfo[playerid][pMarriedTo], MAX_PLAYER_NAME + 1, "%s", fetch);
cache_get_field_content(0, "Accent", fetch);
format(PlayerInfo[playerid][pAccent], 64, "%s", fetch);
if(strlen(PlayerInfo[playerid][pMarriedTo]) == 0)
{
format(PlayerInfo[playerid][pMarriedTo], MAX_PLAYER_NAME + 1, "None");
}
if(strlen(PlayerInfo[playerid][pAccent]) == 0)
{
format(PlayerInfo[playerid][pAccent], 64, "None");
}
new string[32];
for(new i = 0; i < MAX_LSPD_DIVISIONS; i++)
{
new i2 = i + 1;
format(string, sizeof(string), "Division%d", i2);
PlayerInfo[playerid][pDivision][i] = cache_get_field_content_int(0, string);
}
// Load inventory
new InventoryFetch[1024],
InventoryItemID[MAX_INV_SLOTS][64],
InventoryItemQuantity[MAX_INV_SLOTS][64],
InventoryItemEx[MAX_INV_SLOTS][64],
InventoryItemSerial[MAX_INV_SLOTS][64];
cache_get_field_content(0, "InventoryItemID", InventoryFetch);
split(InventoryFetch, InventoryItemID, ',');
cache_get_field_content(0, "InventoryItemQuantity", InventoryFetch);
split(InventoryFetch, InventoryItemQuantity, ',');
cache_get_field_content(0, "InventoryItemEx", InventoryFetch);
split(InventoryFetch, InventoryItemEx, ',');
cache_get_field_content(0, "InventoryItemSerial", InventoryFetch);
split(InventoryFetch, InventoryItemSerial, ',');
for(new i = 0; i < MAX_INV_SLOTS; i++)
{
if(strval(InventoryItemID[i]) >= 1)
{
GiveInvItem(playerid, strval(InventoryItemID[i]), strval(InventoryItemQuantity[i]), strval(InventoryItemEx[i]), strval(InventoryItemSerial[i]));
}
}
// Player Contacts
new ContactFetch[1024];
new ContactNameSplit[MAX_PLAYER_CONTACTS][64];
new ContactNumberSplit[MAX_PLAYER_CONTACTS][64];
cache_get_field_content(0, "ContactNames", ContactFetch);
split(ContactFetch, ContactNameSplit, ',');
cache_get_field_content(0, "ContactNumbers", ContactFetch);
split(ContactFetch, ContactNumberSplit, ',');
for(new i = 0; i < MAX_PLAYER_CONTACTS; i++)
{
format(PlayerContacts[playerid][i][pContactName], 32, "%s", ContactNameSplit[i]);
format(PlayerContacts[playerid][i][pContactNumber], 32, "%s", ContactNumberSplit[i]);
}
// Achievement Loading
new arrCoords[MAX_ACHIEVEMENTS][64];
cache_get_field_content(0, "Achievements", fetch);
split(fetch, arrCoords, ',');
for(new i = 0; i < MAX_ACHIEVEMENTS; i++) {
PlayerInfo[playerid][pAch][i]=strval(arrCoords[i]); }
for(new i = 0; i < 20; i++)
{
TicketInfo[playerid][i][tAmount] = 0;
}
mysql_format(handlesql, query, sizeof(query), "SELECT * FROM `tickets` WHERE player='%e' AND paid=0", PlayerInfo[playerid][pUsername]);
mysql_pquery(handlesql, query, "LoadTickets", "d", playerid);
mysql_format(handlesql, query, sizeof(query), "SELECT ForumName FROM `mainaccounts` WHERE email='%e'", emailv);
mysql_pquery(handlesql, query, "OnAccountLoadMain", "d", playerid);
}
//==========//
if(GetPVarInt(playerid, "Tut") == 1 && GetPVarInt(playerid, "Model") == 0 && GetPVarInt(playerid, "Sex") == 0 && GetPVarInt(playerid, "Age") == 0) return KickPlayer(playerid, "You have to set your Age/Sex/Skin on the UCP before playing (www.pr-rp.com)");
SetPVarInt(playerid,"PlayerLogged", 2);
if(GetPVarInt(playerid, "Tut") == 0)
{
SetPVarInt(playerid, "Cash", 0);
SetPVarInt(playerid, "Bank", 0);
SetPVarInt(playerid, "Interior", 0);
SetPVarInt(playerid, "World", 0);
SetPVarInt(playerid, "Tut", 0);
SetPVarFloat(playerid, "PosX", -2022.255);
SetPVarFloat(playerid, "PosY", 1006.967);
SetPVarFloat(playerid, "PosZ", 1418.486);
SetPVarFloat(playerid, "Health", 50.0);
SetPVarFloat(playerid, "Armour", 0.0);
GiveInvItem(playerid, 405, 1, 1);
new randphone = 1000 + random(9999999);
SetPVarInt(playerid, "PhoneNum", randphone);
new randmask = 1 + random(999999);
SetPVarInt(playerid, "MaskID", randmask);
TogglePlayerControllable(playerid,0);
SetPlayerFacingAngle( playerid, 380.000); //Player faces camera
SelectTextDraw(playerid, 0xFF4040AA);
SetPVarInt(playerid, "Age", 16);
SetPVarInt(playerid, "Sex", 1);
SendClientMessage(playerid, COLOR_WHITE, "Welcome to Last Chance Roleplay!");
SendClientMessage(playerid, COLOR_WHITE, "Remember to use /help to find out more about the command available to you.");
//CallRemoteFunction("GivePlayerMoneyEx","ii", playerid, 300);
GivePlayerMoneyEx(playerid, 300);
ShowRegisterMenu(playerid);
}
CallRemoteFunction("OnLoginInit", "ii", playerid, 1);
SetSlidedMoneyBar(playerid);
CheckIfBanned(playerid);
return 1;
}


