public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(job[playerid] == POLICE) { if(IsPlayerInRangeOfPoint(playerid, 3.0, -1641.1395,686.5178,7.1875)) { if((newkeys & 8 && !IsPlayerInAnyVehicle(playerid)) || (newkeys & KEY_HANDBRAKE && IsPlayerInAnyVehicle(playerid))) { if(DOORMODE == false) { MoveDynamicObject(POLICIJOSDOORS[0], -1641.55225, 688.7032, 6.18130, 3.0); SendClientMessage(playerid, green, "Door is opening"); DOORMODE = true; } else if( DOORMODE == true ) { MoveDynamicObject(POLICEDOORS[0], -1641.55225, 687.22321, 6.18130, 3.0); SendClientMessage(playerid, red, "Doors are closing"); DOORMODE = false; } else if(IsPlayerInRangeOfPoint(playerid, 10.0, -1641.1897,679.5863,7.1875)) { if(DOORMODE2 == false) { MoveDynamicObject(POLICEGATES[0], -1641.60791, 679.52722, 11.5965, 3.0); SendClientMessage(playerid, green, "Gate is opening"); DOORMODE2 = true; } else if(DOORMODE2 == true) { MoveDynamicObject(POLICEGATES[0], -1641.60791, 679.52722, 7.67200, 3.0); SendClientMessage(playerid, red, "Gate is closing"); DOORMODE2 = false; } } } } } return 1; }
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
if(job[playerid] == POLICE)
{
if((newkeys & 8 && !IsPlayerInAnyVehicle(playerid)) || (newkeys & KEY_HANDBRAKE && IsPlayerInAnyVehicle(playerid)))
{
if(IsPlayerInRangeOfPoint(playerid,3.0,-1641.1395,686.5178,7.1875))
{
if(DOORMODE == false)
{
MoveDynamicObject(POLICIJOSDOORS[0],-1641.55225, 688.7032, 6.18130, 3.0);
SendClientMessage(playerid,green,"Door is opening");
DOORMODE = true;
}
else if(DOORMODE == true)
{
MoveDynamicObject(POLICEDOORS[0], -1641.55225, 687.22321, 6.18130, 3.0);
SendClientMessage(playerid, red, "Doors are closing");
DOORMODE = false;
}
}
else if(IsPlayerInRangeOfPoint(playerid,10.0, -1641.1897,679.5863,7.1875))
{
if(DOORMODE2 == false)
{
MoveDynamicObject(POLICEGATES[0], -1641.60791, 679.52722, 11.5965, 3.0);
SendClientMessage(playerid, green, "Gate is opening");
DOORMODE2 = true;
}
else if(DOORMODE2 == true)
{
MoveDynamicObject(POLICEGATES[0], -1641.60791, 679.52722, 7.67200, 3.0);
SendClientMessage(playerid, red, "Gate is closing");
DOORMODE2 = false;
}
}
}
}
return 1;
}
Hello!
You must press the key one times. After that you must press it again to close the gate. Don't hold the key. |
// PRESSED(keys) #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) // HOLDING(keys) #define HOLDING(%0) \ ((newkeys & (%0)) == (%0))
Have a global variable and set it to true before moving the object.
In OnObjectMoved callback, check if the object was the gate and set it to false. In OnPlayerKeyStateChange, check if the variable is set to false (not moving) and only then open/close the /gate (move the object basically) again. |
if (!IsDynamicObjectMoving(POLICEGATE[0]))
{
if (!DOORMODE) // DOORMODE is false
{
...
}
else // DOORMODE is true
{
...
}
}
I forgot about that streamer function Vince mentioned so no need of variables to check if the objects are moving.
pawn Код:
|
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(job[playerid] == POLICE)
{
if((newkeys & 8 && !IsPlayerInAnyVehicle(playerid)) || (newkeys & KEY_HANDBRAKE && IsPlayerInAnyVehicle(playerid)))
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, -1641.1395,686.5178,7.1875))
{
if (!IsDynamicObjectMoving(POLICEGATE[0]))
{
if (!GATEMODE) // DOORMODE is false
{
MoveDynamicObject(POLICEGATE[0], -1641.55225, 688.7032, 6.18130, 3.0);
SendClientMessage(playerid, zalia, "Gate is opening");
VARTUMODE = true;
}
else // DOORMODE is true
{
MoveDynamicObject(POLICEGATE[0], -1641.55225, 687.22321, 6.18130, 3.0);
SendClientMessage(playerid, raudona, "Gate is closing");
GATEMODE = false;
}
}
else if(IsPlayerInRangeOfPoint(playerid, 4.0, -1641.1897,679.5863,7.1875))
{
if (!IsDynamicObjectMoving(POLICEGATE[1]))
{
if(!VARTUMODE2) // DOORMODE is false
{
MoveDynamicObject(POLICEGATE[1], -1641.60791, 679.52722, 11.5965, 3.0);
SendClientMessage(playerid, zalia, "Gate is opening");
GATEMODE2 = true;
}
else // DOORMODE is true
{
MoveDynamicObject(POLICEGATE[1], -1641.60791, 679.52722, 7.67200, 3.0);
SendClientMessage(playerid, raudona, "Gate is closing");
GATEMODE2 = false;
}
}
}
}
}
}
return 1;
}