SA-MP Forums Archive
Vehicle Spawning Command Help - 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: Vehicle Spawning Command Help (/showthread.php?tid=614151)



Vehicle Spawning Command Help - Tass007 - 05.08.2016

I've made a vehicle spawning command however, once the vehicle explodes or is destroyed it respawns back to the place where the user spawned the vehicle. Is there any way that once a player has spawned a vehicle that it doesn't respawn after it's destroyed? Here is my code.

PHP код:
CMD:vehicle(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 4)
    {
        new 
msg[128], string[200], vehiclename[30], Float:a;
        new 
Float:xFloat:yFloat:z;
        if(
sscanf(params,"s[30]",vehiclename)) return SendClientMessage(playeridCOLOR_WHITE,"Usage: /vehicle [Name]");
        new 
vehicle GetVehicleModelIDFromName(vehiclename);
        if(
vehicle 400 || vehicle 611) return SendClientMessage(playeridCOLOR_RED"Error: Invalid Vehicle Model");
        
GetPlayerFacingAngle(playerida);
        
GetPlayerPos(playeridx,y,z);
        if(
IsPlayerInAnyVehicle(playerid) == 1)
        {
            
GetXYInFrontOfPlayer(playerid,x,y,8);
        }
        else
        {
            
GetXYInFrontOfPlayer(playerid,x,y,5);
        }
        new 
PlayersVehicle CreateVehicle(vehiclexyz+2a+90, -1, -1, -1);
        
LinkVehicleToInterior(PlayersVehicleGetPlayerInterior(playerid));
        
format(string,sizeof(string), "You have spawned a %s"VehicleNames[vehicle 400]);
        
SendClientMessage(playeridCOLOR_BLUEstring);
        
format(msg,sizeof(msg), "[Admin Log]: %s has used the command /vehicle. Spawning a %s"GetName(playerid), VehicleNames[vehicle 400]);
        
ABroadCast(COLOR_ADMINmsg1);
      }
    else
    {
        return 
0;
    }
       return 
1;




Re: Vehicle Spawning Command Help - Threshold - 05.08.2016

https://sampwiki.blast.hk/wiki/OnVehicleDeath
??


Re: Vehicle Spawning Command Help - Tass007 - 05.08.2016

I've considered that, but how would I use it? When spawning the vehicle store it in a variable and then onvehicledeath call the variable? I honestly have no idea.


Re: Vehicle Spawning Command Help - PrO.GameR - 05.08.2016

OVD -> DestroyVehicle(vehicleid);
Although I'm not sure if it works, if it doesn't put same code under OnVehicleSpawn.


Re: Vehicle Spawning Command Help - Tass007 - 05.08.2016

I don't understand how that'll work. Because if I put that under the command isn't it instantly going to destroy the vehicle spawned?


Re: Vehicle Spawning Command Help - jlalt - 05.08.2016

here you go sir
PHP код:
new tempveh[MAX_VEHICLES];
CMD:vehicle(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 4)
    {
        new 
msg[128], string[200], vehiclename[30], Float:a;
        new 
Float:xFloat:yFloat:z;
        if(
sscanf(params,"s[30]",vehiclename)) return SendClientMessage(playeridCOLOR_WHITE,"Usage: /vehicle [Name]");
        new 
vehicle GetVehicleModelIDFromName(vehiclename);
        if(
vehicle 400 || vehicle 611) return SendClientMessage(playeridCOLOR_RED"Error: Invalid Vehicle Model");
        
GetPlayerFacingAngle(playerida);
        
GetPlayerPos(playeridx,y,z);
        if(
IsPlayerInAnyVehicle(playerid) == 1)
        {
            
GetXYInFrontOfPlayer(playerid,x,y,8);
        }
        else
        {
            
GetXYInFrontOfPlayer(playerid,x,y,5);
        }
        new 
PlayersVehicle CreateVehicle(vehiclexyz+2a+90, -1, -1, -1); // <- this will return the id of the created vehicle
        
tempveh[PlayersVehicle] = 1;
        
LinkVehicleToInterior(PlayersVehicleGetPlayerInterior(playerid));
        
format(string,sizeof(string), "You have spawned a %s"VehicleNames[vehicle 400]);
        
SendClientMessage(playeridCOLOR_BLUEstring);
        
format(msg,sizeof(msg), "[Admin Log]: %s has used the command /vehicle. Spawning a %s"GetName(playerid), VehicleNames[vehicle 400]);
        
ABroadCast(COLOR_ADMINmsg1);
      }
    else
    {
        return 
0;
    }
       return 
1;
}
public 
OnVehicleDeath(vehicleid,killerid)
{
   if(
tempveh[vehicleid])
   {
      
DestroyVehicle(vehicleid);
      
tempveh[vehicleid] = 0;
   }
   return 
1;




Re: Vehicle Spawning Command Help - Threshold - 05.08.2016

OnVehicleSpawn is actually called when a vehicle 'respawns', not when it initially spawns like the callback suggests. That could be a more appropriate solution I suppose, but it all depends on what you want.

Just follow something similar to what jlalt posted.


Re: Vehicle Spawning Command Help - PrO.GameR - 05.08.2016

^^
Just put the code under one of those, and it will work, simply because it doesn't get called when vehicle gets created for first time.
Quote:
Originally Posted by Threshold
Посмотреть сообщение
OnVehicleSpawn is actually called when a vehicle 'respawns', not when it initially spawns like the callback suggests. That could be a more appropriate solution I suppose, but it all depends on what you want.

Just follow something similar to what jlalt posted.
If he got only this one system for spawning vehicles there is no need to keep track of which are temporary vehicles.


Re: Vehicle Spawning Command Help - Threshold - 05.08.2016

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
^^
Just put the code under one of those, and it will work, simply because it doesn't get called when vehicle gets created for first time.


If he got only this one system for spawning vehicles there is no need to keep track of which are temporary vehicles.
Sure, that's possible, but you can't assume...