Anti vehicle respawn: Is this possible?
#1

Hello,

I am creating a carshop script. When I buy a car, it all goes succesfull. When my vehicle gets killed, it respawn to the place where I bought it (because it spawns there). Is there a way to disable vehicle respawn?

Regards, Jochem
Reply
#2

Do you want it to be deleted? Or respawn at the place it exploded?
Reply
#3

It needs to be deleted.
Reply
#4

pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
    SetTimerEx("ResetCar", 5000, 0,"d", vehicleid); // We make this, that the vehicle will explode before getting deleted.
    return 1;
}
At bottom of your script:

pawn Код:
forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
Its untested, but it should work, if i didnt made any stupid mistakes.

Greetz.
Reply
#5

Is it also possible that this only works for buyed cars only?
Reply
#6

Can you post your shop (car buy thingy) code?
Reply
#7

I am still scripting it, there isnt really much in it and it is unfinished

http://pastebin.com/8ALzy0Nk
Reply
#8

It is possible, but its hard to make. I made it on my server, took me some time.
But, I could make it for you.
Give me time till Wednesday.
Reply
#9

Okay, I made a function. I tested it shortly and it worked.
You should add the "ShopCarSpawner" function at every case where you want the car to be removed after its explosion.

pawn Код:
new csp;
#define FILTERSCRIPT
#define COLOR_RED 0xFF0000AA
#define COLOR_GREEN 0x00FF00AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_YELLOW 0xFFFF00AA
#define CarMenuID 3745
#define FastCars 3746
#define Bikes 3747
#define Boats 3748
#define Planes 3749
#define MAX_SHOP_CARS 2000

#include <a_samp>

#if defined FILTERSCRIPT

new ShopCar[MAX_SHOP_CARS];
new ShopCarExists[MAX_SHOP_CARS];

public OnFilterScriptInit()
{
    csp = CreatePickup(1318, 23, -1975.4729,289.0419,35.1719,-1);
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{

}

#endif

public OnPlayerRequestClass(playerid, classid)
{

    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
for(new i=0; i<MAX_SHOP_CARS; i++)
    {
    if(vehicleid==ShopCar[i])
    {
    SetTimerEx("ResetCar", 5000, 0,"d", vehicleid); // We make this, that the vehicle will explode before getting deleted.
    return 1;
    }
    }
   
return 1;
}

forward ResetCar(vehicleid);
public ResetCar(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/carmenu", true))
{
  ShowPlayerDialog(playerid, CarMenuID, DIALOG_STYLE_LIST, "Car buy shop", "Premier ($1000)\nInfernus ($9500)\nStafford ($2555)", "Buy car", "Quit");
  return 1;
}
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == csp)
  ShowPlayerDialog(playerid, CarMenuID, DIALOG_STYLE_LIST, "Wang Cars Carshop", "Fast Cars\nBikes\nBoats\nPlanes", "Select genre", "Quit");
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new Float: x;
    new Float: y;
    new Float: z;
  // We SHOULD use switch(dialogid) with cases, but we're only going to use one dialog in this tutorial.
  if(dialogid == CarMenuID && response) // If the dialogid is 1 (our dialog) and they pressed 'Purchase'
  {
    // We'll use the switch/cases now because we're going to process a few results, not just one. Remember, the first item in the list has id 0.
    switch(listitem)
    {
      case 0:
      {
        ShowPlayerDialog(playerid, FastCars, DIALOG_STYLE_LIST, "Wang Cars Carshop", "Jester\nInfernus\nEuros\nBullet", "Select genre", "Quit");
        return SendClientMessage(playerid, COLOR_YELLOW, "You selected 'Fast Cars");
      }
      case 1:
      {
        if(GetPlayerMoney(playerid) < 9500) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        GivePlayerMoney(playerid, -9500);
        PutPlayerInVehicle(playerid,411,0);
      }
      case 2:
      {
        if(GetPlayerMoney(playerid) < 2555) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
        GivePlayerMoney(playerid, -2555);
        PutPlayerInVehicle(playerid,580,0);
      }
    }
    return 1;
  }
  if(dialogid == FastCars && response) // If the dialogid is 1 (our dialog) and they pressed 'Purchase'
  {
    // We'll use the switch/cases now because we're going to process a few results, not just one. Remember, the first item in the list has id 0.
    switch(listitem)
    {
      case 0:
      {
        if(GetPlayerMoney(playerid) < 50000) return SendClientMessage(playerid,COLOR_RED,"You don't have $50000!");
        GivePlayerMoney(playerid,-50000);
        ShopCarSpawner(playerid,559);  //The magic function.
        return SendClientMessage(playerid, COLOR_YELLOW, "You bought a Jester!");
      }
      case 1:
      {
        ShopCarSpawner(playerid,411);
        GivePlayerMoney(playerid,-50500);
        return SendClientMessage(playerid, COLOR_YELLOW, "You bought an Infernus!");
      }
      case 2:
      {
        GetPlayerPos(playerid,x,y,z);
        GivePlayerMoney(playerid,-34000);
        CreateVehicle(587,x+2,y+2,z+2,0,0,0,0);
        return SendClientMessage(playerid, COLOR_YELLOW, "You bought an Euros!");
      }
      case 3:
      {
        GetPlayerPos(playerid,x,y,z);
        GivePlayerMoney(playerid,-45005);
        CreateVehicle(541,x+2,y+2,z+2,0,0,0,0);
        return SendClientMessage(playerid, COLOR_YELLOW, "You bought a Bullet!");
            }
    }
  }
  return 1;
}

forward ShopCarSpawner(playerid, vehicleid);
public ShopCarSpawner(playerid, vehicleid)
{
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid,x,y,z);
    GetPlayerFacingAngle(playerid, a);
   
    for(new i=0; i<MAX_SHOP_CARS; i++)
        {
        if(ShopCarExists[i]!=1)
          {
          ShopCar[i]=CreateVehicle(vehicleid,x,y,z,a,-1,-1,-1);
          ShopCarExists[i]=1;
          PutPlayerInVehicle(playerid, ShopCar[i],0);
          return 1;
          }
        }
   
    return 1;
}


public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Try it if it works for you.
Would be nice if you tell me if it works.

Jeffry
Reply
#10

He's asking for a vehicle removal on respawn - not when it 'dies'. Additionally I have no idea why you're using a timer.

Код:
static n_aVehiclePurchased[MAX_VEHICLES] = {0, ...};  // Flag to determine a vehicle is purchased

// When you create your vehicle, assign the relevant array iteration to the vehicle ID.
n_aVehiclePurchased[CreateVehicle(model, x, y, z, rot, color, color2, respawntime)] = 1;


// Now just check when the vehicle respawns if it's a purchased one. If so remove it.
public OnVehicleRespawn(vehicleid)
{
  if(!n_aVehiclePurchased[vehicleid])
    return;
  
  n_aVehiclePurchased = 0;
  DestroyVehicle(vehicleid);
  
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)