SA-MP Forums Archive
Spawning a Vehicle - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Spawning a Vehicle (/showthread.php?tid=178887)



Spawning a Vehicle - Scenario - 24.09.2010

Hi guys. When I use those commands, they do not put me in the vehicle. Instead, if will just spawn it next to me about 4 meters. Why does it not place me in the vehicle? The first command, it does not add the vehicle components. Why not?

pawn Код:
command(admincar, playerid, params[])
{
    new Float:CarToX, Float:CarToY, Float:CarToZ, acar;
    if(PlayerStatistics[playerid][pAdminLevel] >= 2)
    {
        GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
        acar = CreateVehicle(411, CarToX, CarToY+4, CarToZ, 90, 0, 0, -1);
        PutPlayerInVehicle(playerid, acar, 0);
        LinkVehicleToInterior(acar, GetPlayerInterior(playerid));
        SetVehicleVirtualWorld(acar, GetPlayerVirtualWorld(playerid));
        AddVehicleComponent(acar, 1010);
        AddVehicleComponent(acar, 1081);
    }
    return 1;
}

command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(sscanf( params, "ddd", carid, color1, color2))
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 3)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
        }
    }
    else
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 3)
        {
            if(carid < 400 || carid > 611)
            {
                SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");
                return 1;
            }
            GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
            car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

            PutPlayerInVehicle(playerid, car, 0);
            LinkVehicleToInterior(car, GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(car, GetPlayerVirtualWorld(playerid));
        }
    }
    return 1;
}



Re: Spawning a Vehicle - Voldemort - 24.09.2010

Try to put it in last line of command after Inst etc,
pawn Код:
PutPlayerInVehicle(playerid, acar, 0);
Or car can't spawn so fast, car need some 1 sec to spawn, but you put it in same mls


Re: Spawning a Vehicle - Scenario - 26.09.2010

Bump....


Re: Spawning a Vehicle - mick88 - 26.09.2010

I'd try putting player in the vehicle as last thing after linking to interior and virtual world. Vehicle doesn't need time to spawn.

EDIT: I tested the code for you, it works fine as long as you don't try to spawn vehicle it in different VW than 0, becaue you can't put player in vehicle in different virtual world, so my tip will work - PutPlayerInVehicle() as last the last thing.


Re: Spawning a Vehicle - Scenario - 26.09.2010

Quote:
Originally Posted by mick88
Посмотреть сообщение
I'd try putting player in the vehicle as last thing after linking to interior and virtual world. Vehicle doesn't need time to spawn.

EDIT: I tested the code for you, it works fine as long as you don't try to spawn vehicle it in different VW than 0, becaue you can't put player in vehicle in different virtual world, so my tip will work - PutPlayerInVehicle() as last the last thing.
I didn't realize I rearranged the code, oh well. Thanks for the time you took, I appreciate it!


Re: Spawning a Vehicle - Scenario - 27.09.2010

This is the command I am using, but it does not work. I don't get why...

pawn Код:
command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(sscanf( params, "ddd", carid, color1, color2))
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 3)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
        }
    }
    else
    {
        if(PlayerStatistics[playerid][pAdminLevel] >= 3)
        {
            if(carid < 400 || carid > 611)
            {
                SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");
                return 1;
            }
            GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
            car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

            LinkVehicleToInterior(car, GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(car, 0);
            PutPlayerInVehicle(playerid, car, 0);
        }
    }
    return 1;
}



Re: Spawning a Vehicle - mmrk - 27.09.2010

This should work
pawn Код:
command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(PlayerStatistics[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_WHITE, "INFO: You don't have access");
    if(sscanf( params, "iii", carid, color1, color2)) return  SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");

    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

    LinkVehicleToInterior(car, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(car, 0);
    PutPlayerInVehicle(playerid, car, 0);
    return 1;
}



Re: Spawning a Vehicle - Scenario - 27.09.2010

Quote:
Originally Posted by mmrk
Посмотреть сообщение
This should work
pawn Код:
command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(PlayerStatistics[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_WHITE, "INFO: You don't have access");
    if(sscanf( params, "iii", carid, color1, color2)) return  SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");

    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

    LinkVehicleToInterior(car, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(car, 0);
    PutPlayerInVehicle(playerid, car, 0);
    return 1;
}
Just tried, but it didn't work.


Re: Spawning a Vehicle - mmrk - 27.09.2010

Worked fine for me with rcon admin..

Added wrong color id too
pawn Код:
command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(PlayerStatistics[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_WHITE, "INFO: You don't have access");
    if(sscanf( params, "iii", carid, color1, color2)) return  SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");
    if(color1 < 0 || color1 > 252) return SendClientMessage(playerid, COLOR_RED, "Wrong color1 ID (min: 0 max: 252)");
    if(color2 < 0 || color2 > 252) return SendClientMessage(playerid, COLOR_RED, "Wrong color2 ID (min: 0 max: 252)");
    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

    LinkVehicleToInterior(car, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(car, 0);
    PutPlayerInVehicle(playerid, car, 0);
    return 1;
}



Re: Spawning a Vehicle - Scenario - 27.09.2010

Quote:
Originally Posted by mmrk
Посмотреть сообщение
Worked fine for me with rcon admin..

Added wrong color id too
pawn Код:
command(spawncar, playerid, params[])
{
    new carid, Float:CarToX, Float:CarToY, Float:CarToZ, car, color1, color2;
    if(PlayerStatistics[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_WHITE, "INFO: You don't have access");
    if(sscanf( params, "iii", carid, color1, color2)) return  SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /spawncar [modelid] [color1] [color2]");
    if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_RED, "Wrong model ID (min: 400 max: 600)");
    if(color1 < 0 || color1 > 252) return SendClientMessage(playerid, COLOR_RED, "Wrong color1 ID (min: 0 max: 252)");
    if(color2 < 0 || color2 > 252) return SendClientMessage(playerid, COLOR_RED, "Wrong color2 ID (min: 0 max: 252)");
    GetPlayerPos(playerid, CarToX, CarToY, CarToZ);
    car = CreateVehicle(carid, CarToX, CarToY+4, CarToZ, 90, color1, color2, -1);

    LinkVehicleToInterior(car, GetPlayerInterior(playerid));
    SetVehicleVirtualWorld(car, 0);
    PutPlayerInVehicle(playerid, car, 0);
    return 1;
}
I don't know what the problem is. My original code worked, but now it doesn't. I'll bet there's something in my script which is causing issues.