Key detection while in textdraw selection mode
#1

Hi.

My server uses a selectable textdraw spawning screen.

That's all fine and dandy, however I've found that keys are undetected (with exception of escape) while in textdraw selection mode.


Attempting this under OnPlayerUpdate yielded no results.

To clear up any confusion... by textdraw selection mode I was referring to https://sampwiki.blast.hk/wiki/SelectTextdraw

It is under that state that no keys are detected at all.

Код:
public OnPlayerUpdate(playerid)
{
    GetPlayerKeys(playerid, iTemp, hour, minute);

    if(iTemp == KEY_JUMP)
    {
        OnPlayerClickTextDraw(playerid, TEXTDRAW_BUTTON_SPAWN);
    }
}
Can anyone think of a workaround or a solution to this?
Reply
#2

SAMP doen't detect keys, it detects actions. You know, you can't run or jump when a clickable TD or scoreboard is showing. So, you can't detect keys when showing a clickable TD.
Reply
#3

Quote:
Originally Posted by cawfee
Посмотреть сообщение
Код:
    if(iTemp == KEY_JUMP)
    {
        OnPlayerClickTextDraw(playerid, TEXTDRAW_BUTTON_SPAWN);
    }
Can anyone think of a workaround or a solution to this?
That, is not how you use OnPlayerClickTextDraw...


You need to be reading more on scripting.
Reply
#4

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
That, is not how you use OnPlayerClickTextDraw...


You need to be reading more on scripting.
What do you mean? OnPlayerClickTextDraw is not a custom function, and it can be called just by simply doing:
pawn Код:
OnPlayerClickTextDraw(playerid, Text:clickedid);
Where 'playerid' and 'clickedid' are the parameters of OnPlayerClickTextDraw respectively.

Start being a bit more modest.
Reply
#5

Just saying, Modesty has nothing to do with it.
Reply
#6

OnPlayerClickTextDraw is called only when a player clicks a textdraw or escapes from it, not under OnPlayerUpdate. [Use
pawn Код:
CallLocalFunction()
??]
Text:Clickedid can be cycled through with a switch-case statement[switch (Text:Clickedid)] or by an if-else clause.

I don't understand what you're trying to do here but assuming that TEXTDRAW_BUTTON_SPWAN is the id for your textdraw you can do this

pawn Код:
OnPlayerClickTextDraw(playerid,Text:clickedid)
{
     switch(clickedid)
     {
         case TEXTDRAW_BUTTON_SPAWN:
                     {/*Do what you want here!*/}
      }
}

OnPlayerUpdate(playerid)  // shouldn't you use OnPlayerKeyStateChange??
{
   GetPlayerKeys(playerid, iTemp, hour, minute);

    if(iTemp == KEY_JUMP)
    {
        //call TextDrawShowForPlayer(playerid, textid);
        TextDrawShowForPlayer(playerid, TEXTDRAW_BUTTON_SPAWN);
        /*
          *And other stuff you need here
          *
        */

    }
}

PS: I didn't compile this stuff. Might be missing semicolons,temp vars and stuff.
Reply
#7

Also as mentioned above, you should really not use OnPlayerUpdate for that action. OnPlayerUpdate gets called ALOT - whenever you move, walk, anything. It can be around 30 times/second and it can really bring your server down.
Reply
#8

Where he's wanting to detect the keys, can't be detected.


Even though he should actually be using OnPlayerKeyStateChange, it's going to be requirement that the player HAS to click on a textdraw, and that he's going to need to use OnPlayerClickTextDraw.
Reply
#9

How about we get some support here and not aimless opinions? We are well aware of what we're doing, if you can't say anything helpful, please don't say anything at all.


Thanks.
Reply
#10

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Where he's wanting to detect the keys, can't be detected.


Even though he should actually be using OnPlayerKeyStateChange, it's going to be requirement that the player HAS to click on a textdraw, and that he's going to need to use OnPlayerClickTextDraw.
He actually can detect keys at "OnPlayerUpdate" in general.

First thing you should do is although not to use
Код:
 if(iTemp == KEY_JUMP)
You should rather be using
Код:
if(iTemp & KEY_JUMP)
"==" in this case means "this key and only this key"... If you e.g. press the JUMP key while you are pressing anything else, the "==" will be false.

