Help With Gate Timers
#1

Hello,

If i wanted to set a delay of 45 secs to a gate, how'd i do that..
I'm using [INC] t-Auto Gates
these are my gates:

Код:
//--------Gates--------------
	AddAutoGate(10841, 2207.830322, -3391.702148, 5.505639,0.0,0.0,90.00,2207.830322, -3391.702148, 15.105540,"-1",13);
	AddAutoGate(2634, 2324.563965, -3393.401855, 18.768494,0.0,0.0,00.00,2322.646484, -3393.401855, 18.768494,"-1",4);

Код:
//THIS IS THE INCLUDE

#include <a_samp>
#define MAX_GATES	200
new GateCount = 0, GateTimer = -1,SomeoneNearGate[MAX_GATES];
enum gatesinfo
{
	Created,
	Model,
	Float:closeX,
	Float:closeY,
	Float:closeZ,
	Float:rotX,
	Float:rotY,
	Float:rotZ,
	Float:openX,
	Float:openY,
	Float:openZ,
	NameOpen,
	NameEnter[24],
	Distance,
	GateObject
}
new Gate[MAX_GATES][gatesinfo];

/*
native AddAutoGate(modelid,Float:cX,Float:cY,Float:cZ,Float:rX,Float:rY,Float:rZ,Float:oX,Float:oY,Float:oZ,namecanenter[24],open_distance)
*/
//put "-1" at namecanenter so that everyone can enter it

stock AddAutoGate(modelid,Float:cX,Float:cY,Float:cZ,Float:rX,Float:rY,Float:rZ,Float:oX,Float:oY,Float:oZ,namecanenter[24],open_distance)
{
	GateCount++;
	new ID = GateCount;
	Gate[ID][Created] = 1;
	Gate[ID][Model] = modelid;
	Gate[ID][closeX] = cX;
	Gate[ID][closeY] = cY;
	Gate[ID][closeZ] = cZ;
	Gate[ID][rotX] = rX;
	Gate[ID][rotY] = rY;
	Gate[ID][rotZ] = rZ;
	Gate[ID][openX] = oX;
	Gate[ID][openY] = oY;
	Gate[ID][openZ] = oZ;
	if(!strcmp(namecanenter,"-1",true)) Gate[ID][NameOpen] = 0;
	else
	{
		Gate[ID][NameOpen] = 1;
		format(Gate[ID][NameEnter],24,"%s",namecanenter);
	}
	Gate[ID][Distance] = open_distance;
	Gate[ID][GateObject] = CreateObject(modelid,cX,cY,cZ,rX,rY,rZ);
	if(GateTimer == -1)	GateTimer = SetTimer("CheckGates",100,1);
	return 1;
}

forward CheckGates();
public CheckGates()
{
	for(new ID = 0; ID < MAX_GATES; ID++)
	{
		if(Gate[ID][Created] == 1)
		{
			for(new i = 0; i < GetMaxPlayers(); i++)
			{
				if(IsPlayerConnected(i))
				{
					if(GateEnter(i,ID))
					{
						SomeoneNearGate[ID] = 1;
					}else
					{
						if(SomeoneNearGate[ID] == 0)
						{
							MoveObject(Gate[ID][GateObject],Gate[ID][closeX],Gate[ID][closeY],Gate[ID][closeZ],5);
						}
					}
				}
			}
			if(SomeoneNearGate[ID] == 1)
			{
				MoveObject(Gate[ID][GateObject],Gate[ID][openX],Gate[ID][openY],Gate[ID][openZ],5);
			}
			SomeoneNearGate[ID] = 0;
		}
	}
	return 1;
}

stock GateEnter(playerid, gateid)
{
	if(PlayerToPoint(Gate[gateid][Distance],playerid,Gate[gateid][closeX],Gate[gateid][closeY],Gate[gateid][closeZ]))
	{
		new PlNa[24]; 
		GetPlayerName(playerid,PlNa,24);
		if(Gate[gateid][NameOpen] == 1 && !strfind(PlNa,Gate[gateid][NameEnter],true)) return 1;
		if(Gate[gateid][NameOpen] == 0) return 1;
	}
	return 0;
}

