Hey Leute ich arbeite zurzeit an einem Carsystem welches nicht ganz klappen will...
Folgendes wenn ich mein car erstelle steht als Besitzer "2" obwohl ich unter accounts mit der ID 220 eingetragen bin.
Mal wieder alles für MYSQL:
stock Connect_To_Database()
{
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
return 1;
}
stock mysql_CheckAccount(playerid)
{
new Query[128],Name[MAX_PLAYER_NAME],count;
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
mysql_real_escape_string(Name, Name);
format(Query, sizeof(Query), "SELECT * FROM `accounts` WHERE `Name` = '%s'", Name);
mysql_query(Query);
mysql_store_result();
count = mysql_num_rows();
mysql_free_result();
return count;
}
stock CreateAccount(playerid, pass[])
{
new query[256],Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
mysql_real_escape_string(Name,Name);
mysql_real_escape_string(pass,pass);
format(query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Passwort` , `alevel` ) VALUES ('%s', '%s' , '%i')", Name, pass);
mysql_query(query);
return true;
}
stock mysql_getid(playerid,params[])
{
new query[130];
mysql_real_escape_string
format(query, 128, "SELECT `id` FROM `accounts` WHERE `Name` = '%s'", Name);
return 1;
}
stock mysql_ReturnPasswort(Name[])
{
new query[130], Get[130];
mysql_real_escape_string(Name, Name);
format(query, 128, "SELECT `passwort` FROM `accounts` WHERE `Name` = '%s'", Name);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(Get);
mysql_free_result();
return Get;
}
stock LoadPlayer(playerid)
{
if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
{
GetPlayerName(playerid, SpielerInfo[playerid][pName], MAX_PLAYER_NAME);
SpielerInfo[playerid][pLevel] = mysql_GetInt("accounts", "Level", "Name", SpielerInfo[playerid][pName]);
SpielerInfo[playerid][pGeld] = mysql_GetInt("accounts", "Geld", "Name", SpielerInfo[playerid][pName]);
SpielerInfo[playerid][pKills] = mysql_GetInt("accounts", "Kills", "Name", SpielerInfo[playerid][pName]);
SpielerInfo[playerid][pTode] = mysql_GetInt("accounts", "Tode", "Name", SpielerInfo[playerid][pName]);
SpielerInfo[playerid][pAlevel] = mysql_GetInt("accounts","alevel","Name", SpielerInfo[playerid][pName]);
}
return 1;
}
stock mysql_GetInt(Table[], Field[], Where[], Is[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
new sqlint = mysql_fetch_int();
mysql_free_result();
return sqlint;
}
stock mysql_GetString(Table[], Field[], Where[], Is[])
{
new query[128], Get[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(Get);
mysql_free_result();
return Get;
}
stock Float:mysql_GetFloat(Table[], Field[], Where[], Is[])
{
new query[128], Float:sqlfloat;
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_float(sqlfloat);
mysql_free_result();
return sqlfloat;
}
stock SavePlayer(playerid)
{
if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
{
if(GetPVarInt(playerid,"Eingeloggt") == 1)
{
//Nun speichern wir die Daten in der Datenbank.
mysql_SetInt("accounts", "Level", SpielerInfo[playerid][pLevel], "Name", SpielerInfo[playerid][pName]);
mysql_SetInt("accounts", "Geld", SpielerInfo[playerid][pGeld], "Name", SpielerInfo[playerid][pName]);
mysql_SetInt("accounts", "Kills", SpielerInfo[playerid][pKills], "Name", SpielerInfo[playerid][pName]);
mysql_SetInt("accounts", "Tode", SpielerInfo[playerid][pTode], "Name", SpielerInfo[playerid][pName]);
mysql_SetFloat("accounts", "Health", SpielerInfo[playerid][pHealth], "Name", SpielerInfo[playerid][pName]);
mysql_SetInt("accounts", "alevel", SpielerInfo[playerid][pAlevel], "Name", SpielerInfo[playerid][pName]);
}
}
return 1;
}
stock mysql_SetInt(Table[], Field[], To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%d' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_SetString(Table[], Field[], To[], Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(To, To);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%s' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_SetFloat(Table[], Field[], Float:To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%f' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
Mein cveh(auto create befehl) + Savecar
SaveCar(playerid,carid)
{
new query[128];
format(query,sizeof(query),"INSERT INTO autos (besitzer,x,y,z,r,model) VALUES ('%i','%f','%f','%f','%f','%i')",cInfo[playerid][id_x],cInfo[carid][model],cInfo[carid][c_x],cInfo[carid][c_y],cInfo[carid][c_z],cInfo[carid][c_r]);
mysql_query(query);
}
createPlayerCar(playerid,modelid,Float:x,Float:y,Float:z,Float:r)
{
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][id_x]!=0)continue;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,cInfo[i][besitzer],MAX_PLAYER_NAME);
cInfo[i][c_x]=x;
cInfo[i][c_y]=y;
cInfo[i][c_z]=z;
cInfo[i][c_r]=r;
cInfo[i][model]=modelid;
cInfo[i][id_x]=CreateVehicle(modelid,x,y,z,r,-1,-1,-1);
new string[128];
format(string,sizeof(string),"Das Auto cInfo[%i] wurde erstellt!",i);
SendClientMessage(playerid,HELLBLAU,string);
SaveCar(playerid,i);
return 1;
}
return 1;
}
ocmd:cveh(playerid, params[])
{
new mID,pID;
if(!isAdmin(playerid,3)) return SCM(playerid, HELLROT,"Du bist kein Administrator!");
if(sscanf(params,"ui",pID,mID)) return SCM(playerid, GRAU, "[Info] /cveh [playerid] [ID]");
if(mID<400||mID>600)return SCM(playerid, HELLROT, "Falsche CarID!");
new Float:xc,Float:yc,Float:zc,Float:rc;
GetPlayerPos(pID,xc,yc,zc);
GetPlayerFacingAngle(pID,rc);
if(IsPlayerInAnyVehicle(playerid))
{
DestroyVehicle(GetPlayerVehicleID(playerid));
//CreateVehicle(mID,xc,yc,zc,rc,-1,-1,-1);
createPlayerCar(pID,mID,xc,yc,zc,rc);
}
else
//CreateVehicle(mID,xc,yc,zc,rc,-1,-1,-1);
createPlayerCar(pID,mID,xc,yc,zc,rc);
return 1;
}
Ich möchte, dass in der Datenbank als Besitzer auch meine Account ID steht (sprich Besitzer = 220)