Gate newkeys problem and other
#1

Good day SA-MP community,

So i'm making couple of gates (1 door & 1 gate to be exact) to my job, and i have 2 problems

• When i'm not in a vehicle and hold space it spams my chat door is opening and door is closing, and the gate aswell spams opens/closes quickly, but when i'm in the vehicle if i hold space there is no chat spam and doors are not spam opening/ closing, like if i press space and hold it will open, if i press again, it will close everything is normal exept when i'm on foot.

• So the second doors(gate) i've made even when i'm on foot or in a vehicle the second door isn't opening or closing, and i don't get any SendClientMessage, ofcourse i'm in a range of that coordinates i placed.

Here's my code:

Код:
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;
}
Foto when on foot it spams the chat:
http://imgur.com/a/9jSWM

So if anyone knows what i'm doing wrong, please let me know,
Thank you!
Reply
#2

Changed from text from Lithuanian to English, for better understanding.
Reply
#3

Hello!

Try this:
PHP код:
public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
    if(
job[playerid] == POLICE)
    {
        if((
newkeys && !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.55225688.70326.181303.0);
                    
SendClientMessage(playerid,green,"Door is opening");
                    
DOORMODE true;
                }
                else if(
DOORMODE == true)
                {
                    
MoveDynamicObject(POLICEDOORS[0], -1641.55225687.223216.181303.0);
                    
SendClientMessage(playeridred"Doors are closing");
                    
DOORMODE false;
                }
            }
            else if(
IsPlayerInRangeOfPoint(playerid,10.0, -1641.1897,679.5863,7.1875))
            {
                if(
DOORMODE2 == false)
                {
                    
MoveDynamicObject(POLICEGATES[0], -1641.60791679.5272211.59653.0);
                    
SendClientMessage(playeridgreen"Gate is opening");
                    
DOORMODE2 true;
                }
                else if(
DOORMODE2 == true)
                {
                    
MoveDynamicObject(POLICEGATES[0], -1641.60791679.527227.672003.0);
                    
SendClientMessage(playeridred"Gate is closing");
                    
DOORMODE2 false;
                }
            }
        }
    }
    return 
1;

You must press the key one times. After that you must press it again to close the gate. Don't hold the key.
Reply
#4

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

You must press the key one times. After that you must press it again to close the gate. Don't hold the key.
Hi,

So the second problem has been fixed now i'm able to open/ close both doors,
however even though i press once space button, i still get like 10 messages that gates opens and closes you can see timestamp

Btw, i'm using these #defines, tried removing them, same thing happens

Код:
// PRESSED(keys)
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

	// HOLDING(keys)
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
Reply
#5

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.
Reply
#6

Or simply use IsDynamicObjectMoving instead.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
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.
I have this,

new bool:DOORMODE = false; //
new bool:DOORMODE2 = false; //

new POLICEGATE[2];

Do you have example, so i can understand better? :)
Reply
#8

I forgot about that streamer function Vince mentioned so no need of variables to check if the objects are moving.

pawn Код:
if (!IsDynamicObjectMoving(POLICEGATE[0]))
{
    if (!DOORMODE) // DOORMODE is false
    {
        ...
    }
    else // DOORMODE is true
    {
        ...
    }
}
By the way you move POLICEGATE[0] in all four cases, the last two wouldn't be the other object stored in POLICEGATE[1]?
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I forgot about that streamer function Vince mentioned so no need of variables to check if the objects are moving.

pawn Код:
if (!IsDynamicObjectMoving(POLICEGATE[0]))
{
    if (!DOORMODE) // DOORMODE is false
    {
        ...
    }
    else // DOORMODE is true
    {
        ...
    }
}
By the way you move POLICEGATE[0] in all four cases, the last two wouldn't be the other object stored in POLICEGATE[1]?
Okay, door is not spamming anymore, works like it should work, thanks to you! But,
second doors are not opening anymore i get no text that it opens and closes and they're not moving anymore.

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;
}
Reply
#10

Still can't figure out why the second gate isn't working no SendClientMessage and they don't open/ close.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)