I'll also send a huge part of the code, so you can see which part of the debug-log can be related to each part of the code.
pawn Код:
// Include required files
#include <a_samp>
#include <sscanf2>
#include <streamer>
#include <zcmd>
#include <SHA512>
#include <a_mysql>
// ********************************************************************************************************************************************************************************
// Hardcoded settings (you need to edit these here and recompile the filterscript to change them)
// ********************************************************************************************************************************************************************************
// Define your MySQL connection info here
#define mysql_host "127.0.0.1"
#define mysql_user "PowerPC603"
#define mysql_password "pass"
#define mysql_database "ppctrucking"
new SQL_db; // Will hold the connectionhandle to the database
// Define tablenames
#define table_playerdata "playerdata"
#define table_speedcams "speedcameras"
#define table_gasstations "gasstations"
#define table_policestations "policestations"
#define table_vehicleinfo "vehicleinfo"
// This callback gets called when the server initializes the filterscript
public OnFilterScriptInit()
{
// Print some debug-info to the server console
printf(" ");
printf("******************************************************************************************");
printf("PPC Support filterscript initializing...");
printf(" ");
// Turn on debug-logging for MySQL (logs everything into "mysql_log.txt" in the server main directory where "samp-server.exe" is located)
mysql_log(LOG_WARNING | LOG_ERROR | LOG_DEBUG);
// Connect to the MySQL database and store the connection-handle
SQL_db = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
// Check if there were errors after trying to connect
if (mysql_errno() == 0)
printf("Support filterscript: Connecting to MySQL was successful, connection-id: %i", SQL_db);
else // The connection failed, so close the connection and shutdown the server after 5 seconds
{
printf("ERROR: Connecting to MySQL failed, shutting down server in 5 seconds...");
printf(" ");
printf(" ");
printf(" ");
mysql_close(SQL_db);
SetTimer("StartShutdownServer", 1000, false);
// Skip the rest of the callback to prevent trying to load data from a non-existing connection
return 1;
}
// Create tables if they don't exist and populate them with default data (this is checked pretty fast when the tables already exist, usually less than a second)
// This function can take a few seconds when the tables don't exist yet, as they have to be created and some tables will get default data inserted into them
SQL_Setup_Tables();
// Load speedcameras, gas-stations, police-stations and vehicle-info from MySQL and print debug info to the server console
SQL_Data_Load();
printf("PPC Support filterscript initialized");
printf("******************************************************************************************");
printf(" ");
printf(" ");
printf(" ");
return 1;
}
// This timer is used to shutdown the server if connecting to the database failed
forward StartShutdownServer();
public StartShutdownServer()
{
printf("****************************************");
printf("****************************************");
printf(" ");
printf("ERROR: Support filterscript was unable to connect to MySQL, server is shutting down in a few seconds...");
printf(" ");
printf("****************************************");
printf("****************************************");
SetTimer("ShutdownServer", 4000, false);
return 1;
}
// This timer is used to shutdown the server if connecting to the database failed
forward ShutdownServer();
public ShutdownServer()
{
SendRconCommand("exit");
return 1;
}
// This callback is called when the filterscript is unloaded
public OnFilterScriptExit()
{
// Close the connection to the MySQL database
mysql_close(SQL_db);
return 1;
}
// This callback gets called when a player connects to the server
public OnPlayerConnect(playerid)
{
// Setup local variables
new Msg[128];
// Get the name of the player and store it in his account
GetPlayerName(playerid, APlayerData[playerid][PlayerName], 24);
// Try to get the password from the SQL-table (he might have already registered and needs to login properly by entering the password, or he might be a new player)
Player_PasswordLoad(playerid);
// Send a message to all players to let them know somebody else joined the server
format(Msg, 128, "{0000FF}Player '{FFFF00}%s{0000FF}' (id: {FFFF00}%i{0000FF}) has joined the server", APlayerData[playerid][PlayerName], playerid);
SendClientMessageToAll(0xFFFFFFFF, Msg);
return 1;
}
// This function is called when the player logs in (OnPlayerConnect) and sends a query to try to retrieve the password for this player
Player_PasswordLoad(playerid)
{
// Setup local variables
new Query[128];
// Try to get the password from the SQL-table
mysql_format(SQL_db, Query, sizeof(Query), "SELECT Password FROM %s WHERE PlayerName = '%e' LIMIT 1", table_playerdata, APlayerData[playerid][PlayerName]);
mysql_tquery(SQL_db, Query, "Player_OnPasswordLoad", "i", playerid);
}
// This custom callback is called when a player connects to the server (MySQL received a query to get his password using the function "Player_PasswordLoad")
forward Player_OnPasswordLoad(playerid);
public Player_OnPasswordLoad(playerid)
{
// Check if this player's account exists (number of rows should be 1)
if (cache_get_row_count(SQL_db) == 1)
{
// Store the password from the query-result
cache_get_row(0, 0, APlayerData[playerid][PlayerPassword], SQL_db, 130);
// Ask the player to enter his password to login
ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "Welcome", "Please login by entering your password:", "Login", "Cancel");
}
else // The player isn't registered yet (he has no account), so let him enter a password to register his account
ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_PASSWORD, "Welcome", "Please register by entering your password:", "Register", "Cancel");
return 1;
}
// This function is used after logging in properly by entering the correct password to load the rest of the data
Player_AccountLoad(playerid)
{
// Setup local variables
new Query[128];
// Construct the query to get all data from this player from MySQL
mysql_format(SQL_db, Query, sizeof(Query), "SELECT * FROM %s WHERE PlayerName = '%e' LIMIT 1", table_playerdata, APlayerData[playerid][PlayerName]);
// Execute the query and load all data using the custom callback "OnAccountLoad", also inform the player he logged in properly
mysql_tquery(SQL_db, Query, "Player_OnAccountLoad", "i", playerid);
}
// This custom callback is used after logging in to load the rest of the playerdata (only the password was loaded before during OnPlayerConnect callback)
forward Player_OnAccountLoad(playerid);
public Player_OnAccountLoad(playerid)
{
// Get all data from the query and store it in the APlayerData array
if (cache_get_field_content_int(0, "SpeedInMph", SQL_db) == 1)
APlayerData[playerid][SpeedInMph] = true; // Set the SpeedInMph as mph
else
APlayerData[playerid][SpeedInMph] = false; // Set the SpeedInMph as kph
APlayerData[playerid][SQLID] = cache_get_field_content_int(0, "ID", SQL_db);
APlayerData[playerid][PlayerFine] = cache_get_field_content_int(0, "Fines", SQL_db);
APlayerData[playerid][PlayerTickets] = cache_get_field_content_int(0, "Tickets", SQL_db);
APlayerData[playerid][PlayerTicketPrice] = cache_get_field_content_int(0, "TicketCost", SQL_db);
APlayerData[playerid][PlayerMoney] = cache_get_field_content_int(0, "Money", SQL_db);
APlayerData[playerid][PlayerScore] = cache_get_field_content_int(0, "Score", SQL_db);
APlayerData[playerid][AdminLevel] = cache_get_field_content_int(0, "AdminLevel", SQL_db);
APlayerData[playerid][JailTime] = cache_get_field_content_int(0, "JailTime", SQL_db);
// The player has logged in properly
APlayerData[playerid][LoggedIn] = true;
// Send a message to the client to inform him that he logged in properly
SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You logged in, welcome back");
return 1;
}
// This function creates a new account for the given player
Player_AccountCreate(playerid)
{
// Setup local variables
new Query[256];
// Add the player's account to the MySQL database (escape the name only, as there is no need to escape a hashed password)
mysql_format(SQL_db, Query, sizeof(Query), "INSERT INTO %s (PlayerName, Password) VALUES ('%e', '%s')", table_playerdata, APlayerData[playerid][PlayerName], APlayerData[playerid][PlayerPassword]);
mysql_tquery(SQL_db, Query, "Player_OnAccountCreate", "i", playerid);
}
// This custom callback is used after creating a new account (playername and password are inserted, but the ID must be loaded now to reference the player later on using this ID)
forward Player_OnAccountCreate(playerid);
public Player_OnAccountCreate(playerid)
{
// Get the ID from the auto-incremented table ("ID") and store it
APlayerData[playerid][SQLID] = cache_insert_id();
return 1;
}
// ********************************************************************************************************************************************************************************
// MySQL functions (creating tables which don't exist + insert default data, and loading functions)
// ********************************************************************************************************************************************************************************
// This function is called to check if all tables exist, and creates them in case they don't exist
// Also default data is inserted into those tables
SQL_Setup_Tables()
{
// Setup local variables
new Query[1024], Cache:result;
printf(" ");
printf("--------------------------------------------------------------------------------");
// Check if the playerdata table exists, and created it if it doesn't exist
format(Query, sizeof(Query), "SHOW TABLES LIKE '%s'", table_playerdata);
result = mysql_query(SQL_db, Query, true);
if (cache_get_row_count(SQL_db) == 0)
{
printf("MySQL: >> Creating table %s...", table_playerdata);
format(Query, sizeof(Query), "CREATE TABLE `%s` (", table_playerdata);
format(Query, sizeof(Query), "%s`ID` int(11) NOT NULL AUTO_INCREMENT, ", Query);
format(Query, sizeof(Query), "%s`PlayerName` varchar(25) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Password` varchar(130) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`AdminLevel` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Money` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Score` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Fines` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Tickets` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`TicketCost` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`SpeedInMph` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`JailTime` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%sPRIMARY KEY (`ID`)) ", Query);
format(Query, sizeof(Query), "%sENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8", Query);
mysql_query(SQL_db, Query, false);
// Set "TableCreated_PlayerData" to "true" to indicate this session has created the table "playerdata", so the gamemode can detect it and extend the table with it's own required columns
TableCreated_PlayerData = true;
printf("MySQL: >> Table '%s' created", table_playerdata);
}
else
printf("MySQL: Table '%s' exists, skipping table creation and data insertion", table_playerdata);
// Free the result after executing "SHOW TABLES LIKE ..." to prevent memory leaks
cache_delete(result, SQL_db);
// Check if the gasstations table exists, and created it if it doesn't exist, also insert default gas-stations
format(Query, sizeof(Query), "SHOW TABLES LIKE '%s'", table_gasstations);
result = mysql_query(SQL_db, Query, true);
if (cache_get_row_count(SQL_db) == 0)
{
printf("MySQL: >> Creating table %s...", table_gasstations);
format(Query, sizeof(Query), "CREATE TABLE `%s` (", table_gasstations);
format(Query, sizeof(Query), "%s`ID` int(11) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Name` varchar(50) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`X` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Y` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Z` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%sPRIMARY KEY (`ID`)) ", Query);
format(Query, sizeof(Query), "%sENGINE=InnoDB DEFAULT CHARSET=utf8", Query);
mysql_query(SQL_db, Query, false);
printf("MySQL: >> Inserting default data into table %s...", table_gasstations);
mysql_query(SQL_db, "START TRANSACTION", false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('0', 'LV - Tierra Robada', '-1471.50', '1863.75', '32.70')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('1', 'LV - El Quebrados', '-1326.50', '2677.50', '50.10')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('2', 'LV - Bone County', '611.50', '1694.50', '7.00')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('3', 'SF - Angel Pine', '-2249.25', '-2559.00', '32.00')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('4', 'SF - Whetstone', '-1606.50', '-2714.00', '48.60')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('5', 'SF - Flint County', '-93.50', '-1175.00', '2.30')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('6', 'LS - Montgomery', '1377.50', '457.00', '19.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('7', 'LS - Dillimore', '651.50', '-565.50', '16.40')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('8', 'SF - Easter Basin', '-1675.75', '412.75', '7.20')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('9', 'SF - Juniper Hollow', '-2405.50', '976.25', '45.30')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('10', 'SF - Doherty', '-2023.25', '156.75', '28.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('11', 'SF - Easter Bay Airport', '-1131.75', '-204.25', '14.20')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('12', 'LV - Fort Carson', '77.75', '1216.00', '18.83')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('13', 'Verdant Meadows', '350.50', '2537.50', '16.80')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('14', 'LV - Spinybed', '2147.00', '2747.75', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('15', 'LV - Come-A-Lot', '2639.75', '1106.00', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('16', 'LV - The Strip', '2115.00', '920.00', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('17', 'LV - The Emerald Isle', '2202.00', '2475.00', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('18', 'LV - Redsands West', '1596.50', '2199.75', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('19', 'LV - Las Venturas Airport', '1584.25', '1448.25', '10.90')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('20', 'LS - Temple', '1004.25', '-940.50', '42.20')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('21', 'LS - Idlewood', '1935.00', '-1772.75', '13.40')", table_gasstations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('22', 'LS - Los Santos International Airport', '1855.00', '-2394.25', '13.55')", table_gasstations);
mysql_query(SQL_db, Query, false);
mysql_query(SQL_db, "COMMIT", false);
printf("MySQL: >> Table '%s' created and default data inserted (23 gas-stations)", table_gasstations);
}
else
printf("MySQL: Table '%s' exists, skipping table creation and data insertion", table_gasstations);
// Free the result after executing "SHOW TABLES LIKE ..." to prevent memory leaks
cache_delete(result, SQL_db);
// Check if the policestations table exists, and created it if it doesn't exist, also insert default police-stations
format(Query, sizeof(Query), "SHOW TABLES LIKE '%s'", table_policestations);
result = mysql_query(SQL_db, Query, true);
if (cache_get_row_count(SQL_db) == 0)
{
printf("MySQL: >> Creating table %s...", table_policestations);
format(Query, sizeof(Query), "CREATE TABLE `%s` (", table_policestations);
format(Query, sizeof(Query), "%s`ID` int(11) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Name` varchar(50) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`X` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Y` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Z` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%sPRIMARY KEY (`ID`)) ", Query);
format(Query, sizeof(Query), "%sENGINE=InnoDB DEFAULT CHARSET=utf8", Query);
mysql_query(SQL_db, Query, false);
printf("MySQL: >> Inserting default data into table %s...", table_policestations);
mysql_query(SQL_db, "START TRANSACTION", false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('0', 'SF - Downtown', '-1605.50', '711.50', '13.86')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('1', 'SF - Angel Pine', '-2161.00', '-2385.75', '30.62')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('2', 'LV - El Quebrados', '-1390.00', '2637.75', '56.00')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('3', 'LV - Fort Carson', '-217.25', '979.25', '19.50')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('4', 'LV - Roca Escalante', '2290.25', '2430.50', '10.82')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('5', 'LS - Dillimore', '627.75', '-571.75', '17.57')", table_policestations);
mysql_query(SQL_db, Query, false);
format(Query, sizeof(Query), "INSERT INTO `%s` VALUES ('6', 'LS - Pershing Square', '1554.75', '-1675.75', '16.19')", table_policestations);
mysql_query(SQL_db, Query, false);
mysql_query(SQL_db, "COMMIT", false);
printf("MySQL: >> Table '%s' created and default data inserted (7 police-stations)", table_policestations);
}
else
printf("MySQL: Table '%s' exists, skipping table creation and data insertion", table_policestations);
// Free the result after executing "SHOW TABLES LIKE ..." to prevent memory leaks
cache_delete(result, SQL_db);
// Check if the speedcameras table exists, and created it if it doesn't exist
format(Query, sizeof(Query), "SHOW TABLES LIKE '%s'", table_speedcams);
result = mysql_query(SQL_db, Query, true);
if (cache_get_row_count(SQL_db) == 0)
{
printf("MySQL: >> Creating table %s...", table_speedcams);
format(Query, sizeof(Query), "CREATE TABLE `%s` (", table_speedcams);
format(Query, sizeof(Query), "%s`ID` int(11) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Name` varchar(50) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`CamSpeed` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`X` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Y` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Z` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Angle` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%sPRIMARY KEY (`ID`)) ", Query);
format(Query, sizeof(Query), "%sENGINE=InnoDB DEFAULT CHARSET=utf8", Query);
mysql_query(SQL_db, Query, false);
printf("MySQL: >> Table '%s' created", table_speedcams);
}
else
printf("MySQL: Table '%s' exists, skipping table creation and data insertion", table_speedcams);
// Free the result after executing "SHOW TABLES LIKE ..." to prevent memory leaks
cache_delete(result, SQL_db);
// Check if the vehicleinfo table exists, and created it if it doesn't exist
format(Query, sizeof(Query), "SHOW TABLES LIKE '%s'", table_vehicleinfo);
result = mysql_query(SQL_db, Query, true);
if (cache_get_row_count(SQL_db) == 0)
{
printf("MySQL: >> Creating table %s...", table_vehicleinfo);
format(Query, sizeof(Query), "CREATE TABLE `%s` (", table_vehicleinfo);
format(Query, sizeof(Query), "%s`ID` int(11) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Name` varchar(50) NOT NULL, ", Query);
format(Query, sizeof(Query), "%s`Class` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Model` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Price` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`MaxFuel` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Consumption` float NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`RefuelTime` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%s`Disabled` int(11) NOT NULL DEFAULT '0', ", Query);
format(Query, sizeof(Query), "%sPRIMARY KEY (`ID`)) ", Query);
format(Query, sizeof(Query), "%sENGINE=InnoDB DEFAULT CHARSET=utf8", Query);
mysql_query(SQL_db, Query, false);
printf("MySQL: >> Inserting default data into table %s...", table_vehicleinfo);
new ID, Name[50], Class, Model, Price, Float:MaxFuel, Float:Consump, RefuelT, Disabled;
mysql_query(SQL_db, "START TRANSACTION", false);
for (ID = 0; ID < sizeof(AVehicleInfo); ID++)
{
format(Name, sizeof(Name), AVehicleInfo[ID][VehicleName]);
Class = AVehicleInfo[ID][VehicleClass];
Model = AVehicleInfo[ID][VehicleModel];
Price = AVehicleInfo[ID][VehiclePrice];
MaxFuel = AVehicleInfo[ID][VehicleMaxFuel];
Consump = AVehicleInfo[ID][FuelConsumption];
RefuelT = AVehicleInfo[ID][RefuelTime];
if (AVehicleInfo[ID][VehicleDisabled] == true)
Disabled = 1;
else
Disabled = 0;
mysql_format(SQL_db, Query, sizeof(Query), "INSERT INTO `%s` VALUES ('%i', '%e', '%i', '%i', '%i', '%f', '%f', '%i', '%i')", table_vehicleinfo, ID, Name, Class, Model, Price, MaxFuel, Consump, RefuelT, Disabled);
mysql_query(SQL_db, Query, false);
}
mysql_query(SQL_db, "COMMIT", false);
printf("MySQL: >> Table '%s' created and default data inserted (212 vehicles)", table_vehicleinfo);
}
else
printf("MySQL: Table '%s' exists, skipping table creation and data insertion", table_vehicleinfo);
// Free the result after executing "SHOW TABLES LIKE ..." to prevent memory leaks
cache_delete(result, SQL_db);
printf("--------------------------------------------------------------------------------");
printf(" ");
return 1;
}
// This function is used to load all speedcameras, gas-stations from MySQL when starting the server (called only during OnFilterscriptInit)
SQL_Data_Load()
{
// Setup local variables
new Query[128], Cache:result;
printf("--------------------------------------------------------------------------------");
// Send a query to load all speedcameras from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_speedcams);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading speed-cameras from MySQL using \"%s\"", Query);
CamerasLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all gas-stations from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_gasstations);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading gas-stations from MySQL using \"%s\"", Query);
GasStationsLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all police-stations from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_policestations);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading police-stations from MySQL using \"%s\"", Query);
PoliceStationsLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all vehicle-info from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_vehicleinfo);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading vehicle-info from MySQL using \"%s\"", Query);
VehicleInfoLoad();
cache_delete(result, SQL_db);
printf("--------------------------------------------------------------------------------");
return 1;
}
// This function is called to load the speedcameras
CamerasLoad()
{
// Setup local variables
new Rows, CamID, CameraName[50], MaxSpeed, Float:x, Float:y, Float:z, Float:rot, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (cameras)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (cameras) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
CamID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", CameraName, SQL_db, sizeof(CameraName));
MaxSpeed = cache_get_field_content_int(Row, "CamSpeed", SQL_db);
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
rot = cache_get_field_content_float(Row, "Angle", SQL_db);
// Check if the CamID is invalid (out of range)
if ((CamID < 0) || (CamID >= MAX_CAMERAS))
{
// Count the amount of failed cameras (invalid CamID's)
CountFailed++;
printf("*** ERROR: Invalid CamID found in table %s: %i (entry deleted)", table_speedcams, CamID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_speedcams, CamID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next speedcamera from the MySQL query
continue;
}
// Check if the CamSpeed is invalid (0 or lower)
if (MaxSpeed <= 0)
{
// Count the amount of failed cameras (invalid MaxSpeed)
CountFailed++;
printf("*** ERROR: Invalid CamSpeed found in table %s: CamID %i, MaxSpeed %i (entry deleted)", table_speedcams, CamID, MaxSpeed);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_speedcams, CamID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next speedcamera from the MySQL query
continue;
}
// Create the camera at the given CamID (there should be no duplicate cameras with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupSpeedCamera(x, y, z, rot, MaxSpeed, CameraName, CamID);
// Count the succesfully created cameras
CountSuccess++;
}
}
// Print the amount of speedcams loaded for debugging
printf("*** Speed-cameras loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the gas-stations
GasStationsLoad()
{
// Setup local variables
new Rows, GasID, Name[50], Float:x, Float:y, Float:z, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (gas-stations)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (gas-stations) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
GasID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", Name, SQL_db, sizeof(Name));
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
// Check if the GasID is invalid (out of range)
if ((GasID < 0) || (GasID >= MAX_GASSTATIONS))
{
// Count the amount of failed gas-stations (invalid GasID's)
CountFailed++;
printf("*** ERROR: Invalid GasID found in table %s: %i (entry deleted)", table_gasstations, GasID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_gasstations, GasID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next gas-station from the MySQL query
continue;
}
// Create the gas-station at the given GasID (there should be no duplicate gas-stations with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupGasStation(x, y, z, Name, GasID);
// Count the succesfully created gas-stations
CountSuccess++;
}
}
// Print the amount of gas-stations loaded for debugging
printf("*** Gas-stations loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the police-stations
PoliceStationsLoad()
{
// Setup local variables
new Rows, PoliceID, Name[50], Float:x, Float:y, Float:z, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (police-stations)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (police-stations) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
PoliceID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", Name, SQL_db, sizeof(Name));
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
// Check if the PoliceID is invalid (out of range)
if ((PoliceID < 0) || (PoliceID >= MAX_POLICESTATIONS))
{
// Count the amount of failed police-stations (invalid PoliceID's)
CountFailed++;
printf("*** ERROR: Invalid PoliceID found in table %s: %i (entry deleted)", table_policestations, PoliceID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_policestations, PoliceID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next police-station from the MySQL query
continue;
}
// Create the police-station at the given PoliceID (there should be no duplicate police-stations with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupPoliceStation(x, y, z, Name, PoliceID);
// Count the succesfully created police-stations
CountSuccess++;
}
}
// Print the amount of police-stations loaded for debugging
printf("*** Police-stations loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the vehicle-info
VehicleInfoLoad()
{
// Setup local variables
new Rows, ID, Price, Float:MaxFuel, Float:Consump, RefuelT, Disabled, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (vehicle-info)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (vehicle-info) loaded, load data and overwrite default script-values
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
ID = cache_get_field_content_int(Row, "ID", SQL_db);
Price = cache_get_field_content_int(Row, "Price", SQL_db);
MaxFuel = cache_get_field_content_float(Row, "MaxFuel", SQL_db);
Consump = cache_get_field_content_float(Row, "Consumption", SQL_db);
RefuelT = cache_get_field_content_int(Row, "RefuelTime", SQL_db);
Disabled = cache_get_field_content_int(Row, "Disabled", SQL_db);
// Check if the ID is invalid (out of range)
if ((ID < 0) || (ID >= sizeof(AVehicleInfo)))
{
// Count the amount of failed vehicle-info entries (invalid ID's)
CountFailed++;
printf("*** ERROR: Invalid ID found in table %s: %i (entry deleted)", table_vehicleinfo, ID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_vehicleinfo, ID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next vehicle-info entry from the MySQL query
continue;
}
// Store all the data
AVehicleInfo[ID][VehiclePrice] = Price;
AVehicleInfo[ID][VehicleMaxFuel] = MaxFuel;
AVehicleInfo[ID][FuelConsumption] = Consump;
AVehicleInfo[ID][RefuelTime] = RefuelT;
if (Disabled == 1)
AVehicleInfo[ID][VehicleDisabled] = true;
else
AVehicleInfo[ID][VehicleDisabled] = false;
// Count the succesfully loaded vehicle-info entries
CountSuccess++;
}
}
// Print the amount of vehicle-info entries loaded for debugging
printf("*** Vehicle-info loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
As for the logs, they're a little big (about 280KB) so here's the link to them: