KEY_HANDBRAKE acting weird. Need help asap!
#1

Hello,

I am trying to make 'hold down spacebar to reufuel' system, the system works fine. Just the key is acting a bit weird.

Whenever i hold down spacebar, it spams the chat with this message "Vehicle have been refuelled. You paid $%i for %0.1f liters." but doesn't refuel. but if i hold down RMB which is also handbrake, it works perfectly. I tried setting the handbrake as other key and they acted the same as spacebar. It only works when i use RMB o.O am i doing something wrong to check for the spacebar key while player is inside a vehicle? If so, how can i fix this?

These are the code i made

pawn Код:
//Under OnPlayerKeyStateChange

    if((newkeys & KEY_HANDBRAKE) && !(oldkeys & HANDBRAKE))
    {
        for (new i; i < sizeof(gRefuelPickups); i++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 6.5, gRefuelPickups[i][pux], gRefuelPickups[i][puy], gRefuelPickups[i][puz]))
            {
                if (IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
                {
                    if(gVehicleInfo[vehicleid][Fuel] < MAX_VEHICLE_FUEL)
                    {
                        if(pInfo[playerid][Money] > 0)
                        {
                            TogglePlayerControllable(playerid, 0);
                            gTimer_Refuel[playerid] = SetTimerEx("RefuelVehicle", 200, true, "ii", playerid, vehicleid);
                            break;
                        }
                        else
                            return SCM(playerid, RED, "You don't have enough money to refuel your vehicle!");
                    }
                    else
                        return TextDrawSetString(gGasStation_Text[1][playerid], "~n~~r~Fuel tank is full");
                }
            }
        }
    }
    if(RELEASED(KEY_HANDBRAKE))
        PayRefuelPrice(playerid, vehicleid);
       
stock PayRefuelPrice(playerid, vehicleid)
{
    new
        str[80];

    if(gTimer_Refuel[playerid] != 0)
    {
        RewardPlayer(playerid, -gVehicleInfo[vehicleid][RefuelPrice], 0);
        TogglePlayerControllable(playerid, 1);
        format(str, 80, "Vehicle have been refuelled. You paid $%i for %0.1f liters.", gVehicleInfo[vehicleid][RefuelPrice], gVehicleInfo[vehicleid][Liter]);
        SCM(playerid, ORANGE, str);
        KillTimer(gTimer_Refuel[playerid]);
        gTimer_Refuel[playerid] = 0;
        gVehicleInfo[vehicleid][RefuelPrice] = 0;
        gVehicleInfo[vehicleid][Liter] = 0.0;
        return 1;
    }
    return 1;
}

public RefuelVehicle(playerid, vehicleid)
{
    new
        str[100];

    if(gVehicleInfo[vehicleid][Fuel] < MAX_VEHICLE_FUEL)
    {
        gVehicleInfo[vehicleid][Fuel] += 100;
        GetVehicleTank(vehicleid);
        format(str, sizeof(str), "~n~~w~Liters filled: ~g~%0.1fL~n~~w~Total cost:~g~ $%i", gVehicleInfo[vehicleid][Liter], gVehicleInfo[vehicleid][RefuelPrice]);
        TextDrawSetString(gGasStation_Text[1][playerid], str);
    }
    else
        PayRefuelPrice(playerid, vehicleid);
}
I am pretty sure its not the script's fault as it works fine with other keys.
Reply
#2

Try use
pawn Код:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
Reply
#3

Use HOLDING define:
Код:
// HOLDING(keys)
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
Holding one key:

Код:
if (HOLDING( KEY_HANDBRAKE ))
Holding multiple keys:

Код:
if (HOLDING( KEY_FIRE | KEY_CROUCH ))
Reply
#4

Lol, i already have them defined, all showed the same result. And yes i did read wiki and know all those definition that you guys have posted above. Non of them seems to work. Spacebar is still spamming :/
Reply
#5

/Bump, anyone help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)