SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/08/2014, 04:48 PM   #1
iOxide
Huge Clucker
 
Join Date: Nov 2013
Location: Inside PAWNO
Posts: 386
Reputation: 16
Default KEY_HANDBRAKE acting weird. Need help asap!

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 Code:
//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.
iOxide is offline   Reply With Quote
Old 06/08/2014, 05:59 PM   #2
ViniBorn
Godfather
 
ViniBorn's Avatar
 
Join Date: Aug 2010
Location: Brasília
Posts: 5,313
Reputation: 720
Default Re: KEY_HANDBRAKE acting weird. Need help asap!

Try use
pawn Code:
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
__________________



CONTATO: F A C E B O O K: @vinibornpawn

ViniBorn is offline   Reply With Quote
Old 06/08/2014, 06:03 PM   #3
dirigent00
Big Clucker
 
Join Date: Jul 2014
Posts: 72
Reputation: 1
Default Re: KEY_HANDBRAKE acting weird. Need help asap!

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

Code:
if (HOLDING( KEY_HANDBRAKE ))
Holding multiple keys:

Code:
if (HOLDING( KEY_FIRE | KEY_CROUCH ))
dirigent00 is offline   Reply With Quote
Old 06/08/2014, 06:26 PM   #4
iOxide
Huge Clucker
 
Join Date: Nov 2013
Location: Inside PAWNO
Posts: 386
Reputation: 16
Default Re: KEY_HANDBRAKE acting weird. Need help asap!

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 :/
iOxide is offline   Reply With Quote
Old 07/08/2014, 05:20 PM   #5
iOxide
Huge Clucker
 
Join Date: Nov 2013
Location: Inside PAWNO
Posts: 386
Reputation: 16
Default Re: KEY_HANDBRAKE acting weird. Need help asap!

/Bump, anyone help?
iOxide is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
That function is acting weird. Magic_Time Scripting Help 3 04/09/2013 02:46 AM
Textdraws acting weird, back into early samp.. EV007 Scripting Help 2 14/07/2013 10:05 AM
[HELP]: My textdraw's suddenly acting weird? ddnbb Scripting Help 6 19/08/2012 02:01 AM
Command is acting weird (Jeff) Help Archive 2 05/02/2010 04:53 PM
Pawno acting weird? Ozar Help Archive 15 18/08/2009 04:20 AM


All times are GMT. The time now is 05:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.