Respawn at nearest Hospital script not working correctly
#6

The code seems fine only, it would only break if you are over 1000 units away

You could at least try to print both distances and check for yourself why your code did what it did

That would be a version which uses an additional function
Basically put everything into an function if you want to reuse it more than once
pawn Код:
stock SpawnToHospital(playerid) {
    static const Float: hspawns[][] = {
        {2034.1670,-1406.0623,17.2181,150.4297},
        {1177.3391,-1324.2300,14.0658,268.3749}
    };
    new
        closest = GetClosestFromPlayer(playerid, hspawns)
    ;
    if(closest != -1) {
        dead[playerid] = false;
        SetPlayerPos(playerid, hspawns[closest][0], hspawns[closest][1], hspawns[closest][2]);
        SetPlayerFacingAngle(playerid, hspawns[closest][3]);
        return SetCameraBehindPlayer(playerid);
    }
    return false;
}
pawn Код:
GetClosestFromPlayer(playerid, const {_, Float}: data[][], Float: distance = 0.0, size = sizeof data) {
    if((distance = GetPlayerDistanceFromPoint(playerid, data[0][0], data[0][1], data[0][2]))) {
        new
            closest,
            Float: tmp
        ;
        while(--size) {
            tmp = GetPlayerDistanceFromPoint(playerid, data[size][0], data[size][1], data[size][2]);

            if(tmp < distance) {
                distance = tmp;
                closest = size;
            }
        }
        return closest;
    }
    return -1;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)