How to make player owned vehicles?
#1

How to i make it so I can give a player his/hers own vehicle and it will stay that way?
Reply
#2

Example snippet:
pawn Код:
//global
new
    gPlayerVehicle[ MAX_PLAYERS ];
pawn Код:
//onplayerconnect
gPlayerVehicle[ MAX_PLAYERS ] = -1;
pawn Код:
//command to get
CMD:getv(playerid, params[])
{
    new
        vID,
        Float: pPos[ 3 ];

    GetPlayerPos( playerid, pPos[ 0 ], pPos[ 1 ], pPos[ 2 ] );

    if( gPlayerVehicle[ playerid ] != -1 )
    {
        SetVehiclePos( gPlayerVehicle[ playerid ], pPos[ 0 ], pPos[ 1 ], pPos[ 2 ] );
        return SendClientMessage( playerid, 0x00FF00FF, "[INFO] Your personal vehicle has been teleported to your location" );
    }
    else if( sscanf( params, "i", vID ))
        return SendClientMessage( playerid, 0xFFFF00FF, "[USAGE] /getv <model>" );

    // this player doesn't have a car, and the parameter is fullfilled:
    gPlayerVehicle[ playerid ] = CreateVehicle( vID,  ( pPos[ 0 ] + 5.0 ), ( pPos[ 1 ] + 5.0 ), ( pPos[ 2 ] + 1.0 ), 0.0, -1, -1, 999999 );
    SendClientMessage( playerid, 0x00FF00FF, "[SUCCESS] You have created your own personal vehicle!" );
    return SendClientMessage( playerid, 0xFFFF00FF, "Type /getv to teleport it back to you, or /delv to delete it" );
}
pawn Код:
//command to remove
CMD:delv(playerid, params[])
{
    if( gPlayerVehicle[ playerid ] != -1 )
    {
        DestroyVehicle( gPlayerVehicle[ playerid ] );
        SendClientMessage( playerid, 0x00FF00FF, "[SUCCESS] You have deleted your vehicle - do /getv for a new one" );
        return gPlayerVehicle[ playerid ] = -1;
    }
    return SendClientMessage( playerid, 0xFF0000FF, "[ERROR] You don't have a personal vehicle" );
}
This should do the trick
Reply
#3

@larzi:
that does not save the stuff or does it?
Reply
#4

Quote:
Originally Posted by deffo
Посмотреть сообщение
@larzi:
that does not save the stuff or does it?
Currently it only saves to playerid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)