SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 19/01/2016, 10:21 AM   #1
Marcuse
Big Clucker
 
Marcuse's Avatar
 
Join Date: Dec 2011
Location: Bosnia
Posts: 98
Reputation: 5
Post KeyStateChange not registered

Okay I have a function that toggles the cursor when the Y is pressed
It works well when i want to activate the cursor but when i want to disable it (when SelectTextDraw is active) its not registering any keys on KeyStateChange

PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys){
    if(
newkeys KEY_YES){
        if(!
guiActive[playerid]){
            
SelectTextDraw(playerid255);
            
guiActive[playerid] = true;
        } else if(
guiActive[playerid]) {
            
CancelSelectTextDraw(playerid);
            
guiActive[playerid] = false;
        }
    }
    return 
true;

Marcuse is offline   Reply With Quote
Old 19/01/2016, 10:30 AM   #2
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,711
Reputation: 1668
Default Re: KeyStateChange not registered

You might wanna use this: if ((!newkeys & KEY_YES) && (oldkeys & KEY_YES))
It's been a while I been into SAMP, but as far as I know, with your code it works when it's still being pressed, which means it could run many times when you press it (try sending a Client message, when you press the key you could get about 3-5 messages while you press it once), so that's why it might not work (I think - Once again, it's been a while); it's running to many times and could not be processed (I had this once).
And as far as I know, that which I sent checks if you pressed it once, and it will only work if you're not still holding it. Or something like that.
Kwarde is offline   Reply With Quote
Old 19/01/2016, 10:37 AM   #3
Marcuse
Big Clucker
 
Marcuse's Avatar
 
Join Date: Dec 2011
Location: Bosnia
Posts: 98
Reputation: 5
Default Re: KeyStateChange not registered

@Kwarde , I'ts not registering it now at all
f((!newkeys & KEY_YES) && (oldkeys & KEY_YES))
Marcuse is offline   Reply With Quote
Old 19/01/2016, 10:38 AM   #4
Sasquatch
Little Clucker
 
Join Date: Dec 2015
Posts: 8
Reputation: 0
Default Re: KeyStateChange not registered

You are missing a '!' before the (oldkeys & KEY_YES)
Sasquatch is offline   Reply With Quote
Old 19/01/2016, 10:45 AM   #5
Marcuse
Big Clucker
 
Marcuse's Avatar
 
Join Date: Dec 2011
Location: Bosnia
Posts: 98
Reputation: 5
Default Re: KeyStateChange not registered

@Sasquatch , doesn't work either...
Tried with #define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

But again it wont detect any keys when SelectTextDraw is active..
Marcuse is offline   Reply With Quote
Old 19/01/2016, 10:56 AM   #6
Sasquatch
Little Clucker
 
Join Date: Dec 2015
Posts: 8
Reputation: 0
Default Re: KeyStateChange not registered

Im trying to go over that problem, but it wont detect any keys when SelectTextDraw is active... like you said
Sasquatch is offline   Reply With Quote
Old 19/01/2016, 11:02 AM   #7
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,068
Reputation: 2658
Default Re: KeyStateChange not registered

Selectable textdraw freezes the player much like TogglePlayerControllable does and it is been known that keys are not always registered in that case. I don't think there is a fix. You will have to tell players to press ESC to exit the textdraw selection and/or will have to make a dedicated close button.

Sidenote: don't use too many else-if. Especially in cases where it is not at all necessary. It looks ugly and unprofessional and in general makes code harder to dissect. Either the GUI is active or it is not. There is no "in-between" case.
PHP Code:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys){
    if(
newkeys KEY_YES){
        if(!
guiActive[playerid]) 
        {
            
SelectTextDraw(playerid255);
        } 
        else 
        {
            
CancelSelectTextDraw(playerid);
        }
        
guiActive[playerid] = !guiActive[playerid];
    }
    return 
true;

__________________
Vince is offline   Reply With Quote
Old 19/01/2016, 12:47 PM   #8
Marcuse
Big Clucker
 
Marcuse's Avatar
 
Join Date: Dec 2011
Location: Bosnia
Posts: 98
Reputation: 5
Default Re: KeyStateChange not registered

Thanks guys for the response!
Marcuse is offline   Reply With Quote
Old 29/05/2020, 02:30 AM   #9
Sasino97
High-roller
 
Sasino97's Avatar
 
Join Date: Dec 2010
Location: Tampa, FL
Posts: 1,413
Reputation: 139
Default Re: KeyStateChange not registered

Did anyone find a workaround?
I have the same necessity: the user should be able to press shift to spawn in my skin selection clickable-textdraw-based menu.
Sasino97 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
Forum date registered bug? someone registered in the year 1969? WackoX Everything and Nothing 20 09/01/2009 08:02 PM


All times are GMT. The time now is 03:14 PM.


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