Hi,
ich habe mir folgenden Code zusammengebastelt:
ocmd:ccd(playerid,params[])
{
new name[32],price,level,Float:xPos[3];
if(pInfo[playerid][pAdmin] != 5)return 1;
if(sscanf(params,"dds[32]",price,level,name))return SendClientMessage(playerid,COLOR_GREY,"Benutze: /ccd [Preis] [Level] [Name]");
for(new i;i<MAX_AUTOHAUS;i++) {
if(AHInfo[i][zCreated])continue;
new str[256];
GetPlayerPos(playerid,xPos[0],xPos[1],xPos[2]);
format(str,sizeof str,"INSERT INTO `Cardealers` (`PosX`, `PosY`, `PosZ`, `Name`, `Price`, `Level`) VALUES ('%f', '%f', '%f', '%s', '%d', '%d')",xPos[0],xPos[1],xPos[2],name,price,level);
mysql_query(str);
LoadCarDealer(i);
}
return 1;
}
So weit, so gut.
Leider schreibt der Server 2 Einträge in die Datenbank, obwohl ich den Befehl nur 1x ausführe.
Hier der Log des MySQL-Log:
[21:52:29] CMySQLHandler::Query(SELECT * FROM `Cardealers` WHERE `ID` = '0') - Successfully executed.
[21:52:29] >> mysql_store_result( Connection handle: 1 )
[21:52:29] CMySQLHandler::StoreResult() - Result was stored.
[21:52:29] >> mysql_num_rows( Connection handle: 1 )
[21:52:29] CMySQLHandler::NumRows() - Returned 0 row(s)
[21:52:29] >> mysql_query( Connection handle: 1 )
[21:52:29] CMySQLHandler::Query(INSERT INTO `Cardealers` (`PosX`, `PosY`, `PosZ`, `Name`, `Price`, `Level`) VALUES ('-318.554809', '815.759155', '14.518843', 'test', '1000', '1')) - Successfully executed.
[21:52:29] >> mysql_query( Connection handle: 1 )
[21:52:29] CMySQLHandler::Query(SELECT * FROM `Cardealers` WHERE `ID` = '1') - Successfully executed.
[21:52:29] >> mysql_store_result( Connection handle: 1 )
[21:52:29] CMySQLHandler::StoreResult() - Result was stored.
[21:52:29] >> mysql_num_rows( Connection handle: 1 )
[21:52:29] CMySQLHandler::NumRows() - Returned 1 row(s)
[21:52:29] >> mysql_fetch_row_format( Connection handle: 1 )
[21:52:29] CMySQLHandler::FetchRow() - Return: 1|test|-318.555|815.759|14.5188|0||1000|1
[21:52:29] >> mysql_fetch_row_format( Connection handle: 1 )
[21:52:29] >> mysql_free_result( Connection handle: 1 )
[21:52:29] CMySQLHandler::FreeResult() - Result was successfully free'd.
[21:52:32] CMySQLHandler::Query(UPDATE `Cardealers` SET `Owner` = 'Deagle', `Name` = 'test', `Bank` = '0' WHERE `ID` = '1') - Successfully executed.
[21:52:32] >> mysql_query( Connection handle: 1 )
[21:52:32] CMySQLHandler::Query(SELECT * FROM `Cardealers` WHERE `ID` = '0') - Successfully executed.
[21:52:32] >> mysql_store_result( Connection handle: 1 )
[21:52:32] CMySQLHandler::StoreResult() - Result was stored.
[21:52:32] >> mysql_num_rows( Connection handle: 1 )
[21:52:32] CMySQLHandler::NumRows() - Returned 0 row(s)
Alles anzeigen
Hier noch der LoadCarDealer-Stock:
stock LoadCarDealer(id)
{
new q[256];
format(q,256,"SELECT * FROM `Cardealers` WHERE `ID` = '%d'",id);
mysql_query(q);
mysql_store_result();
if(mysql_num_rows() == 1) {
new str[512];
while(mysql_fetch_row(str)) {
for(new i;i<MAX_AUTOHAUS;i++) {
if(AHInfo[i][zCreated])continue;
new string[256];
sscanf(str, "e<p<|>ds[32]fffds[24]dd>",AHInfo[i]);
if((!strcmp(AHInfo[i][zOwner],"Niemand",true))) {
AHInfo[i][zPickup]=CreatePickup(1273,1,AHInfo[i][zPosX],AHInfo[i][zPosY],AHInfo[i][zPosZ],0);
format(string,128,"** %s **\nDieses Autohaus ist zu verkaufen!\nPreis: %s€\nLevel: %d\nAutohaus kaufen: /buybiz",AHInfo[i][zName],inspoints(AHInfo[i][zPrice]),AHInfo[i][zLevel]);
AHInfo[i][zLabel]=Create3DTextLabel(string,COLOR_AHLABEL,AHInfo[i][zPosX],AHInfo[i][zPosY],AHInfo[i][zPosZ],10,0,0);
AHInfo[i][zCreated] = true;
} else {
AHInfo[i][zPickup]=CreatePickup(1272,1,AHInfo[i][zPosX],AHInfo[i][zPosY],AHInfo[i][zPosZ],0);
format(string,128,"** %s **\nBesitzer: %s",AHInfo[i][zName],AHInfo[i][zOwner]);
AHInfo[i][zLabel]=Create3DTextLabel(string,COLOR_AHLABEL,AHInfo[i][zPosX],AHInfo[i][zPosY],AHInfo[i][zPosZ],10,0,0);
AHInfo[i][zCreated] = true;
}
}
}
mysql_free_result();
}
return 1;
}
Warum schreibt er 2 Einträge in die Datenbank?
lg
Deagle