Can't press enter to enter in a building
#1

I try to make a system where when you press the "enter" key in a certain area you will be teleported inside. I made the code, but something is not right, because when I press enter at that location, nothing happens.
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(IsPlayerInRangeOfPoint(playerid, 10, 1219.9609,-1811.9579,16.5938))
	{
		if(newkeys == KEY_SECONDARY_ATTACK)
		{
    		if(GetPlayerInterior(playerid)==0 && GetPlayerVirtualWorld(playerid)==0)
    		{
         		SetPlayerInterior(playerid,3);
         		SetPlayerPos(playerid, 1494.325195,1304.942871,1093.289062);
    		}
		}
	}
	return 1;
}
Reply
#2

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.5, 1219.9609,-1811.9579, 16.5938))
        {
                if(GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid)== 0)
                {
                    SetPlayerInterior(playerid, 3);
                    SetPlayerPos(playerid, 1494.325195,1304.942871,1093.289062);
                }
        }
    }
    return 1;
}
if this doesn't work, check the coordinates are right.
Reply
#3

Thanks,that worked!
Reply
#4

For future reference, keep in mind using "&" instead of "==" is ideal for key state. This is because & functions as a bit-wise "and", meaning it'll check for that key being pressed instead of checking for that key being the only one pressed (since, despite it's name, newkeys is misleadingly composed by all the keys being pressed at once, not just the new key)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)