public OnPlayerConnect(playerid)
{
LoadVehicleForPlayer(playerid);
return 1;
}
stock LoadVehicleForPlayer(playerid)
{
mysql_function_query(mysql, "SELECT * FROM `pvehicles`", true,"OnPlayerLoadVehicles", ""); // we won't pass any other variables to the callback
return 1;
}
forward OnPlayerLoadVehicles(playerid);
public OnPlayerLoadVehicles(playerid)
{
new
idx,
result[256],
query[128];
new id,owner,model,col1,col2,Float:sx,Float:sy,Float:sz,Float:sa;
new name[MAX_PLAYER_NAME], Str[250];
GetPlayerName(playerid, name, 24);
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `pvehicles` WHERE `vOwner` = '%s'", name);
mysql_query(mysql, query, "", "");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Str))
{
sscanf(Str, "p<|>is[24]iiiffff", id, owner, model, col1, col2, sx, sy, sz, sa);
VehicleInfo[idx][vID] = id;
VehicleInfo[idx][vOwner] = owner;
VehicleInfo[idx][vModel] = model;
VehicleInfo[idx][vColor1] = col1;
VehicleInfo[idx][vColor2] = col2;
VehicleInfo[idx][vX] = sx;
VehicleInfo[idx][vY] = sy;
VehicleInfo[idx][vZ] = sz;
VehicleInfo[idx][vA] = sa;
CreateVehicle(model, sx, sy, sz, sa, col1, col2, -1);
//SetVehicleNumberPlate(i, str);
SetVehicleToRespawn(idx);
idx++; // Now increment our index!
}
}
mysql_free_result();
return 1;
}
//------------------------------------------------------------------------------
public OnPlayerConnect(playerid) { static query[128]; mysql_format(mysql, query, sizeof(query), "SELECT * FROM `pvehicles` WHERE `vOwner` = '%s'", name); mysql_function_query(mysql, query, true,"OnPlayerLoadVehicles", "i",playerid); return 1; }
You never passed playerid to mysql_function_query.The OnPlayerLoadVehicles Callback will be called with random playerid(could be 0 , I am not sure).
You don't need another function to call a function and needn't select all vehicles.Just directly fetch the player's vehicles. Код:
public OnPlayerConnect(playerid) { static query[128]; mysql_format(mysql, query, sizeof(query), "SELECT * FROM `pvehicles` WHERE `vOwner` = '%s'", name); mysql_function_query(mysql, query, true,"OnPlayerLoadVehicles", "i",playerid); return 1; } |