Opening Doors with a Key instead of a command?
#1

Hey there. How could I open Doors with a key (such as the KEY_LOOK_BEHIND) instead of a command? Where would I create this and what would I put? Thanks.
Reply
#2

try:

https://sampwiki.blast.hk/wiki/Automatic_Gates

try :
https://sampforum.blast.hk/showthread.php?tid=278880

cmon bro look
Reply
#3

This should be enough information to help you, if not, let me know: https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply
#4

you need to make the range higher of the looking:

cuz the gate is prolly to far in the ground:
pawn Код:
else if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        if(PlayerToPoint(10,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
        {
            MoveObject(door1,1558.970703125, -1677.9114990234, 1722.1081542969,1.50);
            MoveObject(door2,1561.9755859375, -1677.8798828125, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
        {
            MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
            MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
        {
            MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
        }
        return 1;
    }
Reply
#5

Everything is fine except when I press the button again it will not close. Only open. How do I make another one so it closes with the same button?
Reply
#6

Just increase the 10
pawn Код:
if(PlayerToPoint(10,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
for the command it's closing cuz the gate is farther away

pawn Код:
else if(PlayerToPoint(20,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
        {
            MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
            MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(20,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
        {
            MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
        }
        return 1;
    }
try that
Reply
#7

Quote:
Originally Posted by MrSnapp
Посмотреть сообщение
Everything is fine except when I press the button again it will not close. Only open. How do I make another one so it closes with the same button?
Here. (Oh, and, I didn't change this myself, but I'd recommend using IsPlayerInRangeOfPoint rather than PlayerToPoint)

At the top of your script, add
pawn Код:
new gate1status;
new gate2status;
new gate3status;
And change
pawn Код:
else if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        if(PlayerToPoint(3.0,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
        {
            MoveObject(door1,1558.1387939453, -1677.8883056641, 1722.1081542969,1.50);
            MoveObject(door2,1562.7950439453, -1677.8798828125, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
        {
            MoveObject(door3,1549.6147460938, -1691.4772949219, 1722.1081542969,1.50);
            MoveObject(door4,1554.2923583984, -1691.4328613281, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
        {
            MoveObject(door5,1560.1309774200, -1651.7266845703, 1719.5637207031,1.50);
        }
        return 1;
    }
    else if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        if(PlayerToPoint(3.0,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
        {
            MoveObject(door1,1558.970703125, -1677.9114990234, 1722.1081542969,1.50);
            MoveObject(door2,1561.9755859375, -1677.8798828125, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
        {
            MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
            MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
        }
        else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
        {
            MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
        }
        return 1;
    }
to this:
pawn Код:
else if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        else {
            if(PlayerToPoint(3.0,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
            {
                if(gate1status == 0) {
                    MoveObject(door1,1558.1387939453, -1677.8883056641, 1722.1081542969,1.50);
                    MoveObject(door2,1562.7950439453, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 1; }
                else if(gate1status == 1) {
                    MoveObject(door1,1558.970703125, -1677.9114990234, 1722.1081542969,1.50);
                    MoveObject(door2,1561.9755859375, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 0; }
            }
            else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
            {
                if(gate2status == 0) {
                    MoveObject(door3,1549.6147460938, -1691.4772949219, 1722.1081542969,1.50);
                    MoveObject(door4,1554.2923583984, -1691.4328613281, 1722.1081542969,1.50);
                    gate2status = 1; }
                else if(gate2status == 1) {
                    MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
                    MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
                    gate2status = 0; }
                }
            }
            else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
            {
                if(gate3status == 0) {
                    MoveObject(door5,1560.1309774200, -1651.7266845703, 1719.5637207031,1.50);
                    gate3status = 1; }
                else if(gate3status == 1) {
                    MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
                    gate3status = 0; }
                }
            }
        }
        return 1;
    }
This should fix it. A quick review of my edits/additions should tell you what exactly the script is doing now, compared to the original code. PM me if it isn't apparent.

Edit: if you saw that, woops
Reply
#8

This code you listed me:
pawn Код:
if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        else {
            if(PlayerToPoint(3.0,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
            {
                if(gate1status == 0) {
                    MoveObject(door1,1558.1387939453, -1677.8883056641, 1722.1081542969,1.50);
                    MoveObject(door2,1562.7950439453, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 1; }
                else if(gate1status == 1) {
                    MoveObject(door1,1558.970703125, -1677.9114990234, 1722.1081542969,1.50);
                    MoveObject(door2,1561.9755859375, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 0; }
            }
            else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
            {
                if(gate2status == 0) {
                    MoveObject(door3,1549.6147460938, -1691.4772949219, 1722.1081542969,1.50);
                    MoveObject(door4,1554.2923583984, -1691.4328613281, 1722.1081542969,1.50);
                    gate2status = 1; }
                else if(gate2status == 1) {
                    MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
                    MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
                    gate2status = 0; }
                }
            }
            else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
            {
                if(gate3status == 0) {
                    MoveObject(door5,1560.1309774200, -1651.7266845703, 1719.5637207031,1.50);
                    gate3status = 1; }
                else if(gate3status == 1) {
                    MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
                    gate3status = 0; }
                }
            }
        }
        return 1;
    }
Gives me these errors:

Quote:

C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(11759) : warning 219: local variable "H" shadows a variable at a preceding level
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17493) : warning 217: loose indentation
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17493) : error 029: invalid expression, assumed zero
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17493) : warning 215: expression has no effect
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17493) : error 001: expected token: ";", but found "if"
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17503) : warning 209: function "RL_OnPlayerKeyStateChange" should return a value
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17504) : error 010: invalid function or declaration
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17507) : error 010: invalid function or declaration
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17509) : error 010: invalid function or declaration
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17511) : error 010: invalid function or declaration
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17514) : error 021: symbol already defined: "GetPlayerHealth"
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17515) : error 021: symbol already defined: "SetPlayerHealthEx"
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17515) : error 029: invalid expression, assumed zero
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17515) : error 010: invalid function or declaration
C:\Users\Grant\Desktop\zGamingRoleplay\gamemodes\Z RP.pwn(17515 -- 17517) : fatal error 107: too many error messages on one line

Reply
#9

Show me the error line
Reply
#10

I had an extra bracket, sorry. Think this will do it.
pawn Код:
if ( PRESSED(KEY_LOOK_BEHIND) )
    {
        if(!IsACop(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not an SAPD Oficer.");
        else {
            if(PlayerToPoint(3.0,playerid,1558.970703125, -1677.9114990234, 1722.1081542969))
            {
                if(gate1status == 0) {
                    MoveObject(door1,1558.1387939453, -1677.8883056641, 1722.1081542969,1.50);
                    MoveObject(door2,1562.7950439453, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 1; }
                else if(gate1status == 1) {
                    MoveObject(door1,1558.970703125, -1677.9114990234, 1722.1081542969,1.50);
                    MoveObject(door2,1561.9755859375, -1677.8798828125, 1722.1081542969,1.50);
                    gate1status = 0; }
            }
            else if(PlayerToPoint(3.0,playerid,1552.7789306641, -1691.4653320313, 1722.1081542969))
            {
                if(gate2status == 0) {
                    MoveObject(door3,1549.6147460938, -1691.4772949219, 1722.1081542969,1.50);
                    MoveObject(door4,1554.2923583984, -1691.4328613281, 1722.1081542969,1.50);
                    gate2status = 1; }
                else if(gate2status == 1) {
                    MoveObject(door3,1550.4266357422, -1691.5009765625, 1722.1081542969,1.50);
                    MoveObject(door4,1553.4294433594, -1691.4515380859, 1722.1081542969,1.50);
                    gate2status = 0; }
            }
            else if(PlayerToPoint(3.0,playerid,1560.1090087891, -1653.4477539063, 1719.5637207031))
            {
                if(gate3status == 0) {
                    MoveObject(door5,1560.1309774200, -1651.7266845703, 1719.5637207031,1.50);
                    gate3status = 1; }
                else if(gate3status == 1) {
                    MoveObject(door5,1560.1090087891, -1653.4477539063, 1719.5637207031,1.50);
                    gate3status = 0; }
            }
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)