SA-MP Forums Archive
/veh destroys vehicle while entering - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: /veh destroys vehicle while entering (/showthread.php?tid=145204)



/veh destroys vehicle while entering - Andy_McKinley - 01.05.2010

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;
}



Re: /veh destroys vehicle while entering - [MWR]Blood - 01.05.2010

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


Re: /veh destroys vehicle while entering - Andy_McKinley - 01.05.2010

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


Re: /veh destroys vehicle while entering - M4S7ERMIND - 01.05.2010

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;
}



Re: /veh destroys vehicle while entering - Miguel - 01.05.2010

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;
}



Re: /veh destroys vehicle while entering - Andy_McKinley - 01.05.2010

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


Re: /veh destroys vehicle while entering - Miguel - 01.05.2010

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 ).