Here is all of my script, i know its a bit messy but im still learning this coding language.
Код:
#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <core>
#include <float>
//#include "../include/gl_spawns.inc"
#define green 0x33AA33AA
#define red 0xFF0000AA
#define mysql_host "127.0.0.1"
#define mysql_user "XXXXXXXXXXX"
#define mysql_password "XXXXXXXXXXX"
#define mysql_database "samp"
#pragma tabsize 0
main()
{
print("\n----------------------------------");
print(" Welcome to UK-MP GTA Server!\n");
print("----------------------------------\n");
}
public OnPlayerConnect(playerid)
{
GameTextForPlayer(playerid,"~w~SA-MP: ~r~UK-MP GTA Server",5000,5);
new Query[80],pName[24],string[128];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Log in",string,"Login","");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","");
}
mysql_free_result();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new Query[200],pName[24];
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerName(playerid, pName, sizeof(pName));
format(Query,sizeof(Query),"UPDATE `Users` SET PosX='%f',PosY='%f',PosZ='%f',Money='%i' WHERE `Username` = '%s';",X,Y,Z,GetPlayerMoney(playerid),pName);
mysql_query(Query);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
}
else
{
new EscapedText[60], Query[200], pName[24];
mysql_real_escape_string(inputtext, EscapedText);
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money,BankMoney,Level,PosX,PosY,PosZ,CarID1,CarID2,HouseID,GarageID) VALUES ('%s','%s','5000','0','1','2495.0720','-1687.5278','13.5150','0','0','0','0');",pName);
mysql_query(Query);
SendClientMessage(playerid,green,"You have been successfully registered!");
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,1);
}
}
if(dialogid == 0)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60], Query[128], pName[24];
mysql_real_escape_string(password, EscapedText);
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s';",pName,EscapedText);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid,green,"You have been logged in!");
LoadStats(playerid);
}
else
{
SendClientMessage(playerid,red,"Wrong password!");
Kick(playerid);
}
mysql_free_result();
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new idx;
new cmd[256];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/stats", true) == 0) {
SendClientMessage(playerid,red,"[Money: $GetPlayerMoney(playerid)]");
}
return 0;
}
public OnPlayerSpawn(playerid)
{
SetPlayerInterior(playerid,0);
TogglePlayerClock(playerid,0);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
enum pEnum
{
Name[MAX_PLAYER_NAME],
Password[34],
Admin,
Money,
Float:X,
Float:Y,
Float:Z
};
new UserStats[MAX_PLAYERS][pEnum];
public OnPlayerRequestClass(playerid, classid)
{
TogglePlayerSpectating(playerid, 0);
SetTimer("AutoSpawn",500,false);// 2 seconds it will spawn u
return 1;
}
forward AutoSpawn(playerid);
public AutoSpawn(playerid)
{
new Query[128],pName[24],Load[50];
GetPlayerName(playerid,pName,sizeof(pName));
format(Query,sizeof(Query), "SELECT `PosX`, `PosY`, `PosZ` FROM `Users` WHERE `Username` = '%s'", pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(Load))
{
SpawnPlayer(playerid);
sscanf(Load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerSkin(playerid, 230);
}
mysql_free_result();
return 1;
}
enum PlayerInfo
{
Username[23],
Password[24],
Money
}
new PInfo[MAX_PLAYERS][PlayerInfo];
stock LoadStats(playerid)
{
new pName[24],Query[80];
GetPlayerName(playerid,pName,24);
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `Username` = '%s';", pName);
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query, "|");
sscanf(Query, "e<p<|>s[24]s[23]i>", PInfo[playerid]);
mysql_free_result();
GivePlayerMoney(playerid,PInfo[playerid][Money]);
return 1;
}
public OnGameModeInit()
{
//AllowAdminTeleport(1);
mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
mysql_debug(1);
SetGameModeText("UK-MP");
ShowPlayerMarkers(1);
ShowNameTags(1);
AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
return 1;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}