GetPlayerDistanceFromPoint
#1

pawn Код:
new Float:lspddistance=GetPlayerDistanceFromPoint(playerid,1554.9974,-1675.5564,16.4953);
            new Float:sfpddistance=GetPlayerDistanceFromPoint(playerid,-1605.5566,710.4965,13.8672);
            new Float:lvpddistance=GetPlayerDistanceFromPoint(playerid,288.6926,167.3528,1007.4719);
            SetPlayerVirtualWorld(playerid,1);
            if(lspddistance>sfpddistance && lspddistance>lvpddistance)
            {
                SetPlayerInterior(playerid,6);
                SetPlayerPos(playerid,264.7468,77.4799,1001.0391);
            }
            if(sfpddistance>lspddistance && sfpddistance>lvpddistance)
            {
                SetPlayerInterior(playerid,10);
                SetPlayerPos(playerid,227.5555,111.0000,999.0156);
            }
            if(lvpddistance>lspddistance && lvpddistance>sfpddistance)
            {
                SetPlayerInterior(playerid,3);
                SetPlayerPos(playerid,193.4588,175.0000,1003.0234);
            }
This is the part of the command that jails the player. But, the problem is - it always puts the player in SF jail.
Someone please tell me how to fix it. I checked all the co-ordinates and they are correct.
Reply
#2

Logic problems try it like this it also allows you to add as many police stations as you like.

pawn Код:
// 0 = lspd, 1 = sfpd, 2 = lvpd

#define         MAX_POLICE_STATIONS     3

new Float:PDDist[MAX_POLICE_STATIONS], ClosestStation;

// Get distances
PDDist[0]=GetPlayerDistanceFromPoint(playerid,1554.9974,-1675.5564,16.4953);
PDDist[1]=GetPlayerDistanceFromPoint(playerid,-1605.5566,710.4965,13.8672);
PDDist[2]=GetPlayerDistanceFromPoint(playerid,288.6926,167.3528,1007.4719);

// Find closest distance
for(new i = 1; i < MAX_POLICE_STATIONS; i++) if(PDDist[i] < PDDist[ClosestStation]) ClosestStation = i;

// Teleport player
SetPlayerVirtualWorld(playerid,1);
switch(ClosestStation)
{
    case 0:
    {
        SetPlayerInterior(playerid,6);
        SetPlayerPos(playerid,264.7468,77.4799,1001.0391);
    }
    case 1:
    {
        SetPlayerInterior(playerid,10);
        SetPlayerPos(playerid,227.5555,111.0000,999.0156);
    }
    case 2:
    {
        SetPlayerInterior(playerid,3);
        SetPlayerPos(playerid,193.4588,175.0000,1003.0234);
    }
}
Reply
#3

Thanks, bro. It worked.
rep++;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)