help key state
#1

i know how to make agate open whie you press akey but i need from you help how to make the gate close in the same key help
Reply
#2

Well just change the gate object position when closing gate... an example here:

pawn Код:
if(gate==0)
{
gate = 1;
MoveObject(gatename, 1588.965698, -1637.882690, 7.710285, 1.50);
}
else if(gate==1)
{
gate= 0;
MoveObject(gatename, 1588.965698, -1637.882690, 15.260185, 1.50);
}
Reply
#3

if you want your gates open when you press a key then you have to put your codes under this function

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{


	return 1;
}
il make you a example:

oh and here you can get the button id-s https://sampwiki.blast.hk/wiki/GetPlayerKeys
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if(newkeys & KEY_SPRINT) // Sprint key, when you want you character run faster
   {
if(gate==0)
{
gate = 1;
MoveObject(gatename, 1588.965698, -1637.882690, 7.710285, 1.50);
}
else if(gate==1)
{
gate= 0;
MoveObject(gatename, 1588.965698, -1637.882690, 15.260185, 1.50);
    }

}
	return 1;
}
its pretty easy, just the function needs to be scripted better, it was just given for an example, you have to change to your likings.
Reply
#4

He want's to close the gate with the same key...

On top of the script

pawn Код:
new bool:namewhateveryouwant;
OnPlayerKeyStateChange

pawn Код:
if(newkeys & your key)
    {
        if(IsPlayerInRangeOfPoint(.....)) // If you want that a player could only open/close the gate if he's close to your desired position.
        {
            if(namewhateveryouwant== false) // if the gate is closed. By default, the namewhateveryouwant bool will be false when the server starts.
            {
                MoveObject(........);
                namewhateveryouwant = true;
                return 1;
            }
            else
            {
                 MoveObject(......);
                 namewhateveryouwant = false;
                 return 1;
            }
        }
    }
Bools are useful when you want to check if a thing is closed/opened or something like that. Also you can create door locks by the help of the bools, just the way i showed you.

EDIT: Woodpecker, don't edit your wrong scripts and copy and paste the good one's to your post. It will just get you banned.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)