SA-MP Forums Archive
GetPlayerKeys while frozen - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetPlayerKeys while frozen (/showthread.php?tid=253020)



GetPlayerKeys while frozen - Sascha - 04.05.2011

Hi...
I'm working on a little debug filterscript and I'd need to know how / if it's possible to detect if a player is pressing a certain key while he is frozen (TogglePlayerControllable)

if I use the normal way
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION))
  {
    SendClientMessage(playerid, 0x999999AA, "Key pressed");
  }
  return 1;
}
it doesn't work (I'm not sending that msg in my code, this is just an example)...
it works with no key, I've tried different keys...

is there a plugin, include or another way to do it?

(please don't reply and suggest to use one of the existing debug scripts)

thanks


Re: GetPlayerKeys while frozen - Sascha - 04.05.2011

bump


Re: GetPlayerKeys while frozen - Cameltoe - 04.05.2011

Quote:
Originally Posted by Sascha
Посмотреть сообщение
bump
You should rather give it a try


Re: GetPlayerKeys while frozen - Sascha - 04.05.2011

what you mean?
I've tried on different ways (onplayerkeystatechange, onplayerupdate and a timer) and nothing works..
I could try just to set the player in any interior or so and later set him back to the pos, however I would dislike to do that... hehe


Re: GetPlayerKeys while frozen - Cameltoe - 04.05.2011

Quote:
Originally Posted by Sascha
Посмотреть сообщение
what you mean?
I've tried on different ways (onplayerkeystatechange, onplayerupdate and a timer) and nothing works..
I could try just to set the player in any interior or so and later set him back to the pos, however I would dislike to do that... hehe
Sorry lol, i have incurred an annoying habit ( reading titles only, and reply ) caused by this forum being spammed by Childs.


Re: GetPlayerKeys while frozen - Sascha - 04.05.2011

haha I know what you mean lol...
but any idea for a solution?
with out that I can't continue with my script lol^^


Re: GetPlayerKeys while frozen - armyoftwo - 05.05.2011

Try GetPlayerKeys under OnPlayerUpdate.
It works perfectly, but your code should work too.


Re: GetPlayerKeys while frozen - Cameltoe - 05.05.2011

Quote:
Originally Posted by armyoftwo
Посмотреть сообщение
Try GetPlayerKeys under OnPlayerUpdate.
It works perfectly, but your code should work too.
Quote:
Originally Posted by Sascha
Посмотреть сообщение
what you mean?
I've tried on different ways (onplayerkeystatechange, onplayerupdate and a timer) and nothing works..
I could try just to set the player in any interior or so and later set him back to the pos, however I would dislike to do that... hehe
Look's like you did the same mistake as me.


Re: GetPlayerKeys while frozen - BigETI - 05.05.2011

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE)
    {
        SendClientMessage(playerid, 0x999999AA, "Key pressed");
    }
    return 1;
}
Be sure that you have also returned your OnPlayerKeyStateChange in your Gamemode to 1
pawn Код:
//Main Gamemode Script..
//...
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    //Your stuff in your Gamemode...
    return 1; //<-- Set this to 1 to call this callback in another scripts (Filterscripts, etc.)
}
//Some other stuff you have added...
P.S.: I won't suggest to use GetPlayerKeys on OnPlayerUpdate since this function will be called when a player sends a sync (rapidly)


Re: GetPlayerKeys while frozen - Sascha - 05.05.2011

dude... I would advice you to read what I've said before and try it the way I described...
when the player is frozen (TogglePlayerControllable(playerid, 0) none of this ways works for me, so please don't suggest me a way that I've already mentioned not to work...


Re: GetPlayerKeys while frozen - MadeMan - 05.05.2011

Don't know why it doesn't work for you, but OnPlayerKeyStateChange works for me (frozen or not).


Re: GetPlayerKeys while frozen - Sascha - 05.05.2011

weird..


Re: GetPlayerKeys while frozen - MadeMan - 05.05.2011

Are you inside a vehicle when trying?


Re: GetPlayerKeys while frozen - armyoftwo - 05.05.2011

It should work when player is freezed. In my script it works. I think the problem is somewhere else in the script
Try the code without freezing the player and see if it works

i do it like this
pawn Код:
if(newkeys == KEY_ACTION && oldkeys != KEY_ACTION)



Re: GetPlayerKeys while frozen - Sascha - 05.05.2011

nop, I'm outside of a vehicle... sec I'll post my code...

the command that freezes the player also sets sgtPlayerVehicle[playerid] = 0
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(sgtPlayerVehicle[playerid] != -1)
    {
        if((newkeys & KEY_SECONDARY_ATTACK) && !(oldkeys & KEY_SECONDARY_ATTACK))
        {
            TextDrawHideForPlayer(playerid, Info);
            TextDrawHideForPlayer(playerid, Name[playerid]);
            DestroyVehicle(sgtVehicle[playerid]);
            sgtVehicle[playerid] = -1;
            sgtPlayerVehicle[playerid] = -1;
            TogglePlayerControllable(playerid, 1);
            SetCameraBehindPlayer(playerid);
        }
        else if((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION))
        {
            TextDrawHideForPlayer(playerid, Info);
            TextDrawHideForPlayer(playerid, Name[playerid]);
            sgtVehicle[playerid] = -1;
            sgtPlayerVehicle[playerid] = -1;
            TogglePlayerControllable(playerid, 1);
            SetCameraBehindPlayer(playerid);
        }
    }
    return 1;
}