04.11.2018, 23:45
Will someone fix? I have a problem with vID. Please help. The whole code is written from scratch here.
It is a vehicle creation system.
It is a vehicle creation system.
Код:
#include <a_samp> #include <a_mysql> #include <Pawn.CMD> #include <sscanf2> main(){} #define MYSQL_HOST "127.0.0.1" #define MYSQL_USER "root" #define MYSQL_PASSWORD "12345" #define MYSQL_DATABASE "db" new MySQL: g_SQL; enum vInfo { vID, vModel, Text3D:vLabel }; new VehicleInfo[MAX_VEHICLES][vInfo]; public OnGameModeInit() { Connect(); SetupVehicleTable(); mysql_tquery(g_SQL, "SELECT * FROM `veh`", "LoadVehicles"); return 1; } public OnGameModeExit() { new saved; if(cache_num_rows()) { while(saved < cache_num_rows()) { SaveVehicle(saved); saved++; } } printf("%d saved vehicles", saved); mysql_close(g_SQL); return 1; } Connect() { new MySQLOpt: option_id = mysql_init_options(); mysql_set_option(option_id, AUTO_RECONNECT, true); g_SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, option_id); if(g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0) { print("OFF SERVER!"); SendRconCommand("exit"); return 1; } else { print("ON SERVER!"); } return 1; } SetupVehicleTable() { new query[1024]; strcat(query, "CREATE TABLE IF NOT EXISTS `veh` (`vehid` int(11), `vehmodel` int(5) default '0', PRIMARY KEY (`vehid`), UNIQUE KEY `vehid_2` (`vehid`), KEY `vehid` (`vehid`))"); mysql_tquery(g_SQL, query); return 1; } CreateVehicle_2(model) { new ID, query[512], str[512]; VehicleInfo[ID][vID] = CreateVehicle(model, -23.9678, 30.5966, 3.1172, 324.9064, -1, -1, -1); VehicleInfo[ID][vModel] = model; SetVehicleToRespawn(VehicleInfo[ID][vID]); mysql_format(g_SQL, query, sizeof(query), "INSERT INTO `veh` (`vehid`, `vehmodel`) VALUES ('%d', '%d')", VehicleInfo[ID][vID], model); mysql_tquery(g_SQL, query); format(str, sizeof(str), "{0b62ed}VID: {00d820}%d", VehicleInfo[ID][vID]); VehicleInfo[ID][vLabel] = Create3DTextLabel(str, -1, 0.0, 0.0, 0.0, 50.0, 0); Attach3DTextLabelToVehicle(VehicleInfo[ID][vLabel], VehicleInfo[ID][vID], 0.0, 0.0, 1.0); return 1; } forward LoadVehicles(); public LoadVehicles() { new loaded, ID, str[512]; if(cache_num_rows()) { while(loaded < cache_num_rows()) { cache_get_value_int(loaded, "vehid", VehicleInfo[ID][vID]); cache_get_value_int(loaded, "vehmodel", VehicleInfo[ID][vModel]); VehicleInfo[ID][vID] = CreateVehicle(VehicleInfo[ID][vModel], -23.9678, 30.5966, 3.1172, 324.9064, -1, -1, -1); SetVehicleToRespawn(VehicleInfo[ID][vID]); loaded++; format(str, sizeof(str), "{0b62ed}VID: {00d820}%d", VehicleInfo[ID][vID]); VehicleInfo[ID][vLabel] = Create3DTextLabel(str, -1, 0.0, 0.0, 0.0, 50.0, 0); Attach3DTextLabelToVehicle(VehicleInfo[ID][vLabel], VehicleInfo[ID][vID], 0.0, 0.0, 1.0); } } printf("%d loaded vehicles", loaded); return 1; } SaveVehicle(S_VID) { new query[512]; mysql_format(g_SQL, query, sizeof(query), "UPDATE `veh` SET `vehid` = %d, `vehmodel` = %d WHERE `vehid` = %d LIMIT 1", VehicleInfo[S_VID][vID], VehicleInfo[S_VID][vModel], VehicleInfo[S_VID][vID]); mysql_tquery(g_SQL, query); return 1; } DeleteVehicle(D_VID) { new query[512], ID, Veh[MAX_VEHICLES]; VehicleInfo[ID][vID] = DestroyVehicle(D_VID); Veh[VehicleInfo[ID][vID]] = D_VID; mysql_format(g_SQL, query, sizeof(query), "DELETE FROM `veh` WHERE `vehid` = %d LIMIT 1", D_VID); mysql_tquery(g_SQL, query); return 1; } CMD:create(playerid, params[]) { new model; if(sscanf(params, "d", model)) return SendClientMessage(playerid, -1, "USAGE: /create [MODEL ID]"); CreateVehicle_2(model); return 1; } CMD:delete(playerid, params[]) { new del_vid; if(sscanf(params, "d", del_vid)) return SendClientMessage(playerid, -1, "USAGE: /delete [VID]"); DeleteVehicle(del_vid); return 1; } public OnPlayerSpawn(playerid) { SetPlayerSkin(playerid, 29); SetPlayerPos(playerid, -23.9678, 30.5966, 3.1172); SetPlayerFacingAngle(playerid, 324.9064); return 1; }