SA-MP Forums Archive
when pressing the key, he doesnt enters the vehicle, something different than the default - 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: when pressing the key, he doesnt enters the vehicle, something different than the default (/showthread.php?tid=408880)



when pressing the key, he doesnt enters the vehicle, something different than the default - niels44 - 19.01.2013

hey everybody,

ok so my friend had an idea, a caddy, with the car wreck model, attached to it, so it would look cool xD, and it does looks cool now, i attached it to the caddy and its like a real car, so we attached some things to the bonnet and the roof, and a spoiler also, but now when i exit the vehicle, and wanna enter it again, i cant enter it, probably cuz the objects are in the way and that he doesnt wants to enter, so i thought, imma make something for that, but still it aint working, i made some debug msgs, but it only sends the first one when my friend tries it, not the second one, here is my code:

pawn Код:
if(newkeys & KEY_SECONDARY_ATTACK)
    {
        printf("pressed key");
        if(IsPlayerNearVehicle(playerid, GetVehicleModel(457), 10.0))
        {
            PutPlayerInVehicle(playerid, GetClosestVehicle(playerid, 5.0), 0);
            printf("entered");
        }
    }
pawn Код:
stock GetClosestVehicle(playerid, Float:range)
{
    new     Float:p_X;
    new     Float:p_Y;
    new     Float:p_Z;

    new     Float:Distance;
    new     Float:PretendentDistance = range +1;
    new     Pretendent;

    GetPlayerPos(playerid, p_X, p_Y, p_Z);

    for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++)
    {
        Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z);

        if(Distance <= range && Distance <= PretendentDistance)
        {
            Pretendent = vehicleid;
            PretendentDistance = Distance;
        }
    }

    return Pretendent;
}
stock IsPlayerNearVehicle(playerid, vehicleid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(vehicleid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
    else return false;
}
can anybody tell me wuts wrong with this? i tried many things but none worked, as i said the message "pressed key" does gets send, so that works, but the message of "entered" doesnt gets send... meaning something isnt right there, but i cant see wut is wrong, can anybody tell me wuts wrong with this?

greets niels


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - iGetty - 19.01.2013

pawn Код:
if(newkeys & KEY_SECONDARY_ATTACK)
That should be:

pawn Код:
if(newkeys == KEY_SECONDARY_ATTACK)



Re: when pressing the key, he doesnt enters the vehicle, something different than the default - niels44 - 19.01.2013

already said that aint the problem, since it DOES sends the message that the key is pressed, but i will try it anyways, ty


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - Gangster-rocks - 19.01.2013

it is something with GetClosestVehicle function.


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - niels44 - 19.01.2013

lol but wut is wrong with it then xD


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - Gangster-rocks - 19.01.2013

pawn Код:
stock IsPlayerNearVehicle(playerid, vehicleid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(vehicleid, X, Y, Z);
    return IsPlayerInRangeOfPoint(playerid,X,Y,Z);
}
its might work.

-N.Z-


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - CodyCummings - 19.01.2013

This should work...

pawn Код:
if(newkeys & KEY_SECONDARY_ATTACK)
    {
        print("pressed key");
        new newvehid = GetClosestVehicle(playerid, 5.0);
        if(newvehid != 0)
        {
            PutPlayerInVehicle(playerid, newvehid, 0);
            print("entered");
        }
        else
        {
             print("Failed to find car nearby!");
        }
    }



Re: when pressing the key, he doesnt enters the vehicle, something different than the default - niels44 - 19.01.2013

it works, it only doesnt puts me in any vehicle... it does says the "entered" in console... i used yours CodyCummings, but doesnt works properly, i got this now:

pawn Код:
if(newkeys & KEY_SECONDARY_ATTACK)
    {
        print("pressed key");
        new newvehid = GetClosestVehicle(playerid, 5.0);
        if(newvehid != 0)
        {
            PutPlayerInVehicle(playerid, newvehid, 0);
            print("entered");
        }
        else
        {
             print("Failed to find car nearby!");
        }
    }
wuts wrong with this?


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - Vince - 19.01.2013

Why not use OnPlayerEnterVehicle? That one's called as soon as you press the button to enter the vehicle. Or are you actually this far away that the animation/callback isn't triggered?


Re: when pressing the key, he doesnt enters the vehicle, something different than the default - niels44 - 19.01.2013

eehm wut do you mean with: Or are you actually this far away that the animation/callback isn't triggered?

??

also, shouldnt it do the same as this one? just say that i entered, but doesnt puts me in?

EDIT: i tried the onplayerentervehicle thing, didnt sent a print at all, doesnt do anything, doesnt puts me in car, i have this:

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    vehicleid = GetClosestVehicle(playerid, 5.0);
    if(vehicleid != 0)
    {
        PutPlayerInVehicle(playerid, vehicleid, 0);
        print("entered");
    }
    else
    {
        print("Failed to find car nearby!");
    }
    return 1;
}