if "OnPlayerUpdate" doesn't work - and ofc because "OnPlayerUpdate" is generally a risky thing to use (mentioned before) - you can try out a timer.
You could start that timer when the textdraws begin to show and kill it at that spot.
e.g.
Код:
forward TextdrawKeyDetection(playerid);
new TDTimer[MAX_PLAYERS];

public TextdrawKeyDetection(playerid)
{
    new Keys, ud, lr);
    GetPlayerKeys(playerid, Keys, ud, lr);

    if(Keys & KEY_JUMP)
    {
        OnPlayerClickTextDraw(playerid, TEXTDRAW_BUTTON_SPAWN);
        KillTimer(TDTimer[playerid]);
    }
}
and
Код:
TDTimer[playerid] = SetTimerEx("TextdrawKeyDetection", 500, true, "i", playerid);
at the part where you show the textdraw for the player.




Btw: If you are struggling with something like that, when something is not working when pressing a key or so, you might try to find the false spot on your own by showing some "debug messages" at certain spots.
Either as ClientMessage or as print on the console... This way you can exactly find out which part of your code was called, and which wasn't...
You can e.g. find out whether the whole key detection part at "OnPlayerUpdate" works or doesn't. The same way you can find out whether the OnPlayerClickTextDraw function was called at all.
Reply
#11

Quote:
Originally Posted by Sgt.TheDarkness
Посмотреть сообщение
How about we get some support here and not aimless opinions? We are well aware of what we're doing, if you can't say anything helpful, please don't say anything at all.


Thanks.
How's about you follow your own advice.

Quote:
Originally Posted by Sascha
Посмотреть сообщение
He actually can detect keys at "OnPlayerUpdate" in general.
Not when he's in the dialog he can't.
Reply
#12

Quote:
Originally Posted by Sascha
Посмотреть сообщение
He actually can detect keys at "OnPlayerUpdate" in general.

First thing you should do is although not to use
Код:
 if(iTemp == KEY_JUMP)
You should rather be using
Код:
if(iTemp & KEY_JUMP)
"==" in this case means "this key and only this key"... If you e.g. press the JUMP key while you are pressing anything else, the "==" will be false.

if "OnPlayerUpdate" doesn't work - and ofc because "OnPlayerUpdate" is generally a risky thing to use (mentioned before) - you can try out a timer.
You could start that timer when the textdraws begin to show and kill it at that spot.
e.g.
Код:
forward TextdrawKeyDetection(playerid);
new TDTimer[MAX_PLAYERS];

public TextdrawKeyDetection(playerid)
{
    new Keys, ud, lr);
    GetPlayerKeys(playerid, Keys, ud, lr);

    if(Keys & KEY_JUMP)
    {
        OnPlayerClickTextDraw(playerid, TEXTDRAW_BUTTON_SPAWN);
        KillTimer(TDTimer[playerid]);
    }
}
and
Код:
TDTimer[playerid] = SetTimerEx("TextdrawKeyDetection", 500, true, "i", playerid);
at the part where you show the textdraw for the player.




Btw: If you are struggling with something like that, when something is not working when pressing a key or so, you might try to find the false spot on your own by showing some "debug messages" at certain spots.
Either as ClientMessage or as print on the console... This way you can exactly find out which part of your code was called, and which wasn't...
You can e.g. find out whether the whole key detection part at "OnPlayerUpdate" works or doesn't. The same way you can find out whether the OnPlayerClickTextDraw function was called at all.

Hey! Thanks for the constructive feedback. I tried this as well as what everyone else suggested above and unfortunately it appears keys aren't detected at all... every effort of debugging keys pressed returned nothing.
Reply
#13

Hang on, because we were telling you it couldn't be done like this, you don't thank any of us that said about it?

That's so selective that it shows that you're not thanking for the right reasons.


Just because we all told you, that it wasn't right or possible, you ignore us? That's impressive... Highly impressive.
Reply
#14

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Hang on, because we were telling you it couldn't be done like this, you don't thank any of us that said about it?

That's so selective that it shows that you're not thanking for the right reasons.


