[Tutorial] How to make a moving gate on command
#1

Hey this is my first post and first tutorial, hope you like it.
The gate you are gonna make will open on command and only if you use the command close to the gate.
Im using PAWNO and using a blank script for this tutorial.

Things you need before making your gate:
Coords:
You can get a coord by using MTA Map editor, placing your gate and saving the map.
Then convert the map using a map converter(i use this)

There are more ways to get your coords but i think this one is fairly easy to use.

Explaining coords:
Код:
movingdoor1	=	CreateObject(3093, 2354.3403320313, -650.77142333984, 127.85127258301, 0, 0, 269.5);

movingdoor1	=	CreateObject(object id, x coord, y coord, z coord, x rotation axis, y rotation axis, z rotation axis);
Step 1:
Get the coords for your gate in closed position and in open position.

Step 2:
Under #include <a_samp>
you should type: new yourgatename;
So it should look like this:
Код:
#include <a_samp>
new movingdoor1;
In my case im making a door but it will work the same for a gate.

Step 3:
Add the coords from the closed gate to your public OnGameModeInit()
It should look like this:
Код:
public OnGameModeInit()
{
	// Don't use these lines if it's a filterscript
	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	movingdoor1	=	CreateObject(3093, 2354.3403320313, -650.77142333984, 127.85127258301, 0, 0, 269.5);

	return 1;
}
Step 4:
Ok this is where your gonna script the gate to move when you use the by-you-designed command
Go down to public OnPlayerCommandText(playerid, cmdtext[])
Now you should type this under public OnPlayerCommandText(playerid, cmdtext[]):
Код:
{
	if (!strcmp("/close", cmdtext))
	{
		if(IsPlayerInRangeOfPoint(playerid, 7.0, 2353.693359375, -650.77709960938, 127.85127258301))
		{
	  MoveObject(movingdoor1, 2354.3403320313, -650.77142333984, 127.85127258301, 1);
		SendClientMessage(playerid, 0xEF994300, "The gate has closed.");
		 }
 		return 1;
	}

	if (!strcmp("/open", cmdtext))
	{
	  if(IsPlayerInRangeOfPoint(playerid, 7.0, 2353.693359375, -650.77709960938, 127.85127258301))
 	{
 		MoveObject(movingdoor1, 2353.693359375, -650.77709960938, 127.85127258301, 1);
    SendClientMessage(playerid, 0xEF994300, "The gate has opened.");
		}
		return 1;
	}
IsPlayerInRangeOfPoint is a function that you can use to set a radius a player has to be in before he can use the command.
MoveObject moves the object
SendClientMessage gives the player that used the command a message

_________________________________________________

Thats my small tutorial on making a moving gate on command.
If you have any questions, ask them in here.

Made by me, Please do not RIP
Reply
#2

There are plenty of tutorials on this,
There are some to do automatic gates which alot of people prefer to commands
Reply
#3

Joe could you tell me how to give ranks to people.
Like rank 0 can't open a specific gate, and rank 1 can.
Reply
#4

pawn Код:
if (Rank[playerid] == 0)
{
}
else if (Rank[playerid] == 1)
{
// Gate Stuff
}
But if you have account system you can use that but change the rank format around
Reply
#5

Ok and if i want a message to display like:
Код:
SendClientMessage(playerid, 0xEF994300, "You are not close enough to a gate.");
when a player uses the command but isn't within the radius.
Reply
#6

pawn Код:
if(IsPlayerInRangeOfPoint
{
//Whatever here
}
else
{
//Message
}
Reply
#7

ALlright Joe, i got one more question.
Iґm trying to make it that a gate opens, when you come near it with a specific vehicle.
The vehicle i want it to open with is the Camper - vehicle id 483, it's the only vehicle in my script atm.
I have tried some things myself but it doesnt seem to work.

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(IsPlayerInVehicle(playerid,0))
	{
	  if(IsPlayerInRangeOfPoint(playerid, 5, 2351.5935058594, -659.27545166016, 127.52456665039))
		{
		  MoveObject(garage, 2351.5935058594, -659.27545166016, 125.0, 1);
		}
	}
	else
	{
	MoveObject(garage,2351.5935058594, -659.27545166016, 127.52456665039, 1);
	}
	
	return 1;
}
I dunno if its in the right public thingy.
Could you tell me how to fix this, explenation would be awsome
Reply
#8

https://sampwiki.blast.hk/wiki/Automatic_Gates
Reply
#9

gates donґt seem to work, i keep getting errorґs
I have no idea where to put
Код:
public CheckGate()
{
  new c_gate_status;
  for(new i;i<MAX_PLAYERS;i++)
  {
    if(!IsPlayerConnected(i)) continue;
    /* You would only use this if you're using SA-MP v0.2x or lower
    if(PlayerToPoint(10.0, i, closed_X, closed_Y, closed_Z))c_gate_status = 1;
    */
    if(IsPlayerInRangeOfPoint(i,10.0,closed_X,closed_Y,closed_Z))c_gate_status = 1;
  }
  if(c_gate_status)MoveObject(c_gate, open_X, open_Y, open_Z,Moving Speed);
  else MoveObject(c_gate, closed_X, closed_Y, closed_Z,Moving Speed);
}
and
Код:
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
  new Float:oldpos[3], Float:temppos[3];
  GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
  temppos[0] = (oldpos[0] -X);
  temppos[1] = (oldpos[1] -Y);
  temppos[2] = (oldpos[2] -Z);
  if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
  {
    return true;
  }
  return false;
}
Reply
#10

1. Dont use isplayerinpoint replace with isplayerinrangeofpoint
2. Gatecheck goes outside callbacks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)