21.06.2015, 04:12
Hi, i'am using a system that when you doing /myvehicles you got a list of your vehicles and when you click one of your vehicles it will be spawned, but me i want to make all players vehicles spawn when he connect to the server, please help , this is the code of the dialog when you choose your vehicles
this is the thread to load player vehicles when he connect
this is when player logged in ( load stats and load the vehicles ) :
Thank's for reading.
PHP код:
case DIALOG_VEHICLEMANAGE:
{
new
szOutput[128];
if(response) {
if(VehicleInfo[playerid][listitem][Spawned] == 0) { // Stored
if(VehicleInfo[playerid][listitem][Disabled] != 0) {
switch(VehicleInfo[playerid][listitem][Disabled])
{
case 1: szOutput = "This vehicle is currently impounded by the LSPD.";
case 2: szOutput = "This vehicle is currently repossessed by the GOV.";
case 3: szOutput = "This vehicle is currently disabled by an Admin.";
}
SendPlayerMessage(playerid, szOutput);
return 1;
}
VehicleInfo[playerid][listitem][Spawned] = 1;
VehicleInfo[playerid][listitem][VehicleID] = CreateVehicle(VehicleInfo[playerid][listitem][ModelID], VehicleInfo[playerid][listitem][Pos][0], VehicleInfo[playerid][listitem][Pos][1], VehicleInfo[playerid][listitem][Pos][2], VehicleInfo[playerid][listitem][Pos][3], VehicleInfo[playerid][listitem][Colours][0], VehicleInfo[playerid][listitem][Colours][1], -1);
SetVehicleHealth(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Health]);
for(new m = 0; m < 16; m++) { AddVehicleComponent(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Mods][m]); }
if(VehicleInfo[playerid][listitem][PaintJob] != -1) { ChangeVehiclePaintjob(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][PaintJob]); }
SendPlayerMessage(playerid, "You have spawned that vehicle.");
iVehicleFuel[VehicleInfo[playerid][listitem][VehicleID]] = VehicleInfo[playerid][listitem][Fuel];
iVehicleMileage[VehicleInfo[playerid][listitem][VehicleID]] = VehicleInfo[playerid][listitem][Mileage];
}
else { // Spawned
VehicleInfo[playerid][listitem][Fuel] = iVehicleFuel[VehicleInfo[playerid][listitem][VehicleID]];
VehicleInfo[playerid][listitem][Mileage] = iVehicleMileage[VehicleInfo[playerid][listitem][VehicleID]];
GetVehicleHealth(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Health]);
VehicleInfo[playerid][listitem][Spawned] = 0;
DestroyVehicle(VehicleInfo[playerid][listitem][VehicleID]);
VehicleInfo[playerid][listitem][VehicleID] = -1;
SendPlayerMessage(playerid, "You have stored that vehicle.");
}
}
}
PHP код:
case THREAD_LOAD_PVEHICLES:
{
if(IsPlayerConnected(extraid))
{
new i = 0;
while(i < cache_num_rows())
{
if(i >= MAX_PLAYER_VEHICLES)
break;
cache_get_field_content(i, "model", Result, iConnection); VehicleInfo[extraid][i][ModelID] = strval(Result);
cache_get_field_content(i, "slot_id", Result, iConnection); VehicleInfo[extraid][i][SlotID] = strval(Result);
if(VehicleInfo[extraid][i][ModelID] != 0)
{
cache_get_field_content(i, "plate", Result, iConnection); format(VehicleInfo[extraid][i][Plate], 6, "%s", Result);
cache_get_field_content(i, "colour1", Result, iConnection); VehicleInfo[extraid][i][Colours][0] = strval(Result);
cache_get_field_content(i, "colour2", Result, iConnection); VehicleInfo[extraid][i][Colours][1] = strval(Result);
cache_get_field_content(i, "interior", Result, iConnection); VehicleInfo[extraid][i][Interior] = strval(Result);
cache_get_field_content(i, "vw", Result, iConnection); VehicleInfo[extraid][i][VW] = strval(Result);
cache_get_field_content(i, "paintjob", Result, iConnection); VehicleInfo[extraid][i][PaintJob] = strval(Result);
cache_get_field_content(i, "tickets", Result, iConnection); VehicleInfo[extraid][i][Tickets] = strval(Result);
cache_get_field_content(i, "mileage", Result, iConnection); VehicleInfo[extraid][i][Mileage] = strval(Result);
cache_get_field_content(i, "insurance", Result, iConnection); VehicleInfo[extraid][i][Insurance] = strval(Result);
cache_get_field_content(i, "disabled", Result, iConnection); VehicleInfo[extraid][i][Disabled] = strval(Result);
cache_get_field_content(i, "fuel", Result, iConnection); VehicleInfo[extraid][i][Fuel] = floatstr(Result);
cache_get_field_content(i, "health", Result, iConnection); VehicleInfo[extraid][i][Health] = floatstr(Result);
cache_get_field_content(i, "pos_x", Result, iConnection); VehicleInfo[extraid][i][Pos][0] = floatstr(Result);
cache_get_field_content(i, "pos_y", Result, iConnection); VehicleInfo[extraid][i][Pos][1] = floatstr(Result);
cache_get_field_content(i, "pos_z", Result, iConnection); VehicleInfo[extraid][i][Pos][2] = floatstr(Result);
cache_get_field_content(i, "pos_a", Result, iConnection); VehicleInfo[extraid][i][Pos][3] = floatstr(Result);
for(new m = 0; m < 16; m++) {
format(Label, sizeof(Label), "mod%d", m+1);
cache_get_field_content(i, Label, Result, iConnection); VehicleInfo[extraid][i][Mods][m] = strval(Result);
}
if(VehicleInfo[extraid][i][Health] < 300) VehicleInfo[extraid][i][Health] = 300;
format(Query, sizeof(Query), "SELECT * FROM `vehicle_storage` WHERE `vehicle_id` = %d AND `owner_id` = %d", i, GetPlayerSQLID(extraid));
mysql_function_query(iConnection, Query, true, "OnQueryFinish", "ii", THREAD_LOAD_VSTORAGE, i);
}
else { // Invalid vehicle - remove it!
format(Query, sizeof(Query), "DELETE FROM `player_vehicles` WHERE `slot_id` = %d AND `account_id` = %d", VehicleInfo[extraid][i][SlotID], GetPlayerSQLID(extraid));
mysql_function_query(iConnection, Query, false, "OnQueryFinish", "ii", THREAD_NO_QUERY, extraid);
}
i++;
}
}
}
PHP код:
format(szQuery, sizeof(szQuery), "SELECT * FROM `player_vehicles` WHERE `account_id` = %d", GetPlayerSQLID(playerid));
mysql_tquery(iConnection, szQuery, "OnQueryFinish", "ii", THREAD_LOAD_PVEHICLES, playerid);