Guten Tag,
mal wieder benötige ich eure Hilfe. Ich habe eine MySQL Datenbank die wie folgt aufgebaut ist:
CREATE TABLE IF NOT EXISTS `vehicles` (
`vehicleID` int(20) unsigned NOT NULL AUTO_INCREMENT,
`modelID` int(5) unsigned NOT NULL,
`ownerID` int(20) unsigned NOT NULL,
`ingameID` int(5) unsigned NOT NULL,
`posX` float NOT NULL,
`posY` float NOT NULL,
`posZ` float NOT NULL,
`posAngle` float NOT NULL,
`color1` int(3) unsigned NOT NULL,
`color2` int(3) unsigned NOT NULL,
`platetext` varchar(32) NOT NULL,
`respawnTime` int(5) unsigned NOT NULL DEFAULT '0',
`radio` enum('Standart','Radio Galaxy') NOT NULL,
PRIMARY KEY (`vehicleID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=41 ;
Alles anzeigen
Hier die ganzen Inhalte der Tabelle (40 Autos):
INSERT INTO `vehicles` (`vehicleID`, `modelID`, `ownerID`, `ingameID`, `posX`, `posY`, `posZ`, `posAngle`, `color1`, `color2`, `platetext`, `respawnTime`, `radio`) VALUES
(1, 411, 0, 0, 1601.85, -1683.97, 5.61023, 271.774, 79, 1, '', 0, 'Radio Galaxy'),
(2, 411, 0, 0, 1601.98, -1688.04, 5.61064, 94.0516, 79, 1, '', 0, 'Standart'),
(3, 411, 0, 0, 1602.02, -1691.97, 5.61073, 95.5257, 79, 1, '', 0, 'Standart'),
(4, 411, 0, 0, 1602.03, -1696.09, 5.6118, 87.3664, 79, 1, '', 0, 'Standart'),
(5, 411, 0, 0, 1601.99, -1700.13, 5.61057, 69.2405, 79, 1, '', 0, 'Standart'),
(6, 411, 0, 0, 1602.02, -1704.28, 5.61199, 87.4165, 79, 1, '', 0, 'Standart'),
(7, 411, 0, 0, 1585.18, -1667.6, 5.46582, 279.607, 79, 1, '', 0, 'Standart'),
(8, 411, 0, 0, 1585.33, -1671.66, 5.46556, 273.817, 79, 1, '', 0, 'Standart'),
(9, 411, 0, 0, 1595.36, -1710.97, 5.61069, 358.594, 79, 1, '', 0, 'Standart'),
(10, 411, 0, 0, 1591.32, -1710.99, 5.61067, 12.3247, 79, 1, '', 0, 'Standart'),
(11, 411, 0, 0, 1587.47, -1710.85, 5.6102, 355.34, 0, 0, '', 0, 'Standart'),
(12, 411, 0, 0, 1583.54, -1710.92, 5.61065, 0.22985, 0, 0, '', 0, 'Standart'),
(13, 411, 0, 0, 1578.64, -1710.78, 5.61175, 279.066, 0, 0, '', 0, 'Standart'),
(14, 411, 0, 0, 1574.46, -1710.73, 5.61255, 1.51323, 0, 0, '', 0, 'Standart'),
(15, 411, 0, 0, 1570.32, -1710.57, 5.61212, 3.1142, 0, 0, '', 0, 'Standart'),
(16, 411, 0, 0, 1566.88, -1711.42, 5.45788, 3.97542, 0, 0, '', 0, 'Standart'),
(17, 411, 0, 0, 1564.72, -1711.48, 5.46247, 343.738, 0, 0, '', 0, 'Standart'),
(18, 411, 0, 0, 1562.21, -1711.4, 5.45863, 0.896409, 0, 0, '', 0, 'Standart'),
(19, 411, 0, 0, 1558.84, -1711.37, 5.46055, 350.686, 0, 0, '', 0, 'Standart'),
(20, 411, 0, 0, 1545.84, -1684.4, 6.01837, 89.5165, 0, 0, '', 0, 'Standart'),
(21, 411, 0, 0, 1545.97, -1680.4, 6.01806, 84.9167, 0, 0, '', 0, 'Standart'),
(22, 411, 0, 0, 1545.94, -1676.17, 6.01819, 88.4936, 0, 0, '', 0, 'Standart'),
(23, 411, 0, 0, 1545.87, -1672.07, 6.01935, 86.1884, 0, 0, '', 0, 'Standart'),
(24, 411, 0, 0, 1545.92, -1667.94, 6.01928, 91.4821, 0, 0, '', 0, 'Standart'),
(25, 411, 0, 0, 1528.7, -1688.04, 6.01881, 270.156, 0, 0, '', 0, 'Standart'),
(26, 411, 0, 0, 1528.53, -1683.92, 6.01819, 272.765, 0, 0, '', 0, 'Standart'),
(27, 411, 0, 0, 1526.44, -1643.87, 5.64935, 81.5633, 0, 0, '', 0, 'Standart'),
(28, 411, 0, 0, 1530.52, -1643.74, 5.648, 181.882, 0, 0, '', 0, 'Standart'),
(29, 411, 0, 0, 1534.61, -1643.79, 6.08289, 209.907, 79, 1, '', 0, 'Standart'),
(30, 411, 0, 0, 1538.71, -1643.8, 6.08051, 180.442, 79, 1, '', 0, 'Standart'),
(31, 411, 0, 0, 1546.43, -1651.06, 6.0809, 87.1817, 79, 1, '', 0, 'Standart'),
(32, 411, 0, 0, 1546.4, -1655.05, 6.08046, 95.2573, 79, 1, '', 0, 'Standart'),
(33, 411, 0, 0, 1546.28, -1663.21, 5.93411, 94.1161, 79, 1, '', 0, 'Standart'),
(34, 411, 0, 0, 1546.29, -1659.03, 5.93351, 97.6728, 79, 1, '', 0, 'Standart'),
(35, 411, 0, 0, 1783.48, -1894.84, 13.3919, 273.968, 0, 0, '', 0, 'Standart'),
(36, 411, 0, 0, 1766.52, -1896.78, 13.5634, 9.15697, 0, 0, '', 0, 'Standart'),
(37, 411, 0, 0, 1774.79, -1895.63, 13.3855, 276.307, 0, 0, '', 0, 'Radio Galaxy'),
(39, 411, 0, 0, 1787.14, -1897.69, 13.3945, 273.237, 0, 0, '', 0, 'Standart'),
(40, 0, 0, 0, 1787.34, -1897.2, 13.3947, 270.897, 0, 0, '', 0, 'Standart');
Alles anzeigen
So sieht mein GameMode Init aus:
public OnGameModeInit()
{
// Objekte
//new dbVehicleID[20], vehicleID, modelID[5], posX[20], posY[20], posZ[20], posAngle[20], color1[5], color2[5], respawnTime[5];
new carID[30];
new vehicleID[5];
new gameVehicleID;
new color1[2];
new color2[2];
new positionX[20];
new positionY[20];
new positionZ[20];
new positionAngle[20];
new numberPlateText[50];
new numberPlateActivated[1];
new query[180];
// mysql connect
mysql_init(LOG_ALL, 1);
mysql_connect(host, mysqluser, mysqlpass, database);
// GameMode Name
SetGameModeText("Brox German Reallife");
// Server Einstellungen
DisableInteriorEnterExits();
EnableStuntBonusForAll(0);
ShowPlayerMarkers(0);
UsePlayerPedAnims();
SetWeather(10);
// Update
mysql_query("UPDATE users SET ingameID = 0, status = 'offline'");
mysql_query("UPDATE prison_user SET ingameID = 0, status = 'offline'");
mysql_query("UPDATE vehicles SET ingameID = 0");
// Lade alle Autos von der Datenbank
mysql_query("SELECT * FROM vehicles WHERE ownerID = 0");
mysql_store_result();
while (mysql_fetch_row_data())
{
// Speichere alle Daten ab
mysql_fetch_field("vehicleID", carID);
mysql_fetch_field("modelID", vehicleID);
mysql_fetch_field("color1", color1);
mysql_fetch_field("color2", color2);
mysql_fetch_field("posX", positionX);
mysql_fetch_field("posY", positionY);
mysql_fetch_field("posZ", positionZ);
mysql_fetch_field("posAngle", positionAngle);
CreateVehicle(strval(vehicleID), strval(positionX), strval(positionY), strval(positionZ), strval(positionAngle), strval(color1), strval(color2), 5);
/*
format(query1, sizeof(query1), "UPDATE cars SET gameVehicleID = %d WHERE carID = %d", gameVehicleID, strval(carID));
mysql_query(query1);
printf("%s", query1);
*/
}
mysql_free_result();
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
// Timer
SetTimer("AntiWeaponHack", 1000, true);
SetTimer("BanTimer", 60000, true);
SetTimer("ShowPosMarkers", 1000, true);
SetTimer("PrisonTimer", 60000, true);
return 1;
}
Wenn ich den Server starte, läd er genau 1 Auto. Der Log sieht wie folgt aus:
SA-MP Dedicated Server
----------------------
v0.3e, (C)2005-2012 SA-MP Team
[11:59:36] filterscripts = "" (string)
[11:59:36]
[11:59:36] Server Plugins
[11:59:36] --------------
[11:59:36] Loading plugin: mysql
[11:59:36] SA:MP MySQL Plugin v2.1.1 Loaded.
[11:59:36] Loaded.
[11:59:36] Loading plugin: sscanf
[11:59:36] [MySQL] Thread running. Threadsafe: Yes.
[11:59:36]
[11:59:36] ===============================
[11:59:36] sscanf plugin loaded.
[11:59:36] (c) 2009 Alex "Y_Less" Cole
[11:59:36] 0.3d-R2 500 Players "dnee"
[11:59:36] ===============================
[11:59:36] Loaded.
[11:59:36] Loaded 2 plugins.
[11:59:36]
[11:59:36] Filterscripts
[11:59:36] ---------------
[11:59:36] Loaded 0 filterscripts.
[11:59:36] [MySQL] Connected (0) to 'gta-reallife'@'000.000.000.000 via TCP/IP'.
[11:59:36] [MySQL] Server Version 5.1.61-0+squeeze1.
[11:59:37] [MySQL] Error (0): Function: mysql_fetch_row_data failed, no field data.
[11:59:37]
----------------------------------
[11:59:37] Brox German Reallife
[11:59:37] ----------------------------------
[11:59:37] Number of vehicle models: 1
Alles anzeigen
Diese Zeile ist mir schon aufgefallen:
Ich weis aber nicht was ich ändern kann. Seitdem ich meinen GameMode neu gescriptet habe will das ganze nicht mehr, obwohl ich das wirklich so gemacht habe wie immer.
So funktioniert es ja auch:
public OnGameModeInit()
{
// Objekte
new carID[30];
new vehicleID[5];
new gameVehicleID;
new color1[2];
new color2[2];
new positionX[20];
new positionY[20];
new positionZ[20];
new positionAngle[20];
new numberPlateText[50];
new numberPlateActivated[1];
new query1[180];
// mysql connect
mysql_init(LOG_ALL, 1);
mysql_connect(host,mysqluser,mysqlpass,database);
// Setze den Status aller Spieler auf "offline"
mysql_query("UPDATE users SET status = 'offline'");
// Interiors deaktivieren
DisableInteriorEnterExits();
// Spieler auf der Karte deaktivieren
ShowPlayerMarkers(0);
// Setze das Standartwetter
SetWeather(10);
// Lade alle Autos von der Datenbank
mysql_query("SELECT * FROM cars WHERE disabled = 0");
mysql_store_result();
while (mysql_fetch_row_data())
{
// Speichere alle Daten ab
mysql_fetch_field("carID", carID);
mysql_fetch_field("vehicleID", vehicleID);
mysql_fetch_field("color1", color1);
mysql_fetch_field("color2", color2);
mysql_fetch_field("positionX", positionX);
mysql_fetch_field("positionY", positionY);
mysql_fetch_field("positionZ", positionZ);
mysql_fetch_field("positionAngle", positionAngle);
mysql_fetch_field("numberPlateText", numberPlateText);
mysql_fetch_field("numberPlateActivated", numberPlateActivated);
if (strval(numberPlateActivated) == 1)
{
CreateVehicle(strval(vehicleID), strval(positionX), strval(positionY), strval(positionZ), strval(positionAngle), strval(color1), strval(color2), 5);
/*
format(query1, sizeof(query1), "UPDATE cars SET gameVehicleID = %d WHERE carID = %d", gameVehicleID, strval(carID));
mysql_query(query1);
printf("%s", query1);
*/
}
else
{
CreateVehicle(strval(vehicleID), strval(positionX), strval(positionY), strval(positionZ), strval(positionAngle), strval(color1), strval(color2), 5);
/*
format(query1, sizeof(query1), "UPDATE cars SET gameVehicleID = %d WHERE carID = %d", gameVehicleID, strval(carID));
mysql_query(query1);
printf("%s", query1);
*/
}
}
mysql_free_result();
ManualVehicleEngineAndLights();
}
Lasst euch nicht von der Tabelle cars irritieren, ich habe nämlich 2 Auto-Tabellen (bevor ich angefangen habe den GameMode neu zu scripten hieß es cars und jetzt vehicles.) Beide Tabellen existieren noch. Die Tabelle cars lösche ich aber da sie wie ich schon gesagt habe jetzt vehicles heißt. Die Tabelle cars ist so aufgebaut:
CREATE TABLE IF NOT EXISTS `cars` (
`carID` int(20) unsigned NOT NULL AUTO_INCREMENT,
`vehicleID` int(5) unsigned NOT NULL,
`ownerID` int(20) unsigned NOT NULL,
`gameVehicleID` int(20) unsigned NOT NULL,
`color1` int(2) unsigned NOT NULL,
`color2` int(2) unsigned NOT NULL,
`positionX` float NOT NULL,
`positionY` float NOT NULL,
`positionZ` float NOT NULL,
`positionAngle` float NOT NULL,
`numberPlateText` varchar(250) NOT NULL,
`numberPlateActivated` int(1) unsigned NOT NULL,
`carlocked` int(1) unsigned NOT NULL,
`disabled` int(1) unsigned NOT NULL,
PRIMARY KEY (`carID`),
KEY `carID` (`carID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=164 ;
Alles anzeigen
Den Inhalt von cars werde ich aber nicht posten, da sonst der Beitrag zu lang ist. In der Tabelle cars werden aber zumindest 84 Autos geladen. Zwar keine 163 (so viel sind eigentlich eingetragen) aber zumindest 84.
Erkennt jemand den fehler zwischen den beiden GameModes ? Der untere GameModeInit Teil ist vom alten Script und oben das neue. Warum liest er nicht alle Autos aus der MySQL Tabelle aus ? Das ist mein eigentliches Problem derzeit. Ich hoffe ich habe es so verständlich erklärt.
Wenn es nicht verständlich ist, erkläre ich es gerne noch einmal. Ich hoffe ihr könnt mir helfen