10.08.2011, 17:05
(
Last edited by Darnell; 12/08/2011 at 01:20 PM.
)
Automatic gates
Simple as the name.
First, let's store the object.Simple as the name.
pawn Code:
new AutoGate;
pawn Code:
AutoGate = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance)
Now let's set a timer , anywhere in OnPlayerConnect.
pawn Code:
SetTimerEx( "AGCheck", 750, true, "i", playerid );
pawn Code:
public OnPlayerConnect(playerid)
{
SetTimerEx( "AGCheck", 750, true, "i", playerid );
return 1;
}
Now, let's register the callback of the timer.
pawn Code:
forward AGCheck(playerid);
pawn Code:
public AGCheck( playerid );
{
if ( IsPlayerInRangeOfPoint( playerid, Float: range, Float: x, Float: y, Float: z ) )
{
MoveObject( AutoGate, Float: x, Float: y, Float: z, Float: speed );
}
else
{
MoveObject( AutoGate, Float: originalX, Float: originalY, Float: originalZ, Float: speed );
}
return 1;
}
Go to My Documents\GTA User files\SAMP and open ' savedpositions '.
You'll see addplayerclass(..) etc.
All you need is the XYZ, nothing less.
Example :
Quote:
AddPlayerClass(2,2029.8596,1351.5167,10.8203,90.4238,0,0,0,0,0,0); // playerrange |
When we got those positions, now we can set the range using the IsPlayerInRangeOfPoint function.
pawn Code:
if(IsPlayerInRangeOfPoint(i, Float:range, Float:x, Float:y, Float:z)
Now, if there's a player near it, so we need to make the gate automatic, using MoveObject.
pawn Code:
MoveObject(autogate,Float:X, Float:Y, Float:Z, Float:Speed)
Example :
pawn Code:
MoveObject(autogate,2088.9011,1433.1863,10.8203,1.0)
In the end, we'll get something like this
pawn Code:
forward AGCheck( playerid );
public AGCheck( playerid )
{
if ( IsPlayerInRangeOfPoint(playerid, 8.0, Float: x, Float: y, Float: z ) ) // when a player is near at some point;
{
MoveObject( AutoGate, Float: x, Float: y, Float: z, Float: speed ); // moves the object;
}
else
{
MoveObject( AutoGate, Float: originalX, Float: originalY, Float: originalZ, Float: speed ); // moves the object;
}
return 1;
}
* If you didn't understand any function / callback etc, check www.wiki.sa-mp.com
This is my first tutorial, so yeah, be nice.