Today i release a simple function
What it do is add a gate ,at the entrance of Mansion,which can open and close by hotkeys.
OnPlayerStart function.
we bind the key and create the gate here.Also we will make a global variable that tell us is gate open or close.
OnServerStart()
{
open <- false;
mansiongate <- CreateObject(6000,0,Vector(-277, -495, 10),255);
opengate <- BindKey(true,0x104F ,0,0); //The Key IS "O"
closegate <- BindKey(true,0x205A,0,0); //The Key IS "Z"
}
OnKeyDown function
where we will add our function.
function onKeyDown(player, bindid)
{
if(bindid==opengate)
{
if(open==false) MoveGate(player,mansiongate.ID,"open");
else MessagePlayer("Gate is already open.",player);
}
else if(bindid==closegate)
{
if(open==true) MoveGate(player,mansiongate.ID,"close");
else MessagePlayer("Gate is already closed.",player);
}
}
MoveGate function
we will open or close the gate here.
function MoveGate(player,gate, status)
{
local obj=FindObject(gate);
if(obj)
{
if(status=="open")
{
MessagePlayer("Opening Gate",player);
obj.MoveBy(Vector(8,0,0), 2800);
open=true;
}
else if(status=="close")
{
MessagePlayer("Closing Gate",player);
obj.MoveBy(Vector(-8,0,0), 2800);
open=false;
}
}
else MessagePlayer("Object could not be found.",player);
}
This is it for this function or
If you want to only use 1 key for both opening and closing then use this.
OnPlayerStart function.
Same just we dont bind the key "Z".
OnServerStart()
{
open <- false;
mansiongate <- CreateObject(6000,0,Vector(-277, -495, 10),255);
gate <- BindKey(true,0x104F ,0,0); //The Key IS "O"
}
OnKeyDown function
we will only use one key here.
function onKeyDown(player, bindid)
{
if(bindid==gate)
{
if(open==false) MoveGate(player,masiongate.ID,"open");
else MoveGate(player,mansiongate.ID,"close");
}
}
MoveGate function
Same func
function MoveGate(player,gate, status)
{
local obj=FindObject(gate);
if(obj)
{
if(status=="open")
{
MessagePlayer("Opening Gate",player);
obj.MoveBy(Vector(8,0,0), 2800);
open=true;
}
else if(status=="close")
{
MessagePlayer("Closing Gate",player);
obj.MoveBy(Vector(-8,0,0), 2800);
open=false;
}
}
else MessagePlayer("Object could not be found.",player);
}
Screenshots: