Hold And Release Key
#1

I Want To Create A Timer That Repeats Itself After A Player Holds KEY_FIRE And When He Releases It The Timer Gets Killed. I Have Tried OnPlayerKeyStateChange But With No Luck. If Anyone Could Help I Would Be Grateful.
Reply
#2

Okay Boy Have You Tried To ****** It Before Coming Here and Posting a Topic With Caps And All?

Seriously stop with that, makes you look very bad in multiple ways. https://sampwiki.blast.hk/wiki/OnPlayerStateChange and I don't think there are any X-keys by default. You have to choose another one, unless it exists somewhere.

Also next time, state specifically what you have already tried to do because now I'm just guessing that you got the oldkey == ... and newkey == ... wrong, or took the wrong key or something.
Reply
#3

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Okay Boy Have You Tried To ****** It Before Coming Here and Posting a Topic With Caps And All?

Seriously stop with that, makes you look very bad in multiple ways. https://sampwiki.blast.hk/wiki/OnPlayerStateChange and I don't think there are any X-keys by default. You have to choose another one, unless it exists somewhere.

Also next time, state specifically what you have already tried to do because now I'm just guessing that you got the oldkey == ... and newkey == ... wrong, or took the wrong key or something.
First of all thanx for replying

Second i ******d it , yes i did

Third I never wanted it to check the "X" key i wanted it to check "KEY_FIRE"

Fourth OnPlayerStateChange only check when a player state is changed not hiskeys

Fifth if you meant OnPlayerKeyStateChange Than i stated that i have already tried it

Sixth i have said what i wanted clearly and if you can't get could you be nice to me when asking . I never meant to make it unclear . Don't you think ?

Seventh here is what i want .

I want a code that when a player hold fire button creates a timer that checks if a player is holding key fire(again) if true it does a code if no it just kills the timer.
Reply
#4

You can do it using OnPlayerKeyStateChange.
When you press the FIRE key, start a timer that only runs once.
Also, set the player TogglePlayerControllable to false (don't allow the player to move).

Inside the timer function, set TogglePlayerControllable back to true (allow him to move again) when you have finished all code in there.

TogglePlayerControllable blocks the player's keys.
When control is returned to the player, the key-states change automatically if the player is holding a key, so OnPlayerKeyStateChange is called again.

Someone sent me this code:
pawn Код:
#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (HOLDING( KEY_SUBMISSION ))
    {
        if (GetPlayerVehicleSeat(playerid) == 0)
        {
            for (new i; i < sizeof(ARefuelPickups); i++)
            {
                if(IsPlayerInRangeOfPoint(playerid, 6.5, ARefuelPickups[i][pux], ARefuelPickups[i][puy], ARefuelPickups[i][puz]))
                {
                    TogglePlayerControllable(playerid, 0);
                    SetTimerEx("RefuelingVehicle", 100, false, "i", playerid);
                    switch (GetPlayerLanguage(playerid))
                    {
                        case 1,2,3: GameTextForPlayer(playerid, TXT_Refuelling, 1000, 4);
                        case 0,4:   GameTextForPlayer(playerid, ENG_Refuelling, 1000, 4);
                    }
                    break;
                }
            }
        }
    }
}

public RefuelingVehicle(playerid)
{
    new vID = GetPlayerVehicleID(playerid);
    TogglePlayerControllable(playerid, 1);
    if (AVehicleData[vID][Fuel] < MaxFuel-15)
    {
        new Amount = AVehicleData[vID][Fuel]+15 - AVehicleData[vID][Fuel];
        new RefuelPrice = (Amount * RefuelMaxPrice) / MaxFuel;
        if (APlayerData[playerid][PlayerMoney] >= RefuelPrice)
        {
            AVehicleData[vID][Fuel] = AVehicleData[vID][Fuel]+15;
            RewardPlayer(playerid, -RefuelPrice, 0);

        }
        else
            SendMessage(playerid, 0xFFFFFFFF, TXT_CannotRefuelVehicle, ENG_CannotRefuelVehicle);
    }
    else
    {
        switch (GetPlayerLanguage(playerid))
        {
            case 1,2,3: GameTextForPlayer(playerid, "Vozilo je puno!", 1000, 4);
            case 0,4:   GameTextForPlayer(playerid, "Vehicle is full!", 1000, 4);
        }
    }
    return 1;
}
This worked fine for him.
Reply
#5

thanx buddy but the problem is freezing the player. the timer should start every 500 milliseconds so he will be freezed for half a second and that code works while he is in a vehicle so it will be very annoying
Reply
#6

Best way to make someone being frozen:
https://sampwiki.blast.hk/wiki/Function:...erControllable

Remember to set it back so the player is unfrozen after 500 ms as well! Also I can swear that you wrote key X above. :S My apologize.
Reply
#7

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Best way to make someone being frozen:
https://sampwiki.blast.hk/wiki/Function:...erControllable

Remember to set it back so the player is unfrozen after 500 ms as well! Also I can swear that you wrote key X above. :S My apologize.
No problem dude .

The thing is i can't freeze the player for 500 ms it's so !@#$%^ annoying
Reply
#8

Or try to move both TogglePlayerControllable functions into the timer function itself.
Then you block their keys and unblock them immediately after that.
This should trigger the OnPlayerKeyStateChange as well.
Reply
#9

i did this
under OnPlayerKeyStateChange
if(PRESSED(KEY_FIRE))
{
SetTimer(bla,bla,bla);
}
forward bla(bla);
public bla(bla)
{
TogglePlayerControllable(playerid,0);
//Code
TogglePlayerControllable(playerid,1);
}
but not working
what i'm i doing wrong
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)