changing CMD: to Key
#1

Hello, I have command Called /door, which moves the LSPD doors inside the Lobby, I wanted to ask if you guys can help me change the /door to a KEY.. for example, instead of writing /door, pressing F and the door will open..

Here's the /door Command:
Код:
CMD:door(playerid, params[])
	{
	    if(IsPlayerConnected(playerid))
	    { new  string[ 128 ];
	        if(PlayerInfo[playerid][pFaction] == 1)
			{
			    if(IsPlayerInRangeOfPoint(playerid, 3, 246.3489,72.0905,1003.6406))
			    {

			        new name[MAX_PLAYER_NAME];
			        GetPlayerName(playerid, name, sizeof(name));

					    if(IsLSPDDoorOpen == 0)
				    	{
				    		MoveDynamicObject(lspddoor1, 248.35150146484, 72.547714233398, 1002.640625, 1.50);
				    		MoveDynamicObject(lspddoor2, 243.03300476074, 72.547714233398, 1002.640625, 1.50);
      			 			ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
				    		format(string, sizeof(string), "* %s slides their card and opens the door", name);
				    		ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    		IsLSPDDoorOpen = 1;
						}
   				         else
				    	{
				    	    IsLSPDDoorOpen = 0;
					    	MoveDynamicObject(lspddoor1, 246.35150146484, 72.547714233398, 1002.640625, 1.50);
          					MoveDynamicObject(lspddoor2, 245.03300476074, 72.568511962891, 1002.640625, 1.50);
          					ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
                            format(string, sizeof(string), "* %s slides their card and closes the door", name);
				    		ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                            IsLSPDDoorOpen = 0;
						}

					}
			}
	    }
		return 1;
	}
Reply
#2

pawn Код:
// At the top of script under includes:

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

// Under below public, if you don't have replace with OnPlayerStateChange();

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new string[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    if(PRESSED(KEY_SECONDARY_ATTACK))
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pFaction] == 1)
            {
                if(IsLSPDDoorOpen == 0)
                {
                    MoveDynamicObject(lspddoor1, 248.35150146484, 72.547714233398, 1002.640625, 1.50);
                    MoveDynamicObject(lspddoor2, 243.03300476074, 72.547714233398, 1002.640625, 1.50);
                    ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
                    format(string, sizeof(string), "* %s slides their card and opens the door", name);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    IsLSPDDoorOpen = 1;
                }
                else
                {
                    IsLSPDDoorOpen = 0;
                    MoveDynamicObject(lspddoor1, 246.35150146484, 72.547714233398, 1002.640625, 1.50);
                    MoveDynamicObject(lspddoor2, 245.03300476074, 72.568511962891, 1002.640625, 1.50);
                    ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
                    format(string, sizeof(string), "* %s slides their card and closes the door", name);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    IsLSPDDoorOpen = 0;
                }
            }
        }
    }
    return 1;
}
- I made in case if he press Enter. You can change by search on Keys on Wiki SA-MP.
Reply
#3

Still not moving :\ got any idea why?
Reply
#4

@HY - Could you add me on skype xcrazy55 so you will help me?
it easier to chat there ... :\
Reply
#5

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new string[128], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(newkeys == KEY_SECONDARY_ATTACK)
{if(PlayerInfo[playerid][pFaction] == 1)
            {
                if(IsPlayerInRangeOfPoint(playerid, 3, 246.3489,72.0905,1003.6406))
                {
                        if(IsLSPDDoorOpen == 0)
                        {
                            MoveDynamicObject(lspddoor1, 248.35150146484, 72.547714233398, 1002.640625, 1.50);
                            MoveDynamicObject(lspddoor2, 243.03300476074, 72.547714233398, 1002.640625, 1.50);
                            ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
                            format(string, sizeof(string), "* %s slides their card and opens the door", name);
                            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                            IsLSPDDoorOpen = 1;
                        }
                         else
                        {
                            IsLSPDDoorOpen = 0;
                            MoveDynamicObject(lspddoor1, 246.35150146484, 72.547714233398, 1002.640625, 1.50);
                            MoveDynamicObject(lspddoor2, 245.03300476074, 72.568511962891, 1002.640625, 1.50);
                            ApplyAnimation(playerid, "HEIST9", "Use_SwipeCard", 10.0, 0, 0, 0, 0, 0);
                            format(string, sizeof(string), "* %s slides their card and closes the door", name);
                            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                            IsLSPDDoorOpen = 0;
                        }

                    }
            }
        }
        return 1;
    }
return 0;
}
Reply
#6

If I already have "OnPlayerKeyStateChange"... What should I do?
Reply
#7

Anyone got Idea?
After I added what you told me.. when i Comply it shows me:


Reply
#8

As our colleague above said, use:
pawn Код:
// At the top of script under includes:

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
Then under OnPlayerKeyStateChange just detect the key that you want and use a redirection, don't repeat the code because there's no need for that at all. Just do it like this:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
        if(newkeys == KEY_SECONDARY_ATTACK)       return cmd_door(playerid, "door");
        return 1;
}
Reply
#9

Quote:
Originally Posted by davidstyle1125
Посмотреть сообщение
Anyone got Idea?
After I added what you told me.. when i Comply it shows me:


Delete your OnPlayerKeyStateChange, you can't have two of them.
Reply
#10

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
Delete your OnPlayerKeyStateChange, you can't have two of them.
Alright, but if I already have 2, how do I place the second "OnPlayerKeyStateChange"?

I mean What should I put instade of "OnPlayerKeyStateChange" to make it work.. ?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)