Author Topic: Mansion Gate  (Read 5604 times)

0 Members and 1 Guest are viewing this topic.

Offline Flockshot

  • Street Thug
  • *
  • Posts: 29
    • View Profile
Mansion Gate
« on: October 11, 2014, 07:38:51 pm »
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.
Code: [Select]
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.
Code: [Select]
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.
Code: [Select]
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".
Code: [Select]
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.
Code: [Select]
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
Code: [Select]
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:


« Last Edit: October 12, 2014, 08:39:30 am by Flockshot »

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Mansion Gate
« Reply #1 on: October 12, 2014, 12:19:33 am »
By releasing this script to the public, you will help many newbies. :)
(I would use a class to create these gates, to make it easier, instead of this way)
But...  there is a problem. What happens if the gate is not id 0 ?Another object will move instead of the gate.

To fix that, note the object with an word like "mansiongate".
How you do that ? Like this:
Code: [Select]
mansiongate <- CreateObject(6000,0,Vector(-277, -495, 10),255);
Then you simply move it using:
Code: [Select]
mansiongate.MoveBy(Vector(-8,0,0), 2800);


By the way, it's good that it uses a global function as "MoveGate", for closing/opening the gate.
I suggest you to add one more parameter that will represent the gate (object), so you can use the same function for any gate you want. :P
Like this:
Code: [Select]
function MoveGate(player,gate,status)
{
   if(status="open")
   {
         obj.MoveBy(Vector(8,0,0), 2800);
   }
}



Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Flockshot

  • Street Thug
  • *
  • Posts: 29
    • View Profile
Re: Mansion Gate
« Reply #2 on: October 12, 2014, 08:41:25 am »
By releasing this script to the public, you will help many newbies. :)
(I would use a class to create these gates, to make it easier, instead of this way)
But...  there is a problem. What happens if the gate is not id 0 ?Another object will move instead of the gate.

To fix that, note the object with an word like "mansiongate".
How you do that ? Like this:
Code: [Select]
mansiongate <- CreateObject(6000,0,Vector(-277, -495, 10),255);
Then you simply move it using:
Code: [Select]
mansiongate.MoveBy(Vector(-8,0,0), 2800);


By the way, it's good that it uses a global function as "MoveGate", for closing/opening the gate.
I suggest you to add one more parameter that will represent the gate (object), so you can use the same function for any gate you want. :P
Like this:
Code: [Select]
function MoveGate(player,gate,status)
{
   if(status="open")
   {
         obj.MoveBy(Vector(8,0,0), 2800);
   }
}


Hmm.
I have chnaged it now the function will work for any object and also i have created class for mansion gate.
player can add multiple gates in game and can only use one function.

Offline soulshaker

  • Street Thug
  • *
  • Posts: 21
    • View Profile
    • Ethical DM VC:MP 0.4
Re: Mansion Gate
« Reply #3 on: October 12, 2014, 12:09:21 pm »
Why not you make the gate auto open and close instead of bindkeys, as if some newbies joins server they may face problem to enter or exit mansion(just a suggestion)

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: Mansion Gate
« Reply #4 on: October 12, 2014, 12:56:54 pm »
Why not you make the gate auto open and close instead of bindkeys, as if some newbies joins server they may face problem to enter or exit mansion(just a suggestion)

it can be configured to be actioned just by the owner of the property. ;p



Hmm.
I have chnaged it now the function will work for any object and also i have created class for mansion gate.
player can add multiple gates in game and can only use one function.

By class I mean class{} with constructor and etc.
(so it would be easier to check gate's status, like gate.status that will return the status of the gate, obviously)
Anyway, here comes another problem... the variable open is a global one, so when a player will open/close any gate, it will be set for all instead of only to that gate.

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.