[HELP] Vehicle wont spawn
#1

ok, so I'm making a gang gamemode, but I have a problem. I want to make it so a gang member can create car spawns in his own turf. Everything works ok, except the cars aren't getting spawned. It gets spawned with the debug CreateVehicle, but it doesn't get spawned with the timer. I have debugged a lot of things, including the coords and other data in the timers and they are correct. I seriously have no idea what's wrong. Also, I know this code is badly optimized, I will fix that later, I just want the car to be spawned via the timer. Also, GetVehicleModelIDFromName and GetPlayerTurf work correctly.

pawn Код:
dcmd_gangcar(playerid, params[])
{
    new car[20];
    if (sscanf(params, "s", car))
    {
        SendClientMessage(playerid, COLOR_RED, "USAGE: /gangcar [carname]");
        SendClientMessage(playerid, COLOR_RED, "You need to be a turf you own to use this command");
        return 1;
    }
   
    new id = GetVehicleModelIDFromName(car);
    if(id == -1) return SendClientMessage(playerid, COLOR_RED, "That vehicle doesn't exist");
   
    new turf = GetPlayerTurf(playerid);
   
    if(turf == -1) return SendClientMessage(playerid, COLOR_RED, "You must stand in a turf to use this command!");
   
    if(turfs[ turf ][ TurfOwner ] != gRank[ playerid ][ Gang ]) return SendClientMessage(playerid, COLOR_RED, "You   must stand in your own turf to use this command!");
   
   
    MAX_CARS++;
    dini_IntSet("/Gang_System/count.ini", "Cars", MAX_CARS);
   
    new Float:x1, Float:y1, Float:z1, Float:a1;
    GetPlayerPos(playerid, x1, y1, z1);
    GetPlayerFacingAngle(playerid, a1);
   
    CreateVehicle(id, x1, y1, z1, a1, -1, -1, -1);
    SendClientMessage(playerid, COLOR_RED, "Debug car spawn");
    /*THIS CAR SPAWN WORKS*/
   
    if(TurfCars[ turf ][ CarsInTurf ] == 0)
    {
      for(new plid = 0; id < MAX_PLAYERS; id++)
      {
        if(!IsPlayerConnected(plid)) continue;
            if(IsPlayerInVehicle(plid, TurfCars[turf][VehID]))
            {
              RemovePlayerFromVehicle(plid);
              DestroyVehicle(TurfCars[turf][VehID]);
            }
      }
        TurfCars[turf][CarID] = id;
        TurfCars[turf][CarX] = x1;
        TurfCars[turf][CarY] = y1;
        TurfCars[turf][CarZ] = z1;
        TurfCars[turf][CarAngle] = a1;
        TurfCars[ turf ][ CarsInTurf ]++;
       
        SetTimerEx("CarSpawn", 10000, 0, "ddffff",turf,TurfCars[turf][CarID],TurfCars[turf][CarX],TurfCars[turf][CarY],TurfCars[turf][CarZ],TurfCars[turf][CarAngle]);
        SendClientMessage(playerid, COLOR_RED, "A car will be spawned on this location in 10 seconds. Please move to avoid injury");
    }
    else
    {
        for(new plid = 0; id < MAX_PLAYERS; id++)
        {
            if(!IsPlayerConnected(plid)) continue;
            if(IsPlayerInVehicle(plid, TurfCars[turf][Veh2ID]))
            {
              RemovePlayerFromVehicle(plid);
              DestroyVehicle(TurfCars[turf][Veh2ID]);
            }
      }
        TurfCars[turf][CarID2] = id;
        TurfCars[turf][CarX2] = x1;
        TurfCars[turf][CarY2] = y1;
        TurfCars[turf][CarZ2] = z1;
        TurfCars[turf][CarAngle2] = a1;
        TurfCars[turf][ CarsInTurf ] = 0;
        SetTimerEx("CarSpawn2", 10000, 0, "ddffff",turf,TurfCars[turf][CarID2],TurfCars[turf][CarX2],TurfCars[turf][CarY2],TurfCars[turf][CarZ2],TurfCars[turf][CarAngle2]);
        SendClientMessage(playerid, COLOR_RED, "A car will be spawned on this location in 10 seconds. Please move to avoid injury");
    }
   
   
    new File:file = fopen("/Gang_System/cars.txt", io_append);
    new coordsstring[100];
       
    if(TurfCars[ turf ][ CarsInTurf ] == 0)
    {
      format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f\n",
    TurfCars[turf][CarID2],
        TurfCars[turf][CarX2],
        TurfCars[turf][CarY2],
        TurfCars[turf][CarZ2],
        TurfCars[turf][CarAngle2]);
    }
    else if(TurfCars[ turf ][ CarsInTurf ] == 1)
    {
        format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f\n",
        TurfCars[turf][CarID],
        TurfCars[turf][CarX],
        TurfCars[turf][CarY],
        TurfCars[turf][CarZ],
        TurfCars[turf][CarAngle]);
    }
    fwrite(file, coordsstring);
    fclose(file);
    /*THE INFO IN THE FILE IS CORRECT*/
   
    return 1;
   
}

//==============================================================================
forward CarSpawn(turf, carid, carx, cary, carz, carangle);
public CarSpawn(turf, carid, carx, cary, carz, carangle)
{
  TurfCars[turf][VehID] = CreateVehicle(carid, carx, cary, carz, carangle, -1, -1, 360);
    format(msg1, sizeof(msg1), "DEBUG CARSPAWN, etc %d, %f, %f, %f, %f", TurfCars[turf][CarID], TurfCars[turf][CarX], TurfCars[turf][CarY], TurfCars[turf][CarZ], TurfCars[turf][CarAngle]);
    SendClientMessageToAll(COLOR_RED, msg1);
    /*THE MESSAGES ARE SENT, THE COORDS ARE CORRECT*/

}
//==============================================================================
forward CarSpawn2(turf, carid, carx, cary, carz, carangle);
public CarSpawn2(turf, carid, carx, cary, carz, carangle)
{
    TurfCars[turf][Veh2ID] = CreateVehicle(carid, carx, cary, carz, carangle, -1, -1, 360);
    format(msg1, sizeof(msg1), "DEBUG CARSPAWN2, etc %d, %f, %f, %f, %f", TurfCars[turf][CarID], TurfCars[turf][CarX], TurfCars[turf][CarY], TurfCars[turf][CarZ], TurfCars[turf][CarAngle]);
    SendClientMessageToAll(COLOR_RED, msg1);
    /*THE MESSAGES ARE SENT, THE COORDS ARE CORRECT*/
}
//==============================================================================
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)