help key state - 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: help key state (
/showthread.php?tid=267499)
help key state -
[MKD]Max - 08.07.2011
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
Re: help key state -
WoodPecker - 08.07.2011
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);
}
Re: help key state -
andruz99 - 08.07.2011
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.
Re: help key state -
Unte99 - 11.07.2011
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.