SA-MP Forums Archive
Vehicle problem - 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 problem (/showthread.php?tid=453736)



Vehicle problem - martoivanov - 26.07.2013

Sometimes when a player si driving his car, it removes him out ot the car and deletes the car?
Where is the problem?
Here are the sciprts
pawn Код:
public VehicleSpawner(playerid,model){
    if(IsPlayerInAnyVehicle(playerid)){
        SendClientMessage(playerid, COLOR_RED, "ГРЕШКА: Вече имаш кола!");
    }
    else{
    if(VehicleSpawn[playerid]==0){
    new Float:x,Float:y,Float:z,Float:a, vehicleid;
    GetPlayerPos(playerid,x,y,z);
    GetPlayerFacingAngle(playerid,a);
    vehicleid = CreateVehicle(model,x+1,y+1,z,a,-1,-1,-1);
    PutPlayerInVehicle(playerid, vehicleid, 0);
    SetVehicleHealth(vehicleid,  1000.0);
    LinkVehicleToInterior(vehicleid, GetPlayerInterior(playerid));
    for(new i=0;i<MAX_PLAYERVEHICLES;i++){
    if(Turn[playerid]==MAX_PLAYERVEHICLES){
    VehicleDeleter(PlayerVehicle[playerid][0]);
    new b=MAX_PLAYERVEHICLES-1;
    for(new c=0;c<b;c++){
    new A=c+1;
    PlayerVehicle[playerid][c]=PlayerVehicle[playerid][A];
    }
    PlayerVehicle[playerid][b]=0;
    Turn[playerid]--;
    }
    if(!PlayerVehicle[playerid][i]){
    PlayerVehicle[playerid][i]=vehicleid;
    Turn[playerid]++;
    break;
    }
  }
}
        else{
            new string[256];
            format(string, sizeof(string), "Изчакай %d sec. преди да вземаш превозно средство пак!", VehicleSpawn[playerid]);
            SendClientMessage(playerid,COLOR_RED, string);
        }
    }
}
public VehicleDeleter(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++){
        new Float:X,Float:Y,Float:Z;
        if(IsPlayerInVehicle(i, vehicleid)){
            RemovePlayerFromVehicle(i);
            GetPlayerPos(i,X,Y,Z);
            SetPlayerPos(i,X,Y+3,Z);
        }
        SetVehicleParamsForPlayer(vehicleid,i,0,1);
    }
    SetTimerEx("VehicleReseter",2000,0,"i",vehicleid);
}

public VehicleReseter(vehicleid)
{
    DestroyVehicle(vehicleid);
}

public VehicleSpawnerLimiter(){
    new i;
    for(i=0;i<=MAX_PLAYERS;i++){
        if(VehicleSpawn[i]>0){
            VehicleSpawn[i]--;
        }
    }
}
public OnVehicleSpawn(vehicleid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        for(new u=0;u<MAX_PLAYERVEHICLES;u++)
        {
            if(vehicleid==PlayerVehicle[i][u])
            {
                VehicleDeleter(vehicleid);
                PlayerVehicle[i][u]=0;
                Turn[i]--;
            }
        }
    }
    return 0;
}
I use to car spawners - with a dialog and with a model preview menu

Thanks in advance!


Re: Vehicle problem - John_Tylor - 26.07.2013

I'll try it.!


Re: Vehicle problem - martoivanov - 26.07.2013

I use this vehicle spawner with dialogs -https://sampforum.blast.hk/showthread.php?tid=346354
And this vehicle spawner with model preview menu - pastebin.com/w43Qgp4T
The only thing I changed was this:
pawn Код:
SpawnVehicle_InfrontOfPlayer(playerid, vehiclemodel, color1, color2)
{
    new Float:x,Float:y,Float:z;
    new Float:facing;
    new Float:distance;

    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, facing);

    new Float:size_x,Float:size_y,Float:size_z;
    GetVehicleModelInfo(vehiclemodel, VEHICLE_MODEL_INFO_SIZE, size_x, size_y, size_z);
   
    distance = size_x + 0.5;

    x += (distance * floatsin(-facing, degrees));
    y += (distance * floatcos(-facing, degrees));

    facing += 90.0;
    if(facing > 360.0) facing -= 360.0;

    return CreateVehicle(vehiclemodel, x, y, z + (size_z * 0.25), facing, color1, color2, -1);
}
CHANGED TO
pawn Код:
SpawnVehicle_InfrontOfPlayer(playerid, vehiclemodel, color1, color2)
{
 #pragma unused color1
 #pragma unused color2
        if(IsPlayerInAnyVehicle(playerid)){
        SendClientMessage(playerid, COLOR_RED, "ГРЕШКА: Вече имаш кола!");
    }
    else{
    if(VehicleSpawn[playerid]==0){
    new Float:x,Float:y,Float:z,Float:a, vehicleid;
    GetPlayerPos(playerid,x,y,z);
    GetPlayerFacingAngle(playerid,a);
    vehicleid = CreateVehicle(vehiclemodel,x+1,y+1,z,a,-1,-1,-1);
    PutPlayerInVehicle(playerid, vehicleid, 0);
    SetVehicleHealth(vehicleid,  1000.0);
    LinkVehicleToInterior(vehicleid, GetPlayerInterior(playerid));
    for(new i=0;i<MAX_PLAYERVEHICLES;i++){
    if(Turn[playerid]==MAX_PLAYERVEHICLES){
    VehicleDeleter(PlayerVehicle[playerid][0]);
    new b=MAX_PLAYERVEHICLES-1;
    for(new c=0;c<b;c++){
    new A=c+1;
    PlayerVehicle[playerid][c]=PlayerVehicle[playerid][A];
    }
    PlayerVehicle[playerid][b]=0;
    Turn[playerid]--;
    }
    if(!PlayerVehicle[playerid][i]){
    PlayerVehicle[playerid][i]=vehicleid;
    Turn[playerid]++;
    break;
    }
  }
}
        else{
            new string[256];
            format(string, sizeof(string), "Изчакай %d sec. преди да вземаш превозно средство пак!", VehicleSpawn[playerid]);
            SendClientMessage(playerid,COLOR_RED, string);
        }
    }

}