Automatic Gates?
#1

Hey, I need help with making a Gate that Closes automatically after it was open with a command to open it below? :P Could you show me what this code should look like?
pawn Код:
#include <a_samp>
#include <streamer>

#define FILTERSCRIPT
#pragma tabsize 0

#define COLOR_BLUE 0x0000BBAA

#define COLOR_RED 0xAA3333AA

#define COLOR_LIGHTBLUE 0x33CCFFAA

new Gate1;

public OnFilterScriptInit()
{
    Gate1 = CreateObject(980,1337.3000488,687.9000244,12.6000004,0.0000000,0.0000000,270.0000000);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/opengate 1111", true)){
        if(IsPlayerInRangeOfPoint(playerid, 15.0, 1337.3000488,687.9000244,12.6000004)){
            MoveObject(Gate1, 1337.3000488,687.9000244,17.6509991, 3.0, 0.0000000,0.0000000,270.0000000);
            SendClientMessage(playerid, COLOR_BLUE, "Gate(1) Opened Successfuly , Weclome !");
            return 1;
        }
    }
    if(!strcmp(cmdtext, "/closegate 1111", true)){
        if(IsPlayerInRangeOfPoint(playerid, 15.0,  1337.3000488,687.9000244,12.6000004)){
            MoveObject(Gate1,  1337.3000488,687.9000244,12.6000004, 3.0, 0.0000000,0.0000000,270.0000000);
            SendClientMessage(playerid, COLOR_RED, "Gate(1) Closed successfuly !");
            return 1;
        }
    }
    return 0;
}
public OnFilterScriptExit()
{
    return 1;
}
Reply
#2

You're going to need to download the YSI library and put the YSI folder in your /pawno/includes directory... You will also need the foreach include, put that in your pawno/includes directory as well!

pawn Код:
#include <a_samp>
#include <YSI\y_timers>
#include <foreach>

#define COLOR_BLUE 0x0000BBAA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTBLUE 0x33CCFFAA

#define MAX_GATES 10 // change 10 to the amount of gates you have

new Gate1,
    bool:GateOpen[MAX_GATES] = false;

public OnFilterScriptInit()
{
    Gate1 = CreateObject(980,1337.3000488,687.9000244,12.6000004,0.0000000,0.0000000,270.0000000);
    return 1;
}
   
timer gateCheck[1000]() // timer function to check the gate every 1 second
{
    foreach(new i : Player) // loop through connected players
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, 1337.3000488,687.9000244,12.6000004)) // is anyone near the gate?
        {
            if(!GateOpen[1]) // check if the bool statement is set to gate1 being open
            {
                GateOpen[1] = true; // set a bool statement; this says that gate1 is open
                MoveObject(Gate1, 1337.3000488,687.9000244,17.6509991, 3.0, 0.0000000,0.0000000,270.0000000);
                SendClientMessage(i, COLOR_BLUE, "Gate(1) Opened Successfuly , Weclome !"); // send them a message; the gate is open!
               
                defer AutoCloseGate(); // call a timer to auto-close the gate
               
                break; // stop the loop, we found the person
            }
        }
    }
}
       
timer AutoCloseGate[5000]() // timer function to close the gate every 5 seconds
{
    if(GateOpen[i]) // is the gate even open?
    {
        GateOpen[1] = false; // set the gate to closed
        MoveObject(Gate1,  1337.3000488,687.9000244,12.6000004, 3.0, 0.0000000,0.0000000,270.0000000); // close the gate
    }
}
Reply
#3

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
You're going to need to download the YSI library and put the YSI folder in your /pawno/includes directory... You will also need the foreach include, put that in your pawno/includes directory as well!

pawn Код:
#include <a_samp>
#include <YSI\y_timers>
#include <foreach>

#define COLOR_BLUE 0x0000BBAA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTBLUE 0x33CCFFAA

#define MAX_GATES 10 // change 10 to the amount of gates you have

new Gate1,
    bool:GateOpen[MAX_GATES] = false;

public OnFilterScriptInit()
{
    Gate1 = CreateObject(980,1337.3000488,687.9000244,12.6000004,0.0000000,0.0000000,270.0000000);
    return 1;
}
   
timer gateCheck[1000]() // timer function to check the gate every 1 second
{
    foreach(new i : Player) // loop through connected players
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, 1337.3000488,687.9000244,12.6000004)) // is anyone near the gate?
        {
            if(!GateOpen[1]) // check if the bool statement is set to gate1 being open
            {
                GateOpen[1] = true; // set a bool statement; this says that gate1 is open
                MoveObject(Gate1, 1337.3000488,687.9000244,17.6509991, 3.0, 0.0000000,0.0000000,270.0000000);
                SendClientMessage(i, COLOR_BLUE, "Gate(1) Opened Successfuly , Weclome !"); // send them a message; the gate is open!
               
                defer AutoCloseGate(); // call a timer to auto-close the gate
               
                break; // stop the loop, we found the person
            }
        }
    }
}
       
timer AutoCloseGate[5000]() // timer function to close the gate every 5 seconds
{
    if(GateOpen[i]) // is the gate even open?
    {
        GateOpen[1] = false; // set the gate to closed
        MoveObject(Gate1,  1337.3000488,687.9000244,12.6000004, 3.0, 0.0000000,0.0000000,270.0000000); // close the gate
    }
}
Thank you, +REP!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)