2025-04-14, 06:09 PM
(2025-03-24, 09:27 AM)Axzyl Wrote: i wanna make sure that vehicle spawns there but respawns every 5 min if its no longer in that position, that players entering any hotdog vehicle can toggle job by pressing 2 that players next to it can buy by pressing left alt. idk why its so complicated
Hello, you have a flag in your script that tells that you "own" a van but you never use it.
In function:
Code:
forward CheckVehiclePositions();
public CheckVehiclePositions()
{
for (new i = 0; i < MAX_VENDORS; i++)
{
new vehicleId = GetPlayerVehicleID(g_Sellers[i]); // we are getting if seller occupied car
if (vehicleId != 0 && g_VehicleIDs[i] == vehicleId) // if it's actually occupied and the id matches the one that was occupied we skip
{
continue;
}
// Check if the vendor vehicle exists at the spawn location
new Float:vehX, Float:vehY, Float:vehZ;
GetVehiclePos(g_VehicleIDs[i], vehX, vehY, vehZ);
// If the vendor vehicle is not at the spawn location
if (floatabs(vehX - (spawnX + (i * 3))) > 10.0 || floatabs(vehY - spawnY) > 10.0 || floatabs(vehZ - spawnZ) > 10.0) // 10 units tolerance
{
// Try to spawn a new vehicle if it doesn't exist at the spawn point
new vehicleid = INVALID_VEHICLE_ID;
// Loop through all possible vehicle IDs (vehicle IDs are indexed from 1)
for (new vehicleIndex = 1; vehicleIndex <= MAX_VEHICLES; vehicleIndex++)
{
vehicleid = vehicleIndex; // Check each vehicle ID
if (vehicleid != INVALID_VEHICLE_ID)
{
new Float:checkX, Float:checkY, Float:checkZ;
GetVehiclePos(vehicleid, checkX, checkY, checkZ);
// If vehicle is within a 10-unit radius of the spawn location
if (floatabs(checkX - (spawnX + (i * 3))) <= 10.0 && floatabs(checkY - spawnY) <= 10.0 && floatabs(checkZ - spawnZ) <= 10.0)
{
// Vehicle is close enough, no need to respawn
vehicleid = INVALID_VEHICLE_ID;
break;
}
}
}
// If no vehicle found at spawn point, spawn a new one
if (vehicleid == INVALID_VEHICLE_ID)
{
g_VehicleIDs[i] = AddStaticVehicle(VEHICLE_MODEL_ID, spawnX + (i * 3), spawnY, spawnZ, spawnAngle, 1, 1);
SendClientMessageToAll(COLOR_YELLOW, "A vendor vehicle has been reset to its original location!");
}
}
}
return 1;
}