Vehicle Spawning Command Help
#1

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;

Reply
#2

https://sampwiki.blast.hk/wiki/OnVehicleDeath
??
Reply
#3

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.
Reply
#4

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

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?
Reply
#6

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;

Reply
#7

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.
Reply
#8

^^
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.
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)