stock PlayerToPoint(Float:radi,playerid,Float:x,Float:y,Float:z)
{
	new Float:oldposx, Float:oldposy, Float:oldposz;
	new Float:tempposx, Float:tempposy, Float:tempposz;
	GetPlayerPos(playerid, oldposx, oldposy, oldposz);
	tempposx = (oldposx -x);
	tempposy = (oldposy -y);
	tempposz = (oldposz -z);
	if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) return 1;
	return 0;
}

BTW, theres an include. Tell me if i have to insert it to.



Regards, 

Borg245
Reply
#2

Well, the include would be a useful sight. And what are the parameters of "AddAutoGate"?
Reply
#3

modelid - objectid
cX - closedgate X coord
cY - closedgate Y coord
cZ - closedgate Z coord
rX - rotation X coord
rY - rotation Y coord
rZ - rotation Z coord
oX - opengate X coord
oY - opengate Y coord
oZ - opengate Z coord
namecanenter - Full or Part of the PlayerName of the Player/Clan that can enter
open_distance - radius, in which a player has to be that the gate opens
Reply
#4

Hmm so there is no way with this type of gate?
Reply
#5

Oh there is. In the OnGameModeInit, place a timer that checks (maybe every 100 milliseconds) if the player is in the range of the gate (i.e. using IsPlayerInRangeOfPoint by ******), and when they do come in the range of the gate, set another timer for 45 seconds. You will have to place a bool on the gate itself though, for when the person is not in the range of the gate, and when they are.
Reply
#6

Well, I honestly wasn't exactly sure how to do such a thing with "AddAutoGate", so I just used the typical auto gate method:

Код:
#include <a_samp>

new gate;
new gate2;
new OpenGate[MAX_PLAYERS];

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Auto Gates ");
	print("--------------------------------------\n");
	gate = CreateObject(10841, 2207.830322, -3391.702148, 15.105540, 0.0,0.0,90.00);
	gate2 = CreateObject(2634, 2322.646484, -3393.401855, 18.768494, 0.0, 0.0, 00.00);
	SetTimerEx("GateCheck", 100, 1, "i");
	return 1;
}

forward GateCheck();
public GateCheck()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			if(PlayerToPoint(5.0, i, 2207.830322, -3391.702148, 15.105540) && OpenGate[i] == 0)
			{
				SetTimerEx("GateOn", 45000, 0, "i");
	  	}
	  	else if(!PlayerToPoint(5.0, i, 2207.830322, -3391.702148, 15.105540) && OpenGate[i] == 1)
	  	{
	  	  MoveObject(gate, 2207.830322, -3391.702148, 15.105540, 5.0);
	    	OpenGate[i] = 0;
			}
		}
	}
	for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			if(PlayerToPoint(5.0, i, 2322.646484, -3393.401855, 18.768494) && OpenGate[i] == 0)
			{
				SetTimerEx("GateOn2", 45000, 0, "i");
	  	}
	  	else if(!PlayerToPoint(5.0, i, 2322.646484, -3393.401855, 18.768494) && OpenGate[i] == 1)
	  	{
	  	  MoveObject(gate2, 2322.646484, -3393.401855, 18.768494, 5.0);
	    	OpenGate[i] = 0;
			}
		}
	}
	return 1;
}

forward GateOn();
public GateOn()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
		  MoveObject(gate, 2207.830322, -3391.702148, 0, 5.0);
		  	OpenGate[i] = 1;
			return 1;
		}
	}
	return 0;
}

forward GateOn2();
public GateOn2()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			MoveObject(gate2, 2322.646484, -3393.401855, 0, 5.0);
		  	OpenGate[i] = 1;
			return 1;
		}
	}
	return 0;
}

