Take look at this -
Peter_Corneile - 02.09.2009
I have made some automatic gates the codes are as follows
Код:
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;
}
Код:
new Lsgate;
new Lvgate;
forward CheckGate();
forward CheckGate2();
Код:
Lsgate = CreateObject(980, 1961.425415, -2189.519043, 15.320267, 0.0000, 0.0000, 0.0000);
Lvgate = CreateObject(980, 1706.067505, 1607.601563, 11.983828, 0.0000, 0.0000, 253.4298);
SetTimer("CheckGate", 1000, true);
SetTimer("CheckGate2", 1000, true);
Код:
public CheckGate()
{
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(PlayerToPoint(9.5, i, 1961.425415, -2189.519043, 15.320267) && OpenGate[i] == 0)
{
MoveObject(Lsgate, 1961.434082, -2189.519043, 9.050316,3);
PlayerPlaySound(1186,0,0,0,0);
OpenGate[i] = 1;
}
else if(!PlayerToPoint(5.5, i, 1961.425415, -2189.519043, 15.320267) && OpenGate[i] == 1)
{
MoveObject(Lsgate,1961.425415, -2189.519043, 15.320267,3);
PlayerPlaySound(1186,0,0,0,0);
OpenGate[i] = 0;
}
}
}
public CheckGate2()
{
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(PlayerToPoint(9.5, i, 1706.067505, 1607.601563, 11.983828) && OpenGate[i] == 0)
{
MoveObject(Lvgate, 1706.055054, 1607.618652, 5.914435,3);
PlayerPlaySound(1186,0,0,0,0);
OpenGate[i] = 1;
}
else if(!PlayerToPoint(5.5, i, 1706.067505, 1607.601563, 11.983828) && OpenGate[i] == 1)
{
MoveObject(Lvgate,1706.067505, 1607.601563, 11.983828,3);
PlayerPlaySound(1186,0,0,0,0);
OpenGate[i] = 0;
}
Both the gates open but they dont close , i tried to add return 1; as well as return 0; but doesnt help it .... Please help me solving this riddle
Re: Take look at this -
Yuryfury - 02.09.2009
you have gateopen[ i ] = 1
This way if it is closed for one person it is open for another and it is only one object, do just Lsgate = 1 or Lvgate = 1
Код:
player1 is near the gate, it opens
loops to player2 opens for them
loops to player3 opens for them
Re: Take look at this -
Peter_Corneile - 02.09.2009
So do i need to change?
Re: Take look at this -
Peter_Corneile - 03.09.2009
I changed the code to this and it worked .. Thanks
Код:
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;
}
Код:
new Lsgate;
new Lvgate;
new OpenGateLS[MAX_PLAYERS];
new OpenGateLV[MAX_PLAYERS];
forward CheckGate();
Код:
Lsgate = CreateObject(980, 1961.425415, -2189.519043, 15.320267, 0.0000, 0.0000, 0.0000);
Lvgate = CreateObject(980, 1706.067505, 1607.601563, 11.983828, 0.0000, 0.0000, 253.4298);
SetTimer("CheckGate", 1000, true);
Код:
Код:
public CheckGate()
{
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(PlayerToPoint(9.5, i, 1961.425415, -2189.519043, 15.320267) && OpenGateLS[i] == 0)
{
MoveObject(Lsgate, 1961.434082, -2189.519043, 9.050316,3);
OpenGateLS[i] = 1;
}
else if(!PlayerToPoint(5.5, i, 1961.425415, -2189.519043, 15.320267) && OpenGateLS[i] == 1)
{
MoveObject(Lsgate,1961.425415, -2189.519043, 15.320267,3);
OpenGateLS[i] = 0;
}
}
for(new i = 0; i < GetMaxPlayers(); i++)
{
if(!IsPlayerConnected(i)) continue;
if(PlayerToPoint(9.5, i, 1706.067505, 1607.601563, 11.983828) && OpenGateLV[i] == 0)
{
MoveObject(Lvgate, 1706.055054, 1607.618652, 5.914435,3);
OpenGateLV[i] = 1;
}
else if(!PlayerToPoint(5.5, i, 1706.067505, 1607.601563, 11.983828) && OpenGateLV[i] == 1)
{
MoveObject(Lvgate,1706.067505, 1607.601563, 11.983828,3);
OpenGateLV[i] = 0;
}
}