SA-MP Forums Archive
[HELP] looking at a vehicle! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] looking at a vehicle! (/showthread.php?tid=151467)



[HELP] looking at a vehicle! - raever - 30.05.2010

I wanted to do that if a player is looking at a vehicle and press "ENTER" to enter the vehicle (not if it is close, but if you are watching the vehicle.). Is this possible? Thanks in advance.

Translated with ****** Translate.



Re: [HELP] looking at a vehicle! - raever - 30.05.2010

Up з_з


Re: [HELP] looking at a vehicle! - coole210 - 30.05.2010

Worst translation i have ever seen in my life.


Re: [HELP] looking at a vehicle! - [XST]O_x - 30.05.2010

Quote:
Originally Posted by Coole[AG
]
Worst translation i have ever seen in my life.
Why?
Even though It's not the clearer,you can still understand what he asks for.
He asks for a system that will allow you getting into a vehicle from any distance,only by aiming at it and pressing enter.


Re: [HELP] looking at a vehicle! - coole210 - 30.05.2010

Like..

Код:
public GetClosestPlayer(p1)
{
	new
		x,
		Float:dis,
		Float:dis2,
		player;

	player = -1;
	dis = 99999.99;

	for (x=0;x<MAX_PLAYERS;x++)
		if(IsPlayerConnected(x))
			if(x != p1)
			{
				dis2 = GetDistanceBetweenPlayers(x,p1);
				if(dis2 < dis && dis2 != -1.00)
				{
					dis = dis2;
					player = x;
				}
			}

	return player;
}
for cars?


Re: [HELP] looking at a vehicle! - DJDhan - 30.05.2010

You could have used GetPlayerFacingAngle but then it would not detect if a car is in the view. So only thing possible afaik is to use IsPlayerInRangeOfPoint.


Re: [HELP] looking at a vehicle! - [XST]O_x - 30.05.2010

Quote:
Originally Posted by DJDhan
You could have used GetPlayerFacingAngle but then it would not detect if a car is in the view. So only thing possible afaik is to use IsPlayerInRangeOfPoint.
I think you should also use GetPlayerCameraFrontVector.


Re: [HELP] looking at a vehicle! - MadeMan - 30.05.2010

pawn Код:
stock Float:DistanceCameraTargetToLocation(playerid, Float:ObjX, Float:ObjY, Float:ObjZ)
{
    new Float:CamX, Float:CamY, Float:CamZ;
    GetPlayerCameraPos(playerid, CamX, CamY, CamZ);

    new Float:TGTDistance;
    TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));

    new Float:FrX, Float:FrY, Float:FrZ;
    GetPlayerCameraFrontVector(playerid, FrX, FrY, FrZ);

    new Float:tmpX, Float:tmpY, Float:tmpZ;
    tmpX = FrX * TGTDistance + CamX;
    tmpY = FrY * TGTDistance + CamY;
    tmpZ = FrZ * TGTDistance + CamZ;

    return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        if(newkeys & KEY_SECONDARY_ATTACK)
        {
            new Float:pos[3];
            for(new v=1; v < MAX_VEHICLES; v++)
            {
                if(GetVehiclePos(v, pos[0], pos[1], pos[2]))
                {
                    if(DistanceCameraTargetToLocation(playerid, pos[0], pos[1], pos[2]) < 5.0)
                    {
                        PutPlayerInVehicle(playerid, v, 0);
                        return 1;
                    }
                }
            }
        }
    }
    return 1;
}



Re: [HELP] looking at a vehicle! - [XST]O_x - 30.05.2010

Quote:
Originally Posted by MadeMan
pawn Код:
stock Float:DistanceCameraTargetToLocation(playerid, Float:ObjX, Float:ObjY, Float:ObjZ)
{
    new Float:CamX, Float:CamY, Float:CamZ;
    GetPlayerCameraPos(playerid, CamX, CamY, CamZ);

    new Float:TGTDistance;
    TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));

    new Float:FrX, Float:FrY, Float:FrZ;
    GetPlayerCameraFrontVector(playerid, FrX, FrY, FrZ);

    new Float:tmpX, Float:tmpY, Float:tmpZ;
    tmpX = FrX * TGTDistance + CamX;
    tmpY = FrY * TGTDistance + CamY;
    tmpZ = FrZ * TGTDistance + CamZ;

    return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        if(newkeys & KEY_SECONDARY_ATTACK)
        {
            new Float:pos[3];
            for(new v=1; v < MAX_VEHICLES; v++)
            {
                if(GetVehiclePos(v, pos[0], pos[1], pos[2]))
                {
                    if(DistanceCameraTargetToLocation(playerid, pos[0], pos[1], pos[2]) < 5.0)
                    {
                        PutPlayerInVehicle(playerid, v, 0);
                        return 1;
                    }
                }
            }
        }
    }
    return 1;
}
Erm..that's what i was going to say