Skip to content

Fix surfing invisible

Nexius edited this page Oct 14, 2024 · 11 revisions

Variant 1: ignoring bad packet

const PLAYER_SYNC = 207;

IPacket:PLAYER_SYNC(playerid, BitStream:bs)
{
    new onFootData[PR_OnFootSync];

    BS_IgnoreBits(bs, 8); // ignore packetid (byte)
    BS_ReadOnFootSync(bs, onFootData);

    if (onFootData[PR_surfingVehicleId] != 0
        && onFootData[PR_surfingVehicleId] != INVALID_VEHICLE_ID
    ) {
        if (floatabs(onFootData[PR_surfingOffsets][0]) >= 50.0
            || floatabs(onFootData[PR_surfingOffsets][1]) >= 50.0
            || floatabs(onFootData[PR_surfingOffsets][2]) >= 50.0
        ) {
            return 0; // ignore bad packet
        } 
    }

    return 1;
}

Variant 2: rewrite and continue packet processing

const PLAYER_SYNC = 207;

IPacket:PLAYER_SYNC(playerid, BitStream:bs)
{
    new onFootData[PR_OnFootSync];

    BS_IgnoreBits(bs, 8); // ignore packetid (byte)
    BS_ReadOnFootSync(bs, onFootData);

    if (onFootData[PR_surfingVehicleId] != 0
        && onFootData[PR_surfingVehicleId] != INVALID_VEHICLE_ID
    ) {
        if (floatabs(onFootData[PR_surfingOffsets][0]) >= 50.0
            || floatabs(onFootData[PR_surfingOffsets][1]) >= 50.0
            || floatabs(onFootData[PR_surfingOffsets][2]) >= 50.0
        ) {
            onFootData[PR_surfingOffsets][0] =
            onFootData[PR_surfingOffsets][1] =
            onFootData[PR_surfingOffsets][2] = 0.0;

            BS_SetWriteOffset(bs, 8);
            BS_WriteOnFootSync(bs, onFootData); // rewrite
        } 
    }

    return 1;
}