SA-MP Forums Archive
Destroy - 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)
+--- Thread: Destroy (/showthread.php?tid=554150)



Destroy - Desha1 - 02.01.2015

Hello Guys
Guys i want know somthings When im Spawn Vehicle /v
i Want the old Vehicle Destroy



AW: Destroy - CutX - 02.01.2015

Quote:
Originally Posted by Desha1
Посмотреть сообщение
Hello Guys
Guys i want know somthings When im Spawn Vehicle /v
i Want the old Vehicle Destroy
you would have to save that vehicle id somewhere
if you want the old veh. to be destroyed when you spawn a new one.

lets say we have a small cmd to spawn some cars
we also have 1 var
pawn Код:
new myVeh[MAX_PLAYERS];
if we want this to work, we have to
write the vehicle id of the car we spawned into "myVeh"
and also check if theres already a id so we can destroy the old one.
pawn Код:
//inside that cmd:
if(myVeh[playerid]) DestroyVehicle(myVeh[playerid]);
myVeh[playerid] = CreateVehicle(//and so on...
//...
it first checks if there's already a vehicle id and if there is, destroy it
and then create the new vehicle.
like this, the old one will always be destroyed once you spawn a new one


Re: Destroy - ATGOggy - 02.01.2015

PHP код:
new vehicle[MAX_PLAYERS]; 
PHP код:
 public OnPlayerCommandText(playeridcmdtext)
{
   if(!
IsPlayerAdmin....// Some checks
 
   
Destroyveh(vehicle[playerid]);
   
vehicle[playerid]=CreateVehicle(//...........
   
return 1;




Re: Destroy - Desha1 - 02.01.2015

i Can Spawn 50000 Vehicle not fixed
this my full code spawn vehicle
PHP код:
CMD:v(playeridparams[])
{
if(
PlayerInfo[playerid][pRank] >= && PlayerInfo[playerid][pRank] <= 8)
{
        new 
Vehicle[50];
        if(!
sscanf(params"s[50]"Vehicle))
        {
                if(
Myveh[playerid]) DestroyVehicle(Myveh[playerid]);
                new 
string[128], Float:Pos[4];
                
GetPlayerPos(playeridPos[0],Pos[1],Pos[2]); GetPlayerFacingAngle(playeridPos[3]);
                new 
veh GetVehicleModelID(Vehicle);
                if(
veh 400 || veh 611) return SendClientMessage(playeridCOLOR_RED"This is not a valid vehicle name! Please try again ");
                if(
IsPlayerInAnyVehicle(playerid)) { DestroyVehicle(GetPlayerVehicleID(playerid)); }
                
GetXYInFrontOfPlayer(playeridPos[0], Pos[1], 5);
                new 
PVeh CreateVehicle(vehPos[0], Pos[1], Pos[2], Pos[3]+90, -1, -1, -1);
                
LinkVehicleToInterior(PVehGetPlayerInterior(playerid)); SetVehicleVirtualWorld(PVehGetPlayerVirtualWorld(playerid));
                
format(stringsizeof string"You spawned a %s. ID: %i. "aVehicleNames[veh 400], veh);
                
SendClientMessage(playeridCOLOR_GREENstring);
        }
        } else return 
SendClientMessage(playeridCOLOR_LIGHTGREEN"Usage: /v [vehiclename] ");
return 
1;




AW: Re: Destroy - CutX - 02.01.2015

Quote:
Originally Posted by Desha1
Посмотреть сообщение
i Can Spawn 50000 Vehicle not fixed
this my full code spawn vehicle
PHP код:
CMD:v(playeridparams[])
{
if(
PlayerInfo[playerid][pRank] >= && PlayerInfo[playerid][pRank] <= 8)
{
        new 
Vehicle[50];
        if(!
sscanf(params"s[50]"Vehicle))
        {
                if(
Myveh[playerid]) DestroyVehicle(Myveh[playerid]);
                new 
string[128], Float:Pos[4];
                
GetPlayerPos(playeridPos[0],Pos[1],Pos[2]); GetPlayerFacingAngle(playeridPos[3]);
                new 
veh GetVehicleModelID(Vehicle);
                if(
veh 400 || veh 611) return SendClientMessage(playeridCOLOR_RED"This is not a valid vehicle name! Please try again ");
                if(
IsPlayerInAnyVehicle(playerid)) { DestroyVehicle(GetPlayerVehicleID(playerid)); }
                
GetXYInFrontOfPlayer(playeridPos[0], Pos[1], 5);
                new 
PVeh CreateVehicle(vehPos[0], Pos[1], Pos[2], Pos[3]+90, -1, -1, -1);
                
LinkVehicleToInterior(PVehGetPlayerInterior(playerid)); SetVehicleVirtualWorld(PVehGetPlayerVirtualWorld(playerid));
                
format(stringsizeof string"You spawned a %s. ID: %i. "aVehicleNames[veh 400], veh);
                
SendClientMessage(playeridCOLOR_GREENstring);
        }
        } else return 
SendClientMessage(playeridCOLOR_LIGHTGREEN"Usage: /v [vehiclename] ");
return 
1;

it appears that you did not read correctly.
this line:
pawn Код:
new PVeh = CreateVehicle(veh, Pos[0], Pos[1], Pos[2], Pos[3]+90, -1, -1, -1);
is wrong, you have to write the vehicle id in "myVeh" so that we can destroy it later on
just as said before
Quote:
Originally Posted by CutX
Посмотреть сообщение
pawn Код:
//inside that cmd:
if(myVeh[playerid]) DestroyVehicle(myVeh[playerid]);
myVeh[playerid] = CreateVehicle(//and so on...
//...
of course nothing changes if you never ever actually write something
to "myVeh" that should be obvious.


Re: Destroy - Desha1 - 02.01.2015

i dont need to change my cmd
i want only add i told u it