Key Pressed
#1

Hello can some1 tell my or give some sample script how to make example move object on key pressed like i have seen in alot of servers like if u want to start car engine u need tu press y or something
Reply
#2

search on wikipedia about this callback and learn

'public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)'
Reply
#3

tnx u helped my but now i am stuck again , i have this function :

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if (PRESSED(KEY_ANALOG_LEFT ))
	{
	
		if(IsPlayerInRangeOfPoint(playerid, 7.0,1588, -1637.9004, 15))//policija garazas
        {
            MoveDynamicObject(gate1,1580, -1637.9004, 15,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,1549.62, -1628.0699, 16))//policija ivaziavimas
        {
            MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            return 1;
        }
	
	}

	return 1;
}
this function open gate by presing num4 but i need to do like when i press num 4 is open and if i press again it will close can u tell my how to to like that ?
Reply
#4

anyone ? can help my
Reply
#5

add
pawn Код:
new Used[MAX_PLAYERS];
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if (PRESSED(KEY_ANALOG_LEFT ))
    {

        if(IsPlayerInRangeOfPoint(playerid, 7.0,1588, -1637.9004, 15))//policija garazas
        {
            if(Used[playerid] == 0)
            {
               MoveDynamicObject(gate1,1580, -1637.9004, 15,2.5);
               SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            }
            if(Used[playerid] == 1)
            {
               MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
               SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            }
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,1549.62, -1628.0699, 16))//policija ivaziavimas
        {
            MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            return 1;
        }

    }

    return 1;
}
This Should Work!!!
Reply
#6

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
add
pawn Код:
new Used[MAX_PLAYERS];
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if (PRESSED(KEY_ANALOG_LEFT ))
    {

        if(IsPlayerInRangeOfPoint(playerid, 7.0,1588, -1637.9004, 15))//policija garazas
        {
            if(Used[playerid] == 0)
            {
               MoveDynamicObject(gate1,1580, -1637.9004, 15,2.5);
               SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            }
            if(Used[playerid] == 1)
            {
               MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
               SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            }
            return 1;
        }
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,1549.62, -1628.0699, 16))//policija ivaziavimas
        {
            MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            return 1;
        }

    }

    return 1;
}
This Should Work!!!
tnx for help but u forget one thing to change value of used each time when it pressed , i did but not sure i did right and just want to ask that i do good and this code wont cause my any troubles in future

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if (PRESSED(KEY_ANALOG_LEFT ))
	{
	
		if(IsPlayerInRangeOfPoint(playerid, 7.0,1588, -1637.9004, 15))//policija garazas
        {
        
        
            if(Used[playerid] == 0)
            {
        
            MoveDynamicObject(gate1,1580, -1637.9004, 15,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            Used[playerid] = 1;
            return 1;
			}
			 if(Used[playerid] == 1)
            {
            
            MoveDynamicObject(gate1,1588, -1637.9004, 15,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys uzdarytos!");
            Used[playerid] = 0;
            return 1;
        

            }
            
            
            
        }
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,1549.62, -1628.0699, 16))//policija ivaziavimas
        {
            MoveDynamicObject(gate2,1549.62,-1637.1030,16,2.5);
            SendClientMessage(playerid, 0xFFFFFFFF, "Durys atidarytos!");
            return 1;
        }
	
	}

	return 1;
}
Reply
#7

ohh yeah sorry about that i forget it
Reply
#8

And no it wont cause problem!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)