Check if object fully closed or opened
#1

Hi,

How to check if object fully open or closed? Like i don't want player get open/close when gates is not full in open or close position.
Reply
#2

You can add a timer for how long the gate takes to open, example if it takes 1/2 seconds for the gate to open make a timer for 1 / 2 seconds, add a variable like this to remember.

Код:
new gateOpen;

if(gateOpen == 1)
{
    add here the code to happen if the gate is opened fully
    gateOpen = 2;
}
if(gateOpen == 2)
{
  add here what to happen if the gate is opening... in the process to open
  SendClientMessage(playerid, -1, "The gate is opening... please way.");
  SetTimerEx("gateOpenTimer", 2000, false, "i", playerid);//the timer
}
if(gateOpen == 0)
{
  add here to happen if the gate is closed.
  gateOpen = 2;
}


forward gateopentimer(playerid);
public gateopentimer
{
   gateOpen = 0;
   This will happen when the gate fully opened or closed.
}
Not sure if it will work well, you have to modify it a bit to suit your system and work for everyone that tries the .
You will need few more variables for it to work well but I gave you an idea.
Reply
#3

It's possible with getobjectpos ?
Reply
#4

A timer is un-necessary and I recommend using the following callback, which is called when an object finishes moving..

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

A similar callback is available for player objects and dynamic objects.

I assume you're using something like the following function to open/close it:

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

When using the move object function, I would set a variable belonging to the gate to indicate it is moving (not fully opened or closed). Then at the OnObjectMoved callback, set the variable to some number to indicate opened/closed position. For example, some psuedo code of how I might do it:

PHP код:
//Some Defines
#define GATE_POS_CLOSED 0
#define GATE_POS_OPENING 1
#define GATE_POS_OPEN 2
#define GATE_POS_CLOSING 3
//Some Variables
new myGate CreateObject(...);
new 
myGatePos;
public 
OnObjectMoved(objectid)
{
    if (
objectid == myGate)
    {
        
//Check if object was opening..
        
if (myGatePos == GATE_POS_OPENING)
        {
            
myGatePos GATE_POS_OPEN;    //Mark gate as now open
        
}
        
        
//Check if object was closing
        
else if (myGatePos == GATE_POS_CLOSING)
        {
            
myGatePos GATE_POS_CLOSED;    //Mark gate as now closed
        
}
    }    
    return 
1;
}
SomeGateMovingFunction(...)
{    
    if (
myGatePos == GATE_POS_OPEN)
    {
        
MoveObject(myGate, ... to closed coordinates ...);    //Mov object toward closed pos
        
myGatePos GATE_POS_CLOSING;                //Mark object as closing
        
    
}
    
    else if (
myGatePos == GATE_POS_CLOSED)
    {
        
MoveObject(myGate, ... to closed coordinates ...);    //Move gate toward open pos
        
myGatePos GATE_POS_OPENING;                //Mark object as opening
    
}    
    return 
value;
        

P.s. I have used a similar method in the past which worked successfully.
Reply
#5

Timer is worth it, or else the gate will open, then shut without any pause.

That is if it's an auto-open/close gate.


As for OP, you're going to have to start learning some scripting, as constantly asking for "help" and simply being handed the answers, obviously isn't helping you out in the long term...
Reply
#6

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Timer is worth it, or else the gate will open, then shut without any pause.

That is if it's an auto-open/close gate.
It won't as long as he doesn't call the Function from inside OnObjectMoved (i.e. manually with a command).

I'm guessing you mean use a timer to call it at a delay inside this callback, sounds appropriate for an automatic gate
Reply
#7

Yea, just the idea of having the gate open, then close like every server has, as we all know those noobs that want to run through the gate you're heading through just to mess around.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)