createPlayerCar(playerid,ownerid,modelid,Float:x,Float:y,Float:z,Float:r,Color1,Color2)
{
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][VCarID]!=-1)continue;
strmid(cInfo[i][besitzer], GetName(ownerid), 0, MAX_PLAYER_NAME, 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][VCarID] = i;
cInfo[i][VCarID] = CreateVehicle(modelid,x,y,z,r,Color1,Color2,-1);
new string[128];
format(string,sizeof(string),"Das Auto cInfo[%i] wurde erstellt.",i);
SendClientMessageToAll(COLOR_RED,string);
SaveCarToDB(playerid,i);
return 1;
}
return 1;
}
ocmd:createcar(playerid,params[])
{
new mid,pid;
if(sscanf(params,"ui", pid,mid)) return SendClientMessage(playerid,COLOR_RED,"/createcar [ID] [CarID]");
new Float:xc,Float:yc,Float:zc,Float:rc;
GetPlayerPos(pid,xc,yc,zc);
GetPlayerFacingAngle(pid,rc);
createPlayerCar(playerid,pid,mid,xc,yc,zc,rc,0,0);
return 1;
}
SaveCarToDB(playerid,carid)
{
new query[512];
format(query, sizeof(query),"INSERT INTO `PlayerVehs` (carid,modelid, carposx, carposy, carposz,carposr, Color1, Color2,besitzer) VALUES ('%i','%i','%f', '%f', '%f','%f','%d','%d', '%s')",
cInfo[carid][dbCarID],cInfo[carid][model], cInfo[carid][c_x],cInfo[carid][c_y],cInfo[carid][c_z],cInfo[carid][c_r],cInfo[carid][VColor1],cInfo[carid][VColor2],cInfo[carid][besitzer]);
mysql_pquery(handle, query, "OnVehicleCreated", "di", playerid,carid);
return 1;
}
forward OnVehicleCreated(playerid,carid);
public OnVehicleCreated(playerid,carid)
{
// carid=cache_insert_id();
//cInfo[carid][VCarID] = carid;
cInfo[carid][dbCarID]=cache_insert_id();
printf("Das Auto %i wurde erfolgreich von playerid %i erstellt",carid,playerid);
}
OnUserLogin
new query[256];
mysql_format(handle, query, sizeof(query), "SELECT * FROM PlayerVehs WHERE besitzer = '%e'", GetName(playerid));
mysql_pquery(handle, query, "OnPlayerCarsLoad", "d", playerid);
OnGameModeInit
for(new i = 0; i < sizeof(cInfo); i++)
{
cInfo[i][VCarID] = -1;
}
forward OnPlayerCarsLoad(playerid); // bei Login
public OnPlayerCarsLoad(playerid)
{
new num_rows;
cache_get_row_count(num_rows);
if(!num_rows)return 1;
for(new i; i<num_rows; i++)
{
new id=getFreeCarID();
cache_get_value_name_int(i, "carid", cInfo[id][dbCarID]);
cache_get_value_name(i, "besitzer", cInfo[id][besitzer], MAX_PLAYER_NAME);
cache_get_value_name_int(i, "modelid", cInfo[id][model]);
cache_get_value_name_float(i, "carposx", cInfo[id][c_x]);
cache_get_value_name_float(i, "carposy", cInfo[id][c_y]);
cache_get_value_name_float(i, "carposz", cInfo[id][c_z]);
cache_get_value_name_float(i, "carposr", cInfo[id][c_r]);
cache_get_value_name_int(i, "Color1", cInfo[id][VColor1]);
cache_get_value_name_int(i, "Color2", cInfo[id][VColor2]);
cInfo[i][VCarID] = CreateVehicle(cInfo[id][model],cInfo[id][c_x],cInfo[id][c_y],cInfo[id][c_z],cInfo[id][c_r],cInfo[id][VColor1],cInfo[id][VColor2],-1);
}
return 1;
}
getFreeCarID()
{
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][VCarID]==-1) return i;
}
return -1;
}
public OnPlayerDisconnect(playerid, reason)
{
//DisarmBis
if(PlayerInfo[playerid][pLoggedIn] == false) return 1;
KillTimer(DisArmTimerForPlayer[playerid]);
KillTimer(DisArmerOnline[playerid]);
for(new i = 0; i < sizeof(cInfo); i++)
{
if(cInfo[i][VCarID] == -1) continue;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
// if(strlen(cInfo[i][besitzer] != name)) continue;
if(strcmp(cInfo[i][besitzer], name, false)) continue;
new Float:vehx, Float:vehy, Float:vehz,Float:vehr;
GetVehiclePos(cInfo[i][VCarID], vehx, vehy, vehz);
GetVehicleZAngle(cInfo[i][VCarID], vehr);
new query[128];
mysql_format(handle, query, sizeof(query), "UPDATE PlayerVehs SET carposx='%f', carposy = '%f', carposz = '%f', carposr = '%f' WHERE carid = '%d'",vehx,vehy,vehz,vehr,cInfo[i][dbCarID]);
mysql_pquery(handle, query, "VehicleDisFinished");
DestroyVehicle(cInfo[i][VCarID]);
printf(query);
cInfo[i][VCarID] = -1;
}
SaveUserStats(playerid);
return 1;
}
forward VehicleDisFinished();
public VehicleDisFinished()
{
printf("Vehicle abgespeichert");
}
Seperat auf https://pastebin.com/gsXqQDwj