Personal Vehicle Help!
#1

Hello forum samp.

Im trying to make a personal veh command.
When i type /elegy - to spawn an elegy , when i type /elegy second time the first car get destroyed not with DestroyVehicle but with the command. I mean if i exit the car let the first car get destroyed automaticly by the command.

I tried to make it many times in much diferrent ways ,but nothing happened.

So i am stuck here.

Код:
	if (strcmp("/elegy", cmdtext, true, 10) == 0)
	{
	if(IsPlayerInAnyVehicle(playerid))  return SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car.");
	new Float:X, Float:Y, Float:Z, elegy;
	GetPlayerPos(playerid, X, Y, Z);
	elegy = CreateVehicle(562, X, Y, Z, 0.0, 0, 0, 0);
	PutPlayerInVehicle(playerid, elegy, 0);
	return 1;
	}
Any ideas? +Rep for the dude who will help me.
Reply
#2

Please guys i really need that command.
Reply
#3

Quote:
Originally Posted by necrobg3
Посмотреть сообщение
Please guys i really need that command.
There is not really need of szSavePlayerVeh variable but I just made it to make you understand. We can also do this

pawn Код:
DestroyVehicle( GetPlayerVehicleID( playerid ) );
anyway, full code:

pawn Код:
new szSavePlayerVeh[ MAX_PLAYERS ],
    bool:n_biIsPlayerInCar[ MAX_PLAYERS ]; // at top
   
n_biIsPlayerInCar[ playerid ] = false; //in nPlayerConnect and OnPlayerDIsconnect

if (strcmp("/elegy", cmdtext, true, 10) == 0)
{
    if( IsPlayerInAnyVehicle( playerid ) ) return SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car.");

    if( !n_biIsPlayerInCar[ playerid ] )
    {

        new Float:X, Float:Y, Float:Z, elegy;
        GetPlayerPos(playerid, X, Y, Z);
        elegy = CreateVehicle(562, X, Y, Z, 0.0, 0, 0, 0);
        PutPlayerInVehicle(playerid, elegy, 0);
       
        n_biIsPlayerInCar[ playerid ] = true;
       
        szSavePlayerVeh[ playerid ] = GetPlayerVehicleID( playerid );
    }
    else
    {
        n_biIsPlayerInCar[ playerid ] = false;
       
        DestroyVehicle( szSavePlayerVeh[ playerid ] );
    }
   
    return 1;
}
Did you mean this?
Reply
#4

Quote:
Originally Posted by FalconX
Посмотреть сообщение
There is not really need of szSavePlayerVeh variable but I just made it to make you understand. We can also do this

pawn Код:
DestroyVehicle( GetPlayerVehicleID( playerid ) );
anyway, full code:

pawn Код:
new szSavePlayerVeh[ MAX_PLAYERS ],
    bool:n_biIsPlayerInCar[ MAX_PLAYERS ]; // at top
   
n_biIsPlayerInCar[ playerid ] = false; //in nPlayerConnect and OnPlayerDIsconnect

if (strcmp("/elegy", cmdtext, true, 10) == 0)
{
    if( IsPlayerInAnyVehicle( playerid ) ) return SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car.");

    if( !n_biIsPlayerInCar[ playerid ] )
    {

        new Float:X, Float:Y, Float:Z, elegy;
        GetPlayerPos(playerid, X, Y, Z);
        elegy = CreateVehicle(562, X, Y, Z, 0.0, 0, 0, 0);
        PutPlayerInVehicle(playerid, elegy, 0);
       
        n_biIsPlayerInCar[ playerid ] = true;
       
        szSavePlayerVeh[ playerid ] = GetPlayerVehicleID( playerid );
    }
    else
    {
        n_biIsPlayerInCar[ playerid ] = false;
       
        DestroyVehicle( szSavePlayerVeh[ playerid ] );
    }
   
    return 1;
}
Did you mean this?
Not really, i mean when i type /elegy to destroy the vehicle and thats happen , but now when i type it it only destroys not spawn so i need when i type /elegy second time the elegy get destroyed and spawned in one way.
Reply
#5

Any help please?
Reply
#6

pawn Код:
// OnPlayerCommandText
    if(strcmp("/elegy", cmdtext, true) == 0) {
        if(IsPlayerInAnyVehicle(playerid)) {
            return SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car.");
        }
        static
            vehicleid
        ;
        if(vehicleid) {
            DestroyVehicle(vehicleid);
        }
        new
            Float: X,
            Float: Y,
            Float: Z
        ;
        GetPlayerPos(playerid, X, Y, Z);
        PutPlayerInVehicle(playerid, (vehicleid = CreateVehicle(562, X, Y, Z, 0.0, -1, -1, -1)), 0);
        return true;
    }
Reply
#7

Thanks, just one more thing. When i type /elegy the car get spawned but not on my current facing angle. Can this be fixed?
Reply
#8

Quote:
Originally Posted by necrobg3
Посмотреть сообщение
Thanks, just one more thing. When i type /elegy the car get spawned but not on my current facing angle. Can this be fixed?
pawn Код:
// OnPlayerCommandText
    if(strcmp("/elegy", cmdtext, true) == 0) {
        if(IsPlayerInAnyVehicle(playerid)) {
            return SendClientMessage(playerid, COLOR_RED, "ERROR: You already have a car.");
        }
        static
            vehicleid
        ;
        if(vehicleid) {
            DestroyVehicle(vehicleid);
        }
        new
            Float: X,
            Float: Y,
            Float: Z,
            Float: A
        ;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, A);
        PutPlayerInVehicle(playerid, (vehicleid = CreateVehicle(562, X, Y, Z, A, -1, -1, -1)), 0);
        return true;
    }
Reply
#9

Thanks dude, +rep for you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)