Car Spawn help..
#1

Hello everyone, I am trying to make a car spawner, how can I make the car to spawn into the players position. (So he instantly drives it).

Thanks ahead.
Reply
#2

pawn Код:
CMD:veh(playerid, params[])
{
     new vehid, color1, color2, Float:x, Float:y, Float:z, Float:c; // var's
     if(sscanf(params, "ddd", vehid, color1, color2)) return SendClientMessage(playerid, color, "Correct usage: /veh [vehid] [color1] [color2]"); // syntax message
     GetPlayerPos(playerid, x, y, z); // get the player pos
     GetPlayerFacingAngle(playerid, c); // facing angle
     new car = CreateVehicle(vehid, x, y, z, c, color1, color2, -1) // create the car with the var of car
     PutPlayerInVehicle(playerid, car, 0); // put the player in the new "car" var, the 0 is the seat ID, 0 is the driver
     return 1;
}
Try and use some of that command to merge it with your own, i.e. to get the player inside the vehicle.

PS: Made from scratch, untested.

EDIT: Use Konstantinos', it's a bit more complex.
Reply
#3

pawn Код:
CMD:v( playerid, params[ ] )
{
    new
        modelid
    ;
    if( sscanf( params, "i", modelid ) ) return SendClientMessage( playerid, -1, "Usage: /v <modelid>" );
    if( modelid < 400 || modelid > 611 ) return SendClientMessage( playerid, -1, "Invalid modelid (400-611)" );

    new
        Float: x,
        Float: y,
        Float: z,
        Float: rotation,
        vehicleid
    ;

    switch( GetPlayerState( playerid ) )
    {
        case PLAYER_STATE_DRIVER:
        {
            vehicleid = GetPlayerVehicleID( playerid )
            GetVehiclePos( vehicleid, x, y, z );
            GetVehicleZAngle( vehicleid, rotation );
            DestroyVehicle( vehicleid );
        }
        case PLAYER_STATE_ONFOOT:
        {
            GetPlayerPos( playerid, x, y, z );
            GetPlayerFacingAngle( playerid, rotation );
        }
        default: return SendClientMessage( playerid, -1, "You cannot spawn a vehicle" );
    }

    vehicleid = CreateVehicle( modelid, x, y, z, rotation, -1, -1, 60 );
    LinkVehicleToInterior( vehicleid, GetPlayerInterior( playerid ) );
    SetVehicleVirtualWorld( vehicleid, GetPlayerVirtualWorld( playerid ) );
    PutPlayerInVehicle( playerid, vehicleid, 0 );
    return 1;
}
Reply
#4

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
pawn Код:
CMD:veh(playerid, params[])
{
     new vehid, color1, color2, Float:x, Float:y, Float:z, Float:c; // var's
     if(sscanf(params, "ddd", vehid, color1, color2)) return SendClientMessage(playerid, color, "Correct usage: /veh [vehid] [color1] [color2]"); // syntax message
     GetPlayerPos(playerid, x, y, z); // get the player pos
     GetPlayerFacingAngle(playerid, c); // facing angle
     new car = CreateVehicle(vehid, x, y, z, c, color1, color2, -1) // create the car with the var of car
     PutPlayerInVehicle(playerid, car, 0); // put the player in the new "car" var, the 0 is the seat ID, 0 is the driver
     return 1;
}
Try and use some of that command to merge it with your own, i.e. to get the player inside the vehicle.

PS: Made from scratch, untested.

EDIT: Use Konstantinos', it's a bit more complex.
Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
CMD:v( playerid, params[ ] )
{
    new
        modelid
    ;
    if( sscanf( params, "i", modelid ) ) return SendClientMessage( playerid, -1, "Usage: /v <modelid>" );
    if( modelid < 400 || modelid > 611 ) return SendClientMessage( playerid, -1, "Invalid modelid (400-611)" );

    new
        Float: x,
        Float: y,
        Float: z,
        Float: rotation,
        vehicleid
    ;

    switch( GetPlayerState( playerid ) )
    {
        case PLAYER_STATE_DRIVER:
        {
            vehicleid = GetPlayerVehicleID( playerid )
            GetVehiclePos( vehicleid, x, y, z );
            GetVehicleZAngle( vehicleid, rotation );
            DestroyVehicle( vehicleid );
        }
        case PLAYER_STATE_ONFOOT:
        {
            GetPlayerPos( playerid, x, y, z );
            GetPlayerFacingAngle( playerid, rotation );
        }
        default: return SendClientMessage( playerid, -1, "You cannot spawn a vehicle" );
    }

    vehicleid = CreateVehicle( modelid, x, y, z, rotation, -1, -1, 60 );
    LinkVehicleToInterior( vehicleid, GetPlayerInterior( playerid ) );
    SetVehicleVirtualWorld( vehicleid, GetPlayerVirtualWorld( playerid ) );
    PutPlayerInVehicle( playerid, vehicleid, 0 );
    return 1;
}
Thank you both, really helpfull!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)