AttachObjectToVehicle and delete attached object.
#1

Hello everybody! I Attached a red light to maverick and it's attaching but is isn't detaching. Where is my mistake?
Код:
Definicje:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))

OnPlayerKeyStateChange:
new helilight = CreateObject(18657,0,0,0,0,0,0,100.0);
        if    (PRESSED( KEY_CROUCH ))
        {
            new heliid = GetPlayerVehicleID(playerid);
            switch(GetVehicleModel(heliid))
            {
                case 487:
                {
                    AttachObjectToVehicle(helilight, GetPlayerVehicleID(playerid), 0.004999, 2.019998, 0.599999, -80.025001, 0.000000, 0.000000); //Object Model: 18657 | 0
                    return 1;
                }
            }
        }
        if    (RELEASED( KEY_CROUCH ))
        {
            switch(GetVehicleModel(GetPlayerVehicleID(playerid)))
            {
                case 487:
                {
                    DestroyObject(helilight);
                    return 1;
                }
            }
        }
Reply
#2

Try this:
pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))

new helilight[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
    helilight[playerid] = -1;
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED( KEY_CROUCH ))
    {
        new heliid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(heliid) == 487)
        {
            if(helilight[playerid] == -1)
            {
                helilight[playerid] = CreateObject(18657,0,0,0,0,0,0,100.0);
            }
            AttachObjectToVehicle(helilight[playerid], heliid, 0.004999, 2.019998, 0.599999, -80.025001, 0.000000, 0.000000); //Object Model: 18657 | 0
        }
    }
    else
    {
        if(helilight[playerid] != -1)
        {
            DestroyObject(helilight[playerid]);
            helilight[playerid] = -1;
        }
    }
    return 1;
}
Reply
#3

Works. Thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)