Just because we all told you, that it wasn't right or possible, you ignore us? That's impressive... Highly impressive.
What the fuck are you on?

This topic was posted for the sake of finding a solution to the issue of keys not being detected while selecting textdraws, not to hear your critique and compliment you for sharing it. Which I must point out, was very rude.

Judging from your replies, you barely bothered to read the subject matter or have a minimal understanding on how things work.

Good luck.
Reply
#15

You can always use GetAsyncKeyState
Ever tried iPleoMax's TD editor? He has made a plugin which can detect the Virtual Key's using GetAsyncKeyState in C++

Try this code, Make your own plugin or use his..
Credits: iPLeoMaX
Код:
cell* Buff;

cell AMX_NATIVE_CALL GetVirtualKeyState(AMX* amx, cell* params)
{
	return GetAsyncKeyState(params[1]);
}
Untested but it will work, Try his TD Editor, His plugin detects the keys even if he is on a Textdraw Selection or Dialog.
Reply
#16

Quote:
Originally Posted by MafiaOink
Посмотреть сообщение
You can always use GetAsyncKeyState
Ever tried iPleoMax's TD editor? He has made a plugin which can detect the Virtual Key's using GetAsyncKeyState in C++

Try this code, Make your own plugin or use his..
Credits: iPLeoMaX
Код:
cell* Buff;

cell AMX_NATIVE_CALL GetVirtualKeyState(AMX* amx, cell* params)
{
	return GetAsyncKeyState(params[1]);
}
Untested but it will work, Try his TD Editor, His plugin detects the keys even if he is on a Textdraw Selection or Dialog.
Interesting for sure. After having spent a little over an hour trying to use PAWN functions to achieve this, C++ may be the way to go.

Are you referring to his filterscript?
Reply
#17

Quote:
Originally Posted by cawfee
Посмотреть сообщение
What the fuck are you on?

This topic was posted for the sake of finding a solution to the issue of keys not being detected while selecting textdraws, not to hear your critique and compliment you for sharing it. Which I must point out, was very rude.

Judging from your replies, you barely bothered to read the subject matter or have a minimal understanding on how things work.

Good luck.
Actually, quite contrary... At least we're not dealing with broken, non-working code... You're here looking for help...



Just because the help isn't to your liking, doesn't mean it's not help.


BTW, you and your "Co-Dev" are the rudest that I've come across for a long while... I hope you have REAL trouble finding help in the future, just because you are, such spoiled brats.


After all, all my replies, were with reason.

You came here looking for help, you got it, in multiple forms... All of which telling you, that you needed to change your shit.

You ignore everyone else, except the one, who said about the newkeys issue... When really, it didn't matter a rats arse, because IT STILL DIDN'T WORK, AS WAS STATED.


So again, where the fuck have I been "rude"...



As for IPLEO... You won't be able to run that on the main server because of the way it functions... It was only ever intended for editing on local machines... Not being put on production servers.


So therefore, GetASyncKeyState, won't make a difference, as it's nothing to do with SAMP, and can't be used, to script with.
Reply
#18

Movement keys aren't the same as KEY_JUMP. You should have a look at OnPlayerKeyStateChange to see how you should actually do the comparison.
Reply
#19

Quote:
Originally Posted by MafiaOink
Посмотреть сообщение
You can always use GetAsyncKeyState
Ever tried iPleoMax's TD editor? He has made a plugin which can detect the Virtual Key's using GetAsyncKeyState in C++

Try this code, Make your own plugin or use his..
Credits: iPLeoMaX
Код:
cell* Buff;

cell AMX_NATIVE_CALL GetVirtualKeyState(AMX* amx, cell* params)
{
	return GetAsyncKeyState(params[1]);
}
Untested but it will work, Try his TD Editor, His plugin detects the keys even if he is on a Textdraw Selection or Dialog.
That is useless unless you are making local filterscripts.
Reply
#20

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Movement keys aren't the same as KEY_JUMP. You should have a look at OnPlayerKeyStateChange to see how you should actually do the comparison.
Thanks.

I've already tried using OnPlayerKeyStateChange and yet again every key is undetected.


By textdraw selection mode, I mean SelectTextdraw... should have stated this earlier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)