PDA

View Full Version : Mysql creating tables


MadafakaPro
21/03/2013, 07:43 PM
Hello,
This is my first time as i create tables and use mysql , i made this but have some errors
http://i.imgur.com/GJPrsyi.jpg
and i get this error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(11) NOT NULL, `pLastOn` TIMESTAMP(11) NOT NULL, `pHealth` FLOAT(11) NOT NULL, `' at line 1

Jstylezzz
21/03/2013, 07:49 PM
You get this on the phpmyadmin page or on the Debug.txt file?
If it's on the Debug.txt file, post the code.

MadafakaPro
21/03/2013, 07:51 PM
Its on the phpmyadmin page

LarzI
21/03/2013, 07:51 PM
The floats don't need values, AFAIK.. I'm really no expert with SQL but try removing the values from all the Floats. Same with timestamps - I really don't think they need length/values, so if the problem still occurs, try removing the values from them too.

Disclaimer: I have just started to (try) using MySQL to store user data myself, so I have really no idea what causes this error

MadafakaPro
21/03/2013, 08:09 PM
That worked, thnaks larzi.
I made this but its still not showing the dialogs

new rows = mysql_num_rows(); //We get how many rows the query returned.
if(!rows)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE"Account Registration", ""#COL_EMB_WHITE"This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE"!\n\nEnter your desired password below to register this account.", "Submit", "Leave");
}
if(rows == 1)
{
ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", ""#COL_EMB_WHITE"This account has "#COL_EMB_GREEN"been registered"#COL_EMB_WHITE"!\n\nEnter the account password below to proceed.", "Submit", "Leave");
}

LarzI
21/03/2013, 08:11 PM
That worked, thnaks larzi.

Like I suspected - no problem.

I made this but its still not showing the dialogs

new rows = mysql_num_rows(); //We get how many rows the query returned.
if(!rows)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE"Account Registration", ""#COL_EMB_WHITE"This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE"!\n\nEnter your desired password below to register this account.", "Submit", "Leave");
}
if(rows == 1)
{
ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", ""#COL_EMB_WHITE"This account has "#COL_EMB_GREEN"been registered"#COL_EMB_WHITE"!\n\nEnter the account password below to proceed.", "Submit", "Leave");
}

Where'd you put that? Inside OnQueryFinish? (presuming you're using R6)

MadafakaPro
21/03/2013, 08:12 PM
I am using R7 and i added this on OnPlayerConnect

LarzI
21/03/2013, 08:21 PM
If you're already using threaded queries (which is the only type R7 supports) I recommend updating to R15 as it adds a couple of extra features and fixed some bugs.

/rant

Now ontopic: You're using mysql_num_rows inside OnPlayerConnect. mysql_num_rows retrieves the number of rows from a result set after sending a SELECT or SHOW query. You'll need to send a SELECT query to check for the player in the table, then in the callback (which you specify) you can use cache_get_data to retrieve the data and check for rows.

http://forum.sa-mp.com/showthread.php?t=390428 Here's an example gamemode using this method. I recommend reading it - it helped me a lot!

Summary:

Send a SELECT query in OnPlayerConnect:

new
szQuery[ 90 ]
;
format( szQuery, sizeof( szQuery ), "SELECT * from `your_table_here` WHERE `name` = '%s' LIMIT 1", Name( playerid ));
mysql_function_query( handle, szQuery, true, "OnUserCheck", "i", playerid );

Check rows in the specified callback (OnUserCheck):

forward OnUserCheck(playerid);
public OnUserCheck(playerid)
{
new
rows,
fields
;
cache_get_data( rows, fields, handle );
if( rows )
{
// exists - player should log in
}
else
{
// doesn't exist - player should register
}
return true;
}

And that's about it. Keep in mind that this is just a very very rough example.

You should read this tutorial: http://forum.sa-mp.com/showthread.php?t=337810 on using cache in R7 and newer

Scenario
21/03/2013, 08:31 PM
I love when people pull lines from my released GM's and say: "I made this, but..."

Why are you modifying the code from my GM? It worked perfectly where it was...

MadafakaPro
21/03/2013, 08:36 PM
@RealCop228 Its not working i tryed to enter IG a\but the dialog didnt show up
And i didnt sayd i made the script i sayd i made the tables...

@Larzi
I didnt tryed that i will try tommorow and tell u if it works.. Thanks anyways.

And here is what i did..
: http://pastebin.com/EXjcKdjs

Scenario
21/03/2013, 09:09 PM
Oh, you didn't claim you made it? Hm...

I made this but its still not showing the dialogs

The code worked perfectly fine, actually. It just didn't come with a .sql file, hence why you had to make the MySQL table yourself! The mode had an inbuilt temporary banning system. It checks that table before checking if the account exists. If the account exists, it will display the authentication dialog. If the account doesn't exist, it will walk you through the registration process.

It worked fine.

EDIT: See if this version works better for you...

// BoF - Beginning of File

#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <foreach>
#include <zcmd>
#include <YSI\y_timers>
#include <streamer>

native WP_Hash(buffer[], len, const str[]); // Whirlpool is not an include, it is a plugin. This is all we need in order to use it in the script!

#define COLOR_RED 0xE7000000
#define COLOR_GREEN 0x80FF00B9
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_ORANGE 0xFF800000
#define COLOR_YELLOW 0xFFFF09C8
#define COLOR_LIGHTBLUE 0x379BFFC8
#define COLOR_LIGHTRED 0xFF6464C8
#define COLOR_GREY 0xC0C0C0C8

#define COLOR_DGREY1 0xE6E6E6E6
#define COLOR_DGREY2 0xC8C8C8C8
#define COLOR_DGREY3 0xAAAAAAAA
#define COLOR_DGREY4 0x8C8C8C8C
#define COLOR_DGREY5 0x6E6E6E6E

#define COL_EMB_RED "{E70000}"
#define COL_EMB_GREEN "{80FF00}"
#define COL_EMB_WHITE "{FFFFFF}"
#define COL_EMB_ORANGE "{FF8000}"
#define COL_EMB_YELLOW "{FFFF09}"
#define COL_EMB_LIGHTBLUE "{379BFF}"
#define COL_EMB_LIGHTRED "{FF6464}"
#define COL_EMB_GREY "{C0C0C0}"

new
g_szFormatString[128]; // this global string is necessary for the defines below

#define fSendClientMessage(%1,%2,%3) \
SendClientMessage(%1, %2, (format(g_szFormatString, sizeof(g_szFormatString), %3), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now

#define fSendClientMessageToAll(%1,%2) \
sendGlobalMessage(%1, (format(g_szFormatString, sizeof(g_szFormatString), %2), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now

#define fSendAdminMessage(%1,%2) \
sendAdminMessage(%1, (format(g_szFormatString, sizeof(g_szFormatString), %2), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now

#define fSendAreaMessage(%1,%2,%3,%4,%5,%6,%7) \
sendAreaMessage(%1, %2, %3, %4, %5, %6, (format(g_szFormatString, sizeof(g_szFormatString), %7), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now

// -------------------- Server Definitions -------------------- //

#define SCRIPT_VERSION "rev. 0.0.1"

#define DEFAULT_CASH 1000 // set this to the amount of money player's should start with
#define DEFAULT_LEVEL 1 // set this to the score/level player's should start with


#define SQL_DEBUG 1 // enable MySQL debugging by keeping this as "1"; otherwise, use "0"
#define connectionHandle 1 // change this only if you absolutely have to

#define SQL_HOST ""
#define SQL_USER ""
#define SQL_DATA ""
#define SQL_PASS ""

// ------------------------------------------------------------ //

enum // this is easier than handling a bunch of "#define" lines; you can just put a new line in the enum to make a new dialog definition
{
DIALOG_REGISTER,
DIALOG_SETGENDER,
DIALOG_SETAGE,
DIALOG_AUTHENTICATION
}

enum PLAYER_VARIABLES
{
pDataID, // we use database ID's (data ID) as it's easier to handle than a username and provides easy table linking
pPassword[129], // passwords are hashed, the hash is 128 + 1 for the null terminator, equaling 129
pAdmin,
pCash,
pSavings,
pBankAccount,
pLevel,
pKills,
pDeaths,
pRegTime, // registration time/date; saved as a timestamp
pLastOn, // last time/date online; saved as a timestamp
Float:pHealth,
Float:pArmour,
Float:pLastX, // on the last disconnect, this was the X position of the player
Float:pLastY, // on the last disconnect, this was the Y position of the player
Float:pLastZ, // on the last disconnect, this was the Z position of the player
pSkin,
pGender[7],
pAge
};

new pInfo[MAX_PLAYERS][PLAYER_VARIABLES]; // this allows usage of the "pInfo" variable with the "PLAYER_VARIABLES" enumerator

// -------------------- Global Player Variables -------------------- //

new // begins global bool vars
bool:tAuthenticated[MAX_PLAYERS] = false
;

new // begins numerical global vars
iLoginAttempts[MAX_PLAYERS] = 0
;

// ----------------------------------------------------------------- //

main(){}

public OnGameModeInit()
{
mysql_debug(SQL_DEBUG);
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);

SetGameModeText(SCRIPT_VERSION);
return 1;
}

public OnGameModeExit()
{
mysql_close();
return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
return 1;
}

public OnPlayerConnect(playerid)
{
if(!IsRolePlayName(playerid))
{
SendClientMessage(playerid, COLOR_WHITE, "Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
Kick(playerid);
}

TogglePlayerSpectating(playerid, true);

new szQuery[500];
format(szQuery, sizeof(szQuery), "SELECT * FROM `Bans` WHERE `Username` = '%s'", getEscName(playerid));
mysql_function_query(connectionHandle, szQuery, true, "thread_checkBans", "d", playerid);
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
saveVariables(playerid);

new
Float:fPos[3]
;

GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
foreach(new i : Player)
if(IsPlayerInRangeOfPoint(i, 7.0, fPos[0], fPos[1], fPos[2])) fSendClientMessage(i, COLOR_YELLOW, "* %s has disconnected from the server.", getName(playerid));

return 1;
}

public OnPlayerSpawn(playerid)
{
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}

public OnVehicleSpawn(vehicleid)
{
return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}

public OnPlayerText(playerid, text[])
{
if(strlen(text) > 2)
fSendAreaMessage(playerid, COLOR_DGREY1, COLOR_DGREY1, COLOR_DGREY2, COLOR_DGREY3, COLOR_DGREY4, "%s says: %s", getRolePlayName(playerid), text);

return 0;
}

CMD:setadmin(playerid, params[])
{
new
iID,
iLevel
;

if(pInfo[playerid][pAdmin] < 5)
return 1;
if(sscanf(params, "ud", iID, iLevel))
return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /setadmin [nick/id] [level]"), 1;
if(iID == INVALID_PLAYER_ID)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid nickname/ID specified!"), 1;
if(iLevel > 5)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid level specified!"), 1;

pInfo[iID][pAdmin] = iLevel;

fSendClientMessage(playerid, COLOR_WHITE, "You have set %s(%d)'s admin level to: %d", getName(iID), iID, iLevel);
fSendClientMessage(iID, COLOR_GREEN, "ADMIN: %s(%d) has set your admin level to: %d", getName(playerid), playerid, iLevel);
return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}

public OnPlayerEnterDynamicCP(playerid)
{
return 1;
}

public OnPlayerLeaveDynamicCP(playerid)
{
return 1;
}

public OnPlayerEnterDynamicRaceCP(playerid)
{
return 1;
}

public OnPlayerLeaveDynamicRaceCP(playerid)
{
return 1;
}

public OnRconCommand(cmd[])
{
return 1;
}

public OnPlayerRequestSpawn(playerid)
{
return 1;
}

public OnObjectMoved(objectid)
{
return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}

public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}

public OnPlayerExitedMenu(playerid)
{
return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}

public OnPlayerUpdate(playerid)
{
return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(!response || isnull(inputtext))
return clearPlayerChat(playerid), Kick(playerid);
if(strlen(inputtext) < 4 || strlen(inputtext) > 50)
return SendClientMessage(playerid, COLOR_RED, "ERROR: Your password cannot be shorter than 4 characters, or more than 50 characters."), SPD(playerid, DIALOG_REGISTER);

new
szBuffer[129];

WP_Hash(szBuffer, sizeof(szBuffer), inputtext);
pInfo[playerid][pPassword] = szBuffer;

SendClientMessage(playerid, COLOR_WHITE, "Okay, now let's set up your character.");
SPD(playerid, DIALOG_SETGENDER);
}
case DIALOG_SETGENDER:
{
if(!response)
{
format(pInfo[playerid][pGender], 7, "female");
SendClientMessage(playerid, COLOR_WHITE, "You have selected female.");
}
else
{
format(pInfo[playerid][pGender], 7, "male");
SendClientMessage(playerid, COLOR_WHITE, "You have selected male.");
}

SPD(playerid, DIALOG_SETAGE);
}
case DIALOG_SETAGE:
{
if(!response)
{
clearPlayerChat(playerid);
SendClientMessage(playerid, COLOR_RED, "You failed to complete the registration process. Goodbye.");
Kick(playerid);
}

new iTemp = strval(inputtext);
if(iTemp < 10 || iTemp > 80)
return SendClientMessage(playerid, COLOR_RED, "Character ages cannot be less than 10, or greater than 80."), SPD(playerid, DIALOG_SETAGE);

pInfo[playerid][pAge] = iTemp;

new
szQuery[300];

format(szQuery, sizeof(szQuery), "INSERT INTO `Accounts` (`Username`, `Password`, `Level`, `Cash`, `RegTime`, `Gender`, `Age`) VALUES('%s', '%s', %d, %d, %d, '%s', %d)", getEscName(playerid), pInfo[playerid][pPassword], DEFAULT_LEVEL, DEFAULT_CASH, gettime(), pInfo[playerid][pGender], pInfo[playerid][pAge]);
mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");

clearPlayerChat(playerid);
fSendClientMessage(playerid, COLOR_WHITE, "You have set your character's age to %d.", iTemp);
SendClientMessage(playerid, -1, "");
SendClientMessage(playerid, COLOR_WHITE, "You have completed the registration process! You will spawn momentarily...");
TogglePlayerSpectating(playerid, false);
tAuthenticated[playerid] = true;

SetSpawnInfo(playerid, -1, 120, 131.5488, -69.1912, 1.5781, 0.0, 0, 0, 0, 0, 0, 0); // change 131.5488, -69.1912, 1.5781 to your desired spawn point X Y Z coordinates
SpawnPlayer(playerid);

pInfo[playerid][pCash] = DEFAULT_CASH;
pInfo[playerid][pLevel] = DEFAULT_LEVEL;

real_GivePlayerCash(playerid, DEFAULT_CASH);
SetPlayerScore(playerid, pInfo[playerid][pLevel]);
}
case DIALOG_AUTHENTICATION:
{
if(!response || isnull(inputtext))
return clearPlayerChat(playerid), Kick(playerid);

new
szBuffer[129];

WP_Hash(szBuffer, sizeof(szBuffer), inputtext);
if(!strcmp(szBuffer, pInfo[playerid][pPassword], false))
{
clearPlayerChat(playerid);
fSendClientMessage(playerid, COLOR_WHITE, "Welcome back, "#COL_EMB_LIGHTBLUE"%s"#COL_EMB_WHITE"! Last online: "#COL_EMB_ORANGE"%s", getRolePlayName(playerid), date(pInfo[playerid][pLastOn], 2));
TogglePlayerSpectating(playerid, false);
tAuthenticated[playerid] = true;

SetSpawnInfo(playerid, -1, pInfo[playerid][pSkin], pInfo[playerid][pLastX], pInfo[playerid][pLastY], pInfo[playerid][pLastZ], 0.0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
}
else
{
iLoginAttempts[playerid]++;
if(iLoginAttempts[playerid] > 3)
{
iLoginAttempts[playerid] = 0;

clearPlayerChat(playerid);
SendClientMessage(playerid, COLOR_RED, "You have failed to provide the password three times. Goodbye!");
Kick(playerid);
}
else SendClientMessage(playerid, COLOR_RED, "Incorrect password! Please try again..."), SPD(playerid, DIALOG_AUTHENTICATION);
}
}
}
return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}

// ----- Threaded Callbacks [go below this line] ----- //

forward thread_checkBans(playerid);
public thread_checkBans(playerid)
{
new
szUsername[MAX_PLAYER_NAME],
szAdminName[MAX_PLAYER_NAME],
szReason[60],
temp[30];

cache_get_row(0, 0, temp);
new iBanID = strval(temp);
cache_get_row(0, 1, szUsername);
cache_get_row(0, 2, szAdminName);
cache_get_row(0, 3, szReason);
cache_get_row(0, 4, temp);
new iBannedTimestamp = strval(temp);
cache_get_row(0, 5, temp);
new iUnbannedTimestamp = strval(temp);
cache_get_row(0, 6, temp);
new iPerm = strval(temp);

if(gettime() >= iUnbannedTimestamp)
{
new szQuery[128];
format(szQuery, sizeof(szQuery), "DELETE FROM `Bans` WHERE `banID` = %d", iBanID);
mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");

format(szQuery, sizeof(szQuery), "SELECT * FROM `Accounts` WHERE `Username` = '%s'", getEscName(playerid));
mysql_function_query(connectionHandle, szQuery, true, "thread_loadVariables", "d", playerid);
}
else
{
clearPlayerChat(playerid);

SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
SendClientMessage(playerid, -1, " ");
fSendClientMessage(playerid, COLOR_WHITE, "You were banned by {E70000}%s {FFFFFF}on %s.", szAdminName, date(iBannedTimestamp, 2));
fSendClientMessage(playerid, COLOR_WHITE, "Reason: %s", szReason);
SendClientMessage(playerid, -1, " ");
if(iPerm == 0) fSendClientMessage(playerid, COLOR_WHITE, "You will be automatically unbanned on %s.", date(iUnbannedTimestamp, 2));
else if(iPerm == 1) SendClientMessage(playerid, COLOR_WHITE, "This is a permanent ban and it will not expire.");
Kick(playerid);
}
return 1;
}

forward thread_loadVariables(playerid);
public thread_loadVariables(playerid)
{
new
rows,
fields;

cache_get_data(rows, fields);
if(rows == 1)
{
new temp[50];
cache_get_row(0, 0, temp);
pInfo[playerid][pDataID] = strval(temp);
cache_get_row(0, 2, pInfo[playerid][pPassword]);
cache_get_row(0, 3, temp);
pInfo[playerid][pAdmin] = strval(temp);
cache_get_row(0, 4, temp);
pInfo[playerid][pCash] = strval(temp);
cache_get_row(0, 5, temp);
pInfo[playerid][pSavings] = strval(temp);
cache_get_row(0, 6, temp);
pInfo[playerid][pBankAccount] = strval(temp);
cache_get_row(0, 7, temp);
pInfo[playerid][pLevel] = strval(temp);
cache_get_row(0, 8, temp);
pInfo[playerid][pKills] = strval(temp);
cache_get_row(0, 9, temp);
pInfo[playerid][pDeaths] = strval(temp);
cache_get_row(0, 10, temp);
pInfo[playerid][pRegTime] = strval(temp);
cache_get_row(0, 11, temp);
pInfo[playerid][pLastOn] = strval(temp);
cache_get_row(0, 13, temp);
pInfo[playerid][pHealth] = floatstr(temp);
cache_get_row(0, 14, temp);
pInfo[playerid][pArmour] = floatstr(temp);
cache_get_row(0, 15, temp);
pInfo[playerid][pLastX] = floatstr(temp);
cache_get_row(0, 16, temp);
pInfo[playerid][pLastY] = floatstr(temp);
cache_get_row(0, 17, temp);
pInfo[playerid][pLastY] = floatstr(temp);
cache_get_row(0, 18, temp);
pInfo[playerid][pSkin] = strval(temp);
cache_get_row(0, 19, pInfo[playerid][pGender]);
cache_get_row(0, 20, temp);
pInfo[playerid][pAge] = strval(temp);

clearPlayerChat(playerid);
SendClientMessage(playerid, COLOR_WHITE, "SERVER: This account "#COL_EMB_GREEN"has been registered."#COL_EMB_WHITE" Please authenticate in order to proceed.");
SPD(playerid, DIALOG_AUTHENTICATION);
}
else if(rows == 0)
{
clearPlayerChat(playerid);
SendClientMessage(playerid, COLOR_WHITE, "SERVER: This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE".");
SPD(playerid, DIALOG_REGISTER);
}
else
{
clearPlayerChat(playerid);
SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
Kick(playerid);
}
return 1;
}

forward thread_defaultCallback(playerid);
public thread_defaultCallback(playerid)
{
return 1;
}

// -------------- Hooked Functions [go below this line] ------------- //

stock realKick(playerid)
{
defer serverKickDelay(playerid);
return playerid;
}

#if defined _ALS_Kick
#undef Kick
#else
#define _ALS_Kick
#endif
#define Kick realKick

// --------------- Timers [go below this line] -------------- //

timer serverKickDelay[500](playerid)
{
Kick(playerid);
return 1;
}

// ---------- Stock Functions [go below this line] ---------- //

stock saveVariables(playerid)
{
if(tAuthenticated[playerid])
{
new
szQuery[1000],
Float:pFloatValue[5];

GetPlayerHealth(playerid, pFloatValue[0]);
GetPlayerArmour(playerid, pFloatValue[1]);
GetPlayerPos(playerid, pFloatValue[2], pFloatValue[3], pFloatValue[4]);

format(szQuery, sizeof(szQuery), "UPDATE `Accounts` SET `adminLevel` = %d, `Cash` = %d, `Savings` = %d, `BankAccount` = %d, `Level` = %d, `Kills` = %d, `Deaths` = %d, `LastOn` = %d, `Health` = %f, `Armour` = %f, `LastX` = %f, `LastY` = %f, `LastZ` = %f, `Gender` = '%s' AND `Age` = %d WHERE `Username` = '%s'",
pInfo[playerid][pAdmin],
real_GetPlayerCash(playerid),
pInfo[playerid][pSavings],
pInfo[playerid][pBankAccount],
pInfo[playerid][pLevel],
pInfo[playerid][pKills],
pInfo[playerid][pDeaths],
gettime(),
pFloatValue[0],
pFloatValue[1],
pFloatValue[2],
pFloatValue[3],
pFloatValue[4],
pInfo[playerid][pGender],
pInfo[playerid][pAge],
getEscName(playerid));

mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");
}
return 1;
}

stock sendAreaMessage(playerid, color, color1, color2, color3, color4, string[])
{
new
Float:fPos[3]
;

GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
foreach(new i : Player)
{
if(IsPlayerInRangeOfPoint(i, 7.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color, string);
else if(IsPlayerInRangeOfPoint(i, 10.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color1, string);
else if(IsPlayerInRangeOfPoint(i, 15.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color2, string);
else if(IsPlayerInRangeOfPoint(i, 20.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color3, string);
else if(IsPlayerInRangeOfPoint(i, 25.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color4, string);
}
}

stock SPD(playerid, dialogid) // a shortened custom function for ShowPlayerDialog; you don't have to handle all of the ShowPlayerDialog lines, just know the playerid and the dialogid you want to show
{
switch(dialogid)
{
case DIALOG_REGISTER: ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE"Account Registration", ""#COL_EMB_WHITE"This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE"!\n\nEnter your desired password below to register this account.", "Submit", "Leave");
case DIALOG_AUTHENTICATION: ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", ""#COL_EMB_WHITE"This account has "#COL_EMB_GREEN"been registered"#COL_EMB_WHITE"!\n\nEnter the account password below to proceed.", "Submit", "Leave");
case DIALOG_SETGENDER: ShowPlayerDialog(playerid, DIALOG_SETGENDER, DIALOG_STYLE_MSGBOX, ""#COL_EMB_WHITE"Gender Selection", ""#COL_EMB_WHITE"What is your character's gender?", "Male", "Female");
case DIALOG_SETAGE: ShowPlayerDialog(playerid, DIALOG_SETAGE, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE" Age Selection", ""#COL_EMB_WHITE"How old is your character going to be?\n\nValid ages are between between 10 and 80.", "Submit", "Leave");
}
return -1;
}

stock clearPlayerChat(playerid, lines = 20)
{
for(new i; i < lines; i++) SendClientMessage(playerid, -1, " ");
return -1;
}

stock getName(playerid)
{
new
szName[MAX_PLAYER_NAME];

GetPlayerName(playerid, szName, sizeof(szName));
return szName;
}

stock getRolePlayName(playerid)
{
new
szName[MAX_PLAYER_NAME],
stringPos;

GetPlayerName(playerid, szName, sizeof(szName));
stringPos = strfind(szName, "_");
szName[stringPos] = ' ';
return szName;
}

stock getEscName(playerid)
{
new szUsername[25], szEscName[26];
GetPlayerName(playerid, szUsername, sizeof(szUsername));
mysql_real_escape_string(szUsername, szEscName);
return szEscName;
}

stock IsRolePlayName(playerid)
{
new trpn[MAX_PLAYER_NAME];
GetPlayerName(playerid, trpn, sizeof(trpn));
new strd = strfind(trpn, "_", false);
if(strfind(trpn,"_",false,strd+1) == -1)
{
if(strd > 0)
{
if(trpn[strd-1] && trpn[strd+1])
{
for(new a = 0, l = strlen(trpn); a < l; a++)
{
switch(trpn[a])
{
case '0' .. '9': return 0;
case 'a' .. 'z': continue;
case 'A' .. 'Z': continue;
case '_': continue;
default: return 0;
}
}
return 1;
}
}
}
return 0;
}

stock returnTime()
{
new hr, minute, sec;
gettime(hr, minute, sec);

new szString[30];
format(szString, sizeof(szString), "%d:%d:%d", hr, minute, sec);
return szString;
}

stock returnDate()
{
new day, mon, year;
gettime(year, mon, day);

new szString[30];
format(szString, sizeof(szString), "%d/%d/%d", mon, day, year);
return szString;
}

stock date(timestamp, _form = 0) // credits to whoever made this function
{
/* date( 1247182451 ) will print >> 09.07.2009-23:34:11
date( 1247182451, 1) will print >> 09/07/2009
date( 1247182451, 2) will print >> July 09, 2009 at 23:34:11
date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
date( 1247182451, 4) will print >> 23:34
*/

new year=1970, day=0, month=0, hours=0, mins=0, sec=0;

new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
new names_of_month[12][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
new returnstring[32];

while(timestamp>31622400)
{
timestamp -= 31536000;
if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
year++;
}

if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
days_of_month[1] = 29;
else
days_of_month[1] = 28;

while(timestamp>86400)
{
timestamp -= 86400, day++;
if(day==days_of_month[month]) day=0, month++;
}
while(timestamp>60)
{
timestamp -= 60, mins++;
if( mins == 60) mins=0, hours++;
}
sec=timestamp;
switch( _form )
{
case 1: format(returnstring, 31, "%02d/%02d/%d - %02d:%02d", day+1, month+1, year, hours, mins);
case 2: format(returnstring, 31, "%s %02d, %d at %02d:%02d", names_of_month[month], day+1, year, hours, mins);
case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1, names_of_month[month][0], names_of_month[month][1], names_of_month[month][2], year, hours, mins);
case 4: format(returnstring, 31, "%02d:%02d:%02d", hours, mins, sec);
default: format(returnstring, 31, "%02d.%02d.%d-%02d:%02d:%02d", day+1, month+1, year, hours, mins, sec);
}

return returnstring;
}

stock mktime(hour, minute, second, day, month, year) // credits to ******
{
static days_of_month[12] =
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
lMinute, lHour, lDay, lMonth, lYear, lMinuteS, lHourS, lDayS, lMonthS, lYearS;

if (year != lYear)
{
lYearS = 0;
for (new j = 1970; j < year; j++)
{
lYearS += 31536000;
if ((!(j % 4) && (j % 100)) || !(j % 400)) lYearS += 86400;
}
lYear = year;
}
if (month != lMonth)
{
lMonthS = 0;
month--;
for (new i = 0; i < month; i++)
{
lMonthS += days_of_month[i] * 86400;
if ((i == 1) && ((!(year % 4) && (year % 100)) || !(year % 400))) lMonthS += 86400;
}
lMonth = month;
}
if (day != lDay)
{
lDayS = day * 86400;
lDay = day;
}
if (hour != lHour)
{
lHourS = hour * 3600;
lHour = hour;
}
if (minute != lMinute)
{
lMinuteS = minute * 60;
lMinute = minute;
}
return lYearS + lMonthS + lDayS + lHourS + lMinuteS + second;
}

// ---------- Server-Side Money System [functions begin] ---------- //

stock real_GivePlayerCash(playerid, value)
{
pInfo[playerid][pCash] += value;

ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pInfo[playerid][pCash]);
return 1;
}

stock real_TakePlayerCash(playerid, value)
{
pInfo[playerid][pCash] -= value;

ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pInfo[playerid][pCash]);
return 1;
}

stock real_SetPlayerCash(playerid, value)
{
pInfo[playerid][pCash] = value;

ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, value);
return 1;
}

stock real_ResetPlayerCash(playerid)
{
pInfo[playerid][pCash] = 0;
ResetPlayerMoney(playerid);
return 1;
}

stock real_GetPlayerCash(playerid)
return pInfo[playerid][pCash];

// ---------------------------------------------- //



// EoF - End of File

MadafakaPro
22/03/2013, 12:08 PM
Well that code wasnt in ur script i just added it..
Ok leave that.
What columns i should make in the bans table?

Scenario
22/03/2013, 12:50 PM
Here's a package for the GM. It has the .sql files for the accounts and bans table (you'll NEED to upload them both since the version of the GM that's in this package has some additions).

http://www.mediafire.com/?2m4oi4cge622oxl