/veh destroys vehicle while entering
#1

My /veh (dcmd) admin command (spawning vehicles) is working and vehicles are destroying after 50 seconds, but, it's destroying when someone's is in the vehicle... I don't know what's the problem so I hope anyone can help me or correct the script. Btw, if I enter a Hydra and crash, it respawns at the spawned position, I don't want that... Anyway.

pawn Код:
forward DestroyVehicleEx(iVehicleID);
public DestroyVehicleEx(iVehicleID)
{
    for(new i=0;i<=MAX_PLAYERS;i++)
    {
      if(GetPlayerVehicleID(i) != iVehicleID)
            DestroyVehicle(iVehicleID);
    }
}

dcmd_veh(playerid, params[])
{
    new vehicleid, color[2], myString[128];

    if(pInfo[playerid][pAdmin] < 4) return SystemMessage(playerid, "You are not an Administrator with the required level.");
    if(sscanf(params,"ddd",vehicleid,color[0],color[1])) return SystemMessage(playerid, "USAGE: /veh [vehicleid] [color1] [color2]");
    else
    {
      if(vehicleid < 400 || vehicleid > 611) return SystemMessage(playerid, "Please enter a valid vehicle ID (400 - 611).");
        if((color[0] < 0 || color[0] > 128) || (color[1] < 0 || color[1] > 128)) return SystemMessage(playerid, "Please enter valid color IDs (0-128).");

        new Float:PosX, Float:PosY, Float:PosZ, Float:Angle;
        GetPlayerPos(playerid, PosX, PosY, PosZ);
        GetPlayerFacingAngle(playerid, Angle);

        new iID = AddStaticVehicle(vehicleid, PosX+1, PosY+1, PosZ, Angle, color[0], color[1]);
        SetTimerEx("DestroyVehicleEx", 50000, 1, "d", iID);

        format(myString, sizeof(myString), "You have spawned vehicle id %i.",vehicleid);
        SystemMessage(playerid, myString);
    }
    return 1;
}
Reply
#2

pawn Код:
SetTimerEx("DestroyVehicleEx", 50000, 1, "d", iID);
Remove it.
Reply
#3

Quote:
Originally Posted by ikarus❶❸❸❼
pawn Код:
SetTimerEx("DestroyVehicleEx", 50000, 1, "d", iID);
Remove it.
But I do want to destroy vehicle!
Reply
#4

pawn Код:
public DestroyVehicleEx(vehicleid)
{
  if(!IsVehicleOccupied(vehicleid))
  {
    DestroyVehicle(vehicleid);
    //KillTimer
  }
}
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
  for(new i; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      if(IsPlayerInVehicle(i, vehicleid)) return 1;
    }
  }
  return 0;
}
Reply
#5

First of all, you're creating a vehicle from a local variable, which means it can't be destroyed from a function out of that command, except when you use SetTimerEx.

After you created the vehicle you set a timer which was gonna destroy it, but how do you stop it

pawn Код:
if(GetPlayerVehicleID(i) != iVehicleID) DestroyVehicle(iVehicleID);
That's wrong, because what would happen if just one player has the vehicle, then it will be destroyed 500 times - 1 (haha).

THE FIX:
pawn Код:
new MyVehicle[MAX_PLAYERS];
new MyVehTimer[MAX_PLAYERS];
pawn Код:
dcmd_veh(playerid, params[])
{
  // all your stuff to check and w/e
  MyVehicle[playerid] = CreateVehicle(a, b, c, d, e, f, whatever);
  MyVehTime[playerid] = SetTimerEx("DestroyVehicleEx", 1000, true, "i", playerid);
  return 1;
}
pawn Код:
forward DestroyVehicleEx(playerid);
public DestroyVehicleEx(playerid)
{
  static
    timewithoutit;
  new
    doyouhave;

  for(new i = 0; i < MAX_PLAYERS; i ++)
  {
    if(GetPlayerVehicle(i) == MyVehicle[playerid])
    {
      doyouhave ++;
      break;
    }
  }
  if(doyouhave < 1)
  {
    timewithoutit ++;
    if(timewithoutit > 49)
    {
      DestroyVehicle(MyVehicle[playerid]);
      KillTimer(MyVehTimer[playerid]);
    }
  }
  else timewithoutit = 0;
  return 1;
}
Reply
#6

I don't get it guys, it's too complicated now... I see my script and yours, which one is right?
Reply
#7

Both of them are right, though they work different. Mine will destroy the vehicle 50 seconds after it's empty and Mастерминд version will destroy it if there's nobody when the timer checked it.

Btw: http://pawn.pastebin.com/ZhxHxY6Y (check it out ).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)