Need help with car spawner
#1

i mad a car spawner command and its 100% working,but i have 1 small problem why when i spawn a car and the car got damage(caught fire and blow up)it respawns at the place/position you spawned it.Im wondering if there is a way to stop that from happening
Reply
#2

Show your code
Reply
#3

pawn Код:
COMMAND:car(playerid,params[])
{
    if(AdminLevel[playerid] >= 3)
    {
        new car;
        if(IsPlayerInAnyVehicle(playerid)) return 1;
        if(sscanf(params, "i", car)) return SendClientMessage(playerid, COLOR_RED, "USE: /car [car id]");
        if(strval(params) >611 || strval(params) <400) return SendClientMessage(playerid, COLOR_RED, "That id doesn't exist[400-611]");
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x,y,z);
        GetPlayerFacingAngle(playerid, a);
        car = CreateVehicle(strval(params), x, y, z,a, -1, -1, 60);
        PutPlayerInVehicle(playerid, car, 0);
    }
    else SendClientMessage(playerid,COLOR_RED,"You need to be an level 3 admin to use this command");
    return 1;
}
Reply
#4

car = CreateVehicle(strval(params), x, y, z,a, -1, -1, -1);
This will prevent the car from respawning. Just replaced the 60 seconds time delay to -1.

Hope it solves your problem.
Reply
#5

Quote:
Originally Posted by DavidBilla
Посмотреть сообщение
car = CreateVehicle(strval(params), x, y, z,a, -1, -1, -1);
This will prevent the car from respawning. Just replaced the 60 seconds time delay to -1.

Hope it solves your problem.
doesnt work any other suggestion
Reply
#6

You can test this, it surely will work:

PHP код:
new CarToDestroy[MAX_VEHICLES];
COMMAND:car(playerid,params[])
{
    if(
AdminLevel[playerid] >= 3)
    {
        new 
car;
        if(
IsPlayerInAnyVehicle(playerid)) return 1;
        if(
sscanf(params"i"car)) return SendClientMessage(playeridCOLOR_RED"USE: /car [car id]");
        if(
strval(params) >611 || strval(params) <400) return SendClientMessage(playeridCOLOR_RED"That id doesn't exist[400-611]");
        new 
Float:xFloat:yFloat:zFloat:a;
        
GetPlayerPos(playeridx,y,z);
        
GetPlayerFacingAngle(playerida);
        
CarToDestroy[car] = CreateVehicle(strval(params), xyz,a, -1, -160);
        
PutPlayerInVehicle(playeridCarToDestroy[car], 0);
    }
    else 
SendClientMessage(playerid,COLOR_RED,"You need to be an level 3 admin to use this command");
    return 
1;
}
public 
OnVehicleSpawn(vehicleid)
{
    for(new 
iMAX_VEHICLESi++)
    {
        if(
vehicleid == CarToDestroy[i])
        {
            
DestroyVehicle(vehicleid);
            break;
        }
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
You can test this, it surely will work:

PHP код:
new CarToDestroy[MAX_VEHICLES];
COMMAND:car(playerid,params[])
{
    if(
AdminLevel[playerid] >= 3)
    {
        new 
car;
        if(
IsPlayerInAnyVehicle(playerid)) return 1;
        if(
sscanf(params"i"car)) return SendClientMessage(playeridCOLOR_RED"USE: /car [car id]");
        if(
strval(params) >611 || strval(params) <400) return SendClientMessage(playeridCOLOR_RED"That id doesn't exist[400-611]");
        new 
Float:xFloat:yFloat:zFloat:a;
        
GetPlayerPos(playeridx,y,z);
        
GetPlayerFacingAngle(playerida);
        
CarToDestroy[car] = CreateVehicle(strval(params), xyz,a, -1, -160);
        
PutPlayerInVehicle(playeridCarToDestroy[car], 0);
    }
    else 
SendClientMessage(playerid,COLOR_RED,"You need to be an level 3 admin to use this command");
    return 
1;
}
public 
OnVehicleSpawn(vehicleid)
{
    for(new 
iMAX_VEHICLESi++)
    {
        if(
vehicleid == CarToDestroy[i])
        {
            
DestroyVehicle(vehicleid);
            break;
        }
    }
    return 
1;

Thanks man
Reply
#8

This would be a better alternative:
pawn Код:
new pVeh[MAX_PLAYERS]; //At the top of your script.

COMMAND:car(playerid,params[])
{
    if(AdminLevel[playerid] < 3) return SendClientMessage(playerid, COLOR_RED, "You need to be a level 3 admin to use this command");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must not be in a vehicle to use this command");
    new car;
    if(sscanf(params, "i", car)) return SendClientMessage(playerid, COLOR_RED, "USE: /car [car id]");
    if(!(400 <= car <= 611)) return SendClientMessage(playerid, COLOR_RED, "That id doesn't exist [400-611]");
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x,y,z);
    GetPlayerFacingAngle(playerid, a);
    if(pVeh[playerid]) DestroyVehicle(pVeh[playerid]);
    PutPlayerInVehicle(playerid, (pVeh[playerid] = CreateVehicle(car, x, y, z, a, -1, -1, -1)), 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(pVeh[playerid])
    {
        DestroyVehicle(pVeh[playerid]);
        pVeh[playerid] = 0;
    }
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(vehicleid != pVeh[i]) continue;
        DestroyVehicle(pVeh[i]);
        pVeh[i] = 0;
        break;
    }
    return 1;
}
EDIT: ThePhenix's code will not work. It might work visually, but eventually you will realise that it's not working completely functionally.
Reply
#9

Quote:
Originally Posted by Threshold
Посмотреть сообщение
This would be a better alternative:
pawn Код:
new pVeh[MAX_PLAYERS]; //At the top of your script.

COMMAND:car(playerid,params[])
{
    if(AdminLevel[playerid] < 3) return SendClientMessage(playerid, COLOR_RED, "You need to be a level 3 admin to use this command");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must not be in a vehicle to use this command");
    new car;
    if(sscanf(params, "i", car)) return SendClientMessage(playerid, COLOR_RED, "USE: /car [car id]");
    if(!(400 <= car <= 611)) return SendClientMessage(playerid, COLOR_RED, "That id doesn't exist [400-611]");
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x,y,z);
    GetPlayerFacingAngle(playerid, a);
    if(pVeh[playerid]) DestroyVehicle(pVeh[playerid]);
    PutPlayerInVehicle(playerid, (pVeh[playerid] = CreateVehicle(car, x, y, z, a, -1, -1, -1)), 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(pVeh[playerid])
    {
        DestroyVehicle(pVeh[playerid]);
        pVeh[playerid] = 0;
    }
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(vehicleid != pVeh[i]) continue;
        DestroyVehicle(pVeh[i]);
        pVeh[i] = 0;
        break;
    }
    return 1;
}
EDIT: ThePhenix's code will not work. It might work visually, but eventually you will realise that it's not working completely functionally.
Your code will work, but what if he wants to create two cars being spawned at the same time?
Reply
#10

Then you just add an extra array onto pVeh.
Example:
pawn Код:
new pVeh[MAX_PLAYERS][5];
and edit accordingly.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)