Trailer wont detach
#1

Hi,

I have this code:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(vehicleid) == 525)
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(newkeys == KEY_FIRE)
                {
                    if(IsTrailerAttachedToVehicle(vehicleid))
                    {
                        DetachTrailerFromVehicle(GetVehicleTrailer(vehicleid));
                    }
                    else
                    {
                        new Float:x, Float:y, Float:z;
                        GetVehiclePos(vehicleid, x, y, z);
                        for(new i = 0; i < MAX_VEHICLES; i++)
                        {
                            if(IsVehicleInRangeOfPoint(i, 6, x, y, z))
                            {
                                AttachTrailerToVehicle(i, vehicleid);
                            }
                        }
                    }
                }
            }
        }
    }
    return 1;
}
It works fine.. I can drive up to a vehicle and tow it.. But i cannot detach the trailer, any ideas why?
Reply
#2

Well the code looks fine to me, although there is a redundant check, why check if someone is in a vehicle AND if they are the driver? Just check if someone is the driver and then they must be in a vehicle to be the driver

As for why it's not working, I'm not sure really, unless I'm missing something it looks like it would work to me. Although the way you are checking which key is being pressed, you need to make sure you are not pressing any other keys when you press KEY_FIRE, otherwise it will not work. Maybe you were pressing other keys when you tried to detatch it?
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Maybe you were pressing other keys when you tried to detatch it?
Nope that was the only key i was pressing
And the player state was a last minute addon :P
Reply
#4

What version of SA-MP are you using?

Edit: I did some testing actually, it didn't detatch until I lowered the thing on the back of the mechanic vehicle. Did you try lowering it and see if it detatches then?
Reply
#5

Aha yes, so i dont need the detach code since the game does it auto
Thanks, works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)