stock PlayerToPoint(Float:radi,playerid,Float:x,Float:y,Float:z)
{
	new Float:oldposx, Float:oldposy, Float:oldposz;
	new Float:tempposx, Float:tempposy, Float:tempposz;
	GetPlayerPos(playerid, oldposx, oldposy, oldposz);
	tempposx = (oldposx -x);
	tempposy = (oldposy -y);
	tempposz = (oldposz -z);
	if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) return 1;
	return 0;
}
NOTE: It remains untested. You'll have to test it yourself.
Reply
#7

Quote:
Originally Posted by raydrezack
Well, I honestly wasn't exactly sure how to do such a thing with "AddAutoGate", so I just used the typical auto gate method:

Код:
#include <a_samp>

new gate;
new gate2;
new OpenGate[MAX_PLAYERS];

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Auto Gates ");
	print("--------------------------------------\n");
	gate = CreateObject(10841, 2207.830322, -3391.702148, 15.105540, 0.0,0.0,90.00);
	gate2 = CreateObject(2634, 2322.646484, -3393.401855, 18.768494, 0.0, 0.0, 00.00);
	SetTimerEx("GateCheck", 100, 1, "i");
	return 1;
}

forward GateCheck();
public GateCheck()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			if(PlayerToPoint(5.0, i, 2207.830322, -3391.702148, 15.105540) && OpenGate[i] == 0)
			{
				SetTimerEx("GateOn", 45000, 0, "i");
	  	}
	  	else if(!PlayerToPoint(5.0, i, 2207.830322, -3391.702148, 15.105540) && OpenGate[i] == 1)
	  	{
	  	  MoveObject(gate, 2207.830322, -3391.702148, 15.105540, 5.0);
	    	OpenGate[i] = 0;
			}
		}
	}
	for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			if(PlayerToPoint(5.0, i, 2322.646484, -3393.401855, 18.768494) && OpenGate[i] == 0)
			{
				SetTimerEx("GateOn2", 45000, 0, "i");
	  	}
	  	else if(!PlayerToPoint(5.0, i, 2322.646484, -3393.401855, 18.768494) && OpenGate[i] == 1)
	  	{
	  	  MoveObject(gate2, 2322.646484, -3393.401855, 18.768494, 5.0);
	    	OpenGate[i] = 0;
			}
		}
	}
	return 1;
}

forward GateOn();
public GateOn()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
		  MoveObject(gate, 2207.830322, -3391.702148, 0, 5.0);
		 	OpenGate[i] = 1;
			return 1;
		}
	}
	return 0;
}

forward GateOn2();
public GateOn2()
{
  for(new i = 0; i < GetMaxPlayers(); i++)
  {
    if(IsPlayerConnected(i))
		{
			MoveObject(gate2, 2322.646484, -3393.401855, 0, 5.0);
		 	OpenGate[i] = 1;
			return 1;
		}
	}
	return 0;
}

stock PlayerToPoint(Float:radi,playerid,Float:x,Float:y,Float:z)
{
	new Float:oldposx, Float:oldposy, Float:oldposz;
	new Float:tempposx, Float:tempposy, Float:tempposz;
	GetPlayerPos(playerid, oldposx, oldposy, oldposz);
	tempposx = (oldposx -x);
	tempposy = (oldposy -y);
	tempposz = (oldposz -z);
	if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) return 1;
	return 0;
}
NOTE: It remains untested. You'll have to test it yourself.
so, i can say that this actually works (lol had to change one coordinate actually but it was worth it at the end) now if you dont mind do you know how to actually show the coutdwon time in text? Like 45,44,43 appearing at the bottom left of your screen for gate 1 and on the upper right hand side of the screen for gate 2.

thanks in advance,

Borg245
Reply
#8

Countdowns are a bit of a hassle, so I'll just toss ya this:
http://forum.sa-mp.com/index.php?topic=50842.0

Use CountDownForPlayer (though, I've never used it.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)