SA-MP Forums Archive
AutoGates - Howto? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: AutoGates - Howto? (/showthread.php?tid=92076)



AutoGates - Howto? - cozza123456 - 18.08.2009

How do i convert this script so it closes automatically when the player that opened it walks away?




if(strcmp(cmdtext,"/secret", true) == 0) //CLOSEGATE
{
if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
{
MoveObject(cozgate, -2468.352051, 1547.224243, 21.280209, 2.0);
}
return 1;
}

if(strcmp(cmdtext,"/secret1", true) == 0) //OPENGATE
{
if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
{
MoveObject(cozgate, -2468.371338, 1547.240723, 24.030167, 2.0);
}
return 1;
}


Re: AutoGates - Howto? - Hei2 - 18.08.2009

You'd have to create a timer to constantly check the area of the player and I'd suggest staying away from timers if you can. If you're willing to wait I'm make something for you that should work.


Re: AutoGates - Howto? - _Vortex - 18.08.2009

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


Re: AutoGates - Howto? - cozza123456 - 18.08.2009

hei im happy to wait, all i need is auto close not auto open? ty


Re: AutoGates - Howto? - Takumi.WS - 18.08.2009

Well, make a command to open the gate that you want, then make a timer, to close the gate after a specific time


Re: AutoGates - Howto? - Hei2 - 18.08.2009

Код:
new GatePos; //Checks if the gate is open or closed ((Add this to the top of your code))
new AreaTimer; //Variable assigned to the Area timer ((Add this to the top of your code))
forward Area(playerid); //Script initiated for the timer ((Add this to the top of your code))

GatePos = 0; //((Add this part to the OnGameModeInit))

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/secret", cmdtext, true, 10) == 0)
	{
		if(GatePos==0)
		{
		  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  		{
     		MoveObject(cozgate, -2468.371338, 1547.240723, 24.030167, 2.0);
     		GatePos=1;
     		AreaTimer=SetTimerEx("Area",1,true,"d",playerid);
    	}
    	else
    	{
    	  SendClientMessage(playerid,0xFFFF00AA,"You are not near the gate!");
    	}
		}
		else
		{
		  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  		{
     		MoveObject(cozgate, -2468.352051, 1547.224243, 21.280209, 2.0);
				GatePos=0;
     		KillTimer(AreaTimer);
    	}
    	else
    	{
    	  SendClientMessage(playerid,0xFFFF00AA,"You are not near the gate!");
    	}
		}
		return 1;
	}
	return 0;
}

public Area(playerid)
{
  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  {
  }
	else
	{
	  MoveObject(cozgate, -2468.352051, 1547.224243, 21.280209, 2.0);
	  GatePos=0;
	  KillTimer(AreaTimer);
	}
	return 1;
}
This should work. If it doesn't, feel free to ask for help.

EDIT: I added some coding so if you haven't copied it recently, replace all the code in public OnPlayerCommandText and public Area(playerid).


Re: AutoGates - Howto? - cozza123456 - 18.08.2009

C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(373) : warning 217: loose indentation
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(373) : error 029: invalid expression, assumed zero
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(373) : error 029: invalid expression, assumed zero
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(374) : warning 217: loose indentation
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(40 : warning 225: unreachable code
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(40 : error 029: invalid expression, assumed zero
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(40 : error 004: function "Area" is not implemented
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(419) : warning 217: loose indentation
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(422) : warning 225: unreachable code
C:\Users\Administrator\Desktop\SAMPSERVER (1)\gamemodes\CJFreeRoam212121.pwn(422) : warning 217: loose indentation

373 = public OnPlayerCommandText(playerid, cmdtext[])

408 =public Area(playerid)

419 = return 1;

422 = if(strcmp(cmdtext,"/bclose", true) == 0) //CLOSEGATE
EDIT:
accidently put 408 twice

And err how do i make my code come up like yours!?
408 =


Re: AutoGates - Howto? - Hei2 - 18.08.2009

Remember to add:
Код:
new GatePos; //Checks if the gate is open or closed
new AreaTimer; //Variable assigned to the Area timer
forward Area(playerid); //Script initiated for the timer
All to the top of your script.

Instead of adding "public OnPlayerCommandText(playerid, cmdtext[])"
Код:
if (strcmp("/secret", cmdtext, true, 10) == 0)
	{
		if(GatePos==0)
		{
		  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  		{
     		MoveObject(cozgate, -2468.371338, 1547.240723, 24.030167, 2.0);
     		GatePos=1;
     		AreaTimer=SetTimerEx("Area",1,true,"d",playerid);
    	}
    	else
    	{
    	  SendClientMessage(playerid,0xFFFF00AA,"You are not near the gate!");
    	}
		}
		else
		{
		  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  		{
     		MoveObject(cozgate, -2468.352051, 1547.224243, 21.280209, 2.0);
				GatePos=0;
     		KillTimer(AreaTimer);
    	}
    	else
    	{
    	  SendClientMessage(playerid,0xFFFF00AA,"You are not near the gate!");
    	}
		}
		return 1;
	}
Put that inside the "public OnPlayerCommandText(playerid, cmdtext[])"

And add:
Код:
public Area(playerid)
{
  if(PlayerToPoint(15.0, playerid, -2468.3889, 1547.0945, 23.8359))
  {
  }
	else
	{
	  MoveObject(cozgate, -2468.352051, 1547.224243, 21.280209, 2.0);
	  GatePos=0;
	  KillTimer(AreaTimer);
	}
	return 1;
}
To the bottom of your script.


Re: AutoGates - Howto? - cozza123456 - 18.08.2009

ok, compiled. now to test!

ty!


Re: AutoGates - Howto? - Hei2 - 18.08.2009

Good luck