//==========[INCLUDES]==========//
#include <a_samp>
#include <a_mysql>
//==========[Farben]==========//
//==========[Dialoge]==========//
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
//==========[News]==========//
new vermysql;
//==========[Forwards]==========//
forward UserCheck(playerid);
forward UserRegister(playerid);
forward UserLogin(playerid);
//==========[Enums]==========//
enum Spieler
{
p_id,
pLoggedIn,
pName[MAX_PLAYER_NAME],
pLevel,
pGeld,
pKills,
pDeaths
}
new SpielerInfo[MAX_PLAYERS][Spieler];
//==========[MYSQL]==========//
#define db_host "-"
#define db_user "-"
#define db_pass "-"
#define db_db "-"
//==========[Einstellungen]==========//
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
SetGameModeText("HSP4F v0.0.1");
EnableStuntBonusForAll(0);
UsePlayerPedAnims();
MySQL_SetupConnection();
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
mysql_close(vermysql);
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if(!SpielerInfo[playerid][pLoggedIn])
{
new query[128];
mysql_format(vermysql, query, sizeof(query), "SELECT id FROM users WHERE name = '%e'", SpielerInfo[playerid][pName]);
mysql_pquery(vermysql, query, "OnUserCheck", "id", playerid);
}
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
SpielerInfo[playerid][p_id] = 0;
SpielerInfo[playerid][pLoggedIn] = false;
SpielerInfo[playerid][pLevel] = 0;
SpielerInfo[playerid][pGeld] = 0;
SpielerInfo[playerid][pKills] = 0;
SpielerInfo[playerid][pDeaths] = 0;
GetPlayerName(playerid,SpielerInfo[playerid][pName], MAX_PLAYER_NAME);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SpielerSpeichern(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
SpielerInfo[killerid][pKills]++;
GivePlayerMoney(killerid, 10);
SpielerInfo[killerid][pGeld] += 10;
if(SpielerInfo[killerid][pKills] > 3)
{
SpielerInfo[killerid][pLevel] = 1;
}
}
SpielerInfo[playerid][pDeaths]++;
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(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 OnPlayerPickUpPickup(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[])
{
if(dialogid == DIALOG_REGISTER)
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", "Bitte registriere Dich:\n{FF0000}Mindestens 3 Zeichen!", "Ok", "Abbrechen");
new query[256];
mysql_format(vermysql, query, sizeof(query), "INSERT INTO users (name, password) VALUES ('%e', MD5('%e'))", SpielerInfo[playerid][pName], inputtext);
mysql_pquery(vermysql, query, "OnUserRegister", "d", playerid);
return 1;
}
if(dialogid == DIALOG_LOGIN)
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Anmeldung", "Bitte logge Dich ein:\n{FF0000}Mindestens 3 Zeichen!", "Ok", "Abbrechen");
new query[256];
mysql_format(vermysql, query, sizeof(query), "SELECT * FROM users WHERE name = '%e' AND password = MD5('%e')", SpielerInfo[playerid][pName], inputtext);
mysql_pquery(vermysql, query, "OnUserLogin", "d", playerid);
return 1;
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
public UserCheck(playerid)
{
if(cache_get_row_count() == 0)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", "Bitte registriere Dich:", "Ok", "Abbrechen");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Anmeldung", "Bitte logge Dich ein:", "Ok", "Abbrechen");
}
return 1;
}
public UserRegister(playerid)
{
SpielerInfo[playerid][p_id] = cache_insert_id();
SendClientMessage(playerid, 0x00FF00FF, "[Konto] Registration erfolgreich.");
return 1;
}
public UserLogin(playerid)
{
if(cache_get_row_count() == 0)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Anmeldung", "Bitte logge Dich ein:\n{FF0000}Falsches Passwort!", "Ok", "Abbrechen");
}
else
{
SpielerInfo[playerid][p_id] = cache_get_field_content_int(0, "id", vermysql);
SpielerInfo[playerid][pLevel] = cache_get_field_content_int(0, "level", vermysql);
SpielerInfo[playerid][pGeld] = cache_get_field_content_int(0, "geld", vermysql);
SpielerInfo[playerid][pKills] = cache_get_field_content_int(0, "kills", vermysql);
SpielerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "deaths", vermysql);
SpielerInfo[playerid][pLoggedIn] = true;
SendClientMessage(playerid, 0x00FF00FF, "[Konto] Eingeloggt.");
GivePlayerMoney(playerid, SpielerInfo[playerid][pGeld]);
}
return 1;
}
stock MySQL_SetupConnection(ttl = 3)
{
print("[MySQL] Verbindungsaufbau...");
vermysql = mysql_connect(db_host,db_user,db_db,db_pass);
if(mysql_errno(vermysql) != 0)
{
if(ttl > 1)
{
print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
printf("[MySQL] Starte neuen Verbindungsversuch (TTL: %d).", ttl-1);
return MySQL_SetupConnection(ttl-1);
}
else
{
print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
print("[MySQL] Bitte prüfen Sie die Verbindungsdaten.");
print("[MySQL] Der Server wird heruntergefahren.");
return SendRconCommand("exit");
}
}
printf("[MySQL] Die Verbindung zur Datenbank wurde erfolgreich hergestellt! Handle: %d", vermysql);
return 1;
}
stock SpielerSpeichern(playerid)
{
if(!SpielerInfo[playerid][pLoggedIn]) return 1;
new query[256];
mysql_format(vermysql, query, sizeof(query), "UPDATE users SET level = '%d', money = '%d', kills = '%d', deaths = '%d' WHERE id = '%d'",
SpielerInfo[playerid][pLevel], SpielerInfo[playerid][pGeld], SpielerInfo[playerid][pKills], SpielerInfo[playerid][pDeaths], SpielerInfo[playerid][p_id]);
mysql_pquery(vermysql, query);
return 1;
}