Bind key to player.
#1

Hello,
I have a couple of keys defined to move an object, the problem is that every player can press the keys and the object moves. I want there to be a command with binds a player to the object so only he can move it with the keys.
Thanks in advance.
Reply
#2

Well, you can make the object to be moved only if player who's pressing the key = your desired player.

Give us some example of your code to understand it better.
Reply
#3

Okay heres the code,

First, the keys defined under OnPlayerUpdate:
Код:
public OnPlayerUpdate(playerid)
{

    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);
    
	if(MakeBoatControllable==1)
	{
	    if(ud > 0)
	    {
	    	new Float:x1, Float:y1, Float:z1;
			GetObjectPos(PirateShip, x1, y1, z1);
			
			new Float:x2, Float:y2, Float:z2;
			GetObjectPos(PirateShip, x2, y2, z2);

	        MoveObject(PirateShip, x1+ShipMovingValue, y1, z1, ShipSpeed);
	        MoveObject(PirateShippart, x2+ShipMovingValue, y2, z2, ShipSpeed);
	    }
	    else if(ud < 0)
	    {
	    	new Float:x1, Float:y1, Float:z1;
			GetObjectPos(PirateShip, x1, y1, z1);

			new Float:x2, Float:y2, Float:z2;
			GetObjectPos(PirateShip, x2, y2, z2);

	        MoveObject(PirateShip, x1-ShipMovingValue, y1, z1, ShipSpeed);
	        MoveObject(PirateShippart, x2-ShipMovingValue, y2, z2, ShipSpeed);
	    }

	    else if(lr > 0)
	    {
	    	new Float:x1, Float:y1, Float:z1;
			GetObjectPos(PirateShip, x1, y1, z1);

			new Float:x2, Float:y2, Float:z2;
			GetObjectPos(PirateShip, x2, y2, z2);

	        MoveObject(PirateShip, x1, y1+ShipMovingValue, z1, ShipSpeed);
	        MoveObject(PirateShippart, x2, y2+ShipMovingValue, z2, ShipSpeed);
	    }

	    else if(lr < 0)
	    {
	    	new Float:x1, Float:y1, Float:z1;
			GetObjectPos(PirateShip, x1, y1, z1);

			new Float:x2, Float:y2, Float:z2;
			GetObjectPos(PirateShip, x2, y2, z2);

	        MoveObject(PirateShip, x1, y1-ShipMovingValue, z1, ShipSpeed);
	        MoveObject(PirateShippart, x2, y2-ShipMovingValue, z2, ShipSpeed);
	    }
    }
}
And Second, the keys defined under OnPlayerKeyStateChange:
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(MakeBoatControllable==1)
	{
    	if (newkeys & KEY_CROUCH)
    	{
    		new Float:RotX,Float:RotY,Float:RotZ;
			GetObjectRot(PirateShip, RotX, RotY, RotZ);
			
			new Float:RotX2,Float:RotY2,Float:RotZ2;
			GetObjectRot(PirateShip, RotX2, RotY2, RotZ2);			

			SetObjectRot(PirateShip, RotX, RotY, RotZ+3);
			SetObjectRot(PirateShippart, RotX2, RotY2, RotZ2+3);
    	}
    	if (newkeys & KEY_JUMP)
    	{
    		new Float:RotX,Float:RotY,Float:RotZ;
			GetObjectRot(PirateShip, RotX, RotY, RotZ);

			new Float:RotX2,Float:RotY2,Float:RotZ2;
			GetObjectRot(PirateShip, RotX2, RotY2, RotZ2);

			SetObjectRot(PirateShip, RotX, RotY, RotZ-3);
			SetObjectRot(PirateShippart, RotX2, RotY2, RotZ2-3);
    	}
 	}
}
Reply
#4

Okay, and who should move this ? Admins? Some player id ? Your name only ?
Reply
#5

there sould be a command to assign a player to the object, so that only he can move it.
Reply
#6

So, I don't understand you.


You want to change those keys for a command? Like /moveup. And that command it's hidden and only you know it?

or You want something like this.

If a player uses /controlboat, he will be able to move the boat with the keys .
Reply
#7

Quote:

If a player uses /controlboat, he will be able to move the boat with the keys .

that's just what I want
Reply
#8

Okay, so it should be something like this...

The command, under OnPlayerCommandText
pawn Код:
if(strcmp(cmd, "/controlboat", true) == 0)
{
     new IsABoatDriver[MAX_PLAYERS];
     IsABoatDriver[playerid] = 1;
     return 1;
}
Then on your code..

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsABoatDriver[playerid] && MakeBoatControllable==1)
    {
        if (newkeys & KEY_CROUCH)
        {
            new Float:RotX,Float:RotY,Float:RotZ;
            GetObjectRot(PirateShip, RotX, RotY, RotZ);

            new Float:RotX2,Float:RotY2,Float:RotZ2;
            GetObjectRot(PirateShip, RotX2, RotY2, RotZ2);

            SetObjectRot(PirateShip, RotX, RotY, RotZ+3);
            SetObjectRot(PirateShippart, RotX2, RotY2, RotZ2+3);
        }
        if (newkeys & KEY_JUMP)
        {
            new Float:RotX,Float:RotY,Float:RotZ;
            GetObjectRot(PirateShip, RotX, RotY, RotZ);

            new Float:RotX2,Float:RotY2,Float:RotZ2;
            GetObjectRot(PirateShip, RotX2, RotY2, RotZ2);

            SetObjectRot(PirateShip, RotX, RotY, RotZ-3);
            SetObjectRot(PirateShippart, RotX2, RotY2, RotZ2-3);
        }
    }
}
Try this, I didn't tested it, so I'll wait for your reply.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)