24.12.2010, 19:42
I havent seen many of these around so i decided to make one.
Ok, first we need to include a_samp so all the functions will work. So we will want to put this at the top of the script.
Then we need to forward the timer that we will use later on. So we put this under #include <a_samp>
Then we will want to create something to store the gate object. So we will want to put this under the include and forward.
Ok, if you have a filterscript you will use "OnFilterScriptInit" instead of "OnGameModeInit", im using "OnGameModeInit" here, Change it to "OnFilterScriptInit" if your puting this into a filterscript instead.
Now we want to add the timer that we forwarded before to check if a player is near the gate.
You can change 500 to a lower amount if you want, but the lower amount you take the more it might lag your server.
And now we want to create the gate object and attach the something that stores the object.
I have selected to create my object at the co-ords 2641.8201, 2810.6196 and 36.3222.
Read https://sampwiki.blast.hk/wiki/CreateObject for more information about this function.
When we are done it should look something like this
And at last, we want to create the timer function that we forwarded at first.
Then we will want to make a loop for all players.
And after that we will want to check if the players are connected. (To be safe)
Now we want to check if a player is near the gate. Using the IsPlayerInRangeOfPoint function.
See https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint for more info about this function.
And if a player is near the gate, we will want to move it.
I have choosed to move it 10 points down.
If the player is not near the gate, we should reset it.
Now it should look something like this.
Thats all for me, hope it helped.
Ok, first we need to include a_samp so all the functions will work. So we will want to put this at the top of the script.
pawn Код:
#include <a_samp>
pawn Код:
forward GateCheck();
pawn Код:
new AutomaticGate;
pawn Код:
public OnGameModeInit()
pawn Код:
SetTimer("GateCheck", 500, true);
And now we want to create the gate object and attach the something that stores the object.
I have selected to create my object at the co-ords 2641.8201, 2810.6196 and 36.3222.
pawn Код:
AutomaticGate = CreateObject(971, 2641.8201, 2810.6196, 36.3222, 0, 0, 0);
When we are done it should look something like this
pawn Код:
public OnGameModeInit()
{
SetTimer("GateCheck", 500, true);
AutomaticGate = CreateObject(971, 2641.8201, 2810.6196, 36.3222, 0, 0, 0);
return 1;
}
pawn Код:
public GateCheck()
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
pawn Код:
if(IsPlayerConnected(i))
pawn Код:
if(IsPlayerInRangeOfPoint(i, 10.0, 2641.8201, 2810.6196, 36.3222))
And if a player is near the gate, we will want to move it.
pawn Код:
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 26.3222, 5.0);
If the player is not near the gate, we should reset it.
pawn Код:
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 36.3222, 5.0);
pawn Код:
public CheckGate()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInRangeOfPoint(i, 10.0, 2641.8201, 2810.6196, 36.3222))
{
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 26.3222, 5.0);
}
else
{
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 36.3222, 5.0);
}
}
}
}
Thats all for me, hope it helped.