Player face player
#1

hey.. i'm trying to make a /handshake command and when the player is using the command its change the players their face to each other...

pawn Код:
stock SetPlayerFacePlayer(playerid, giveplayer)
{
    new Float:Px, Float:Py, Float: Pa;
    GetPlayerPos(playerid, Px, Py, Pa);
    new Float:fpX, Float:fpY, Float: fpZ;
    GetPlayerPos(giveplayer, fpX, fpY, fpZ);
    Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
    if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
    else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
    else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
    else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}


    if(strcmp(cmd, "/handshake", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(Offer[playerid] > -1)
            {
                giveplayerid = Offer[playerid];
                if (ProxDetectorS(1.5, playerid, giveplayerid))
                {
                    SetPlayerFacePlayer(playerid, giveplayer)
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    ApplyAnimation(playerid,"GANGS","hndshkfa",4.1,0,0,0,0,0);
                    ApplyAnimation(giveplayerid,"GANGS","hndshkfa",4.1,0,0,0,0,0);
                    PlayerInfo[playerid][pMember] = 11;
                    PlayerInfo[playerid][pRank] = 1;
                    format(string, sizeof(string), "You have joined Le Sangre Gang by %d",  giveplayer);
                    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                    format(string, sizeof(string), "You have Invited %d to join the Le Sangre.", sendername);
                    SendClientMessage(giveplayerid, COLOR_LIGHTBLUE, string);
                    SendClientMessage(playerid, COLOR_GRAD2, "{33CCFF}Welcome to Le Sangre Gang:{009999} go to /changeclothes for finishing your recruiting");
                    Offer[playerid] = -1;
                    Offer[giveplayerid] = -1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   That player is not near you !");
                    return 1;
                }
            }
        }
    }
Reply
#2

to obtain the angle, the atan2 function is a good way:
Код:
new Angle=atan2(DiffX,DiffY);//or
new Angle=atan2(X1-X2,Y1-Y2);//or
new Angle=atan2(X2-X1,Y2-Y1);//in case your angles are rotated by 180 degrees, try this one instead of adding 180.0 later...
...for the last line: you might swap player ids aswell, if 2 players are facing each other, then their angles are related to each other (180° offset, to be precise):
iam in angel pine (south west), youre in Dillimore (north east) - so i will face north east (45.0°), so you will face south west (225°), and 45°+180°=225° - calculate playerA's angle, playerB's angle=playerA's angle+180.0

edit: you forgot the semicolon after
Код:
SetPlayerFacePlayer(playerid, giveplayer)
i assume thats supposed to be a
Код:
stock SetPlayerFacePlayer(playerid, giveplayer){
	new Float:PlayerX[2],Float:PlayerY[2],Float:PlayerZ[2];
	GetPlayerPos(playerid,PlayerX[0],PlayerY[0],PlayerZ[0]);
	GetPlayerPos(giveplayer,PlayerX[1],PlayerY[1],PlayerZ[1]);
	new Angle=atan2(PlayerX[0]-PlayerX[1],PlayerY[0]-PlayerY[1]);
	return Angle;
}
now i dont know which player gets set the returned angle, and which one needs to get added 180 lol
Reply
#3

Well it giving me error:

warning 213: tag mismatch

on this line:
new Angle=atan2(PlayerX[0]-PlayerX[1],PlayerY[0]-PlayerY[1]);
Reply
#4

You should / could knew who gets the extra 180° if you wrote the calculation...

Full and working function
pawn Код:
stock SetPlayerFacePlayer(playerid, giveplayerid) {
    new
        Float: pX,
        Float: pY,
        Float: pZ,
        Float: gX,
        Float: gY,
        Float: gZ
    ;
    if(GetPlayerPos(playerid, pX, pY, pZ) && GetPlayerPos(giveplayerid, gX, gY, gZ)) {
        SetPlayerFacingAngle(playerid, (pX = -atan2((gX - pX), (gY - pY))));
        return SetPlayerFacingAngle(giveplayerid, (pX + 180.0));
    }
    return false;
}
Also using arrays is slower than normal variables, just use them if you need them
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)