0% found this document useful (0 votes)
39 views

DisableMapHack Lua

The document describes code for a Grand Theft Auto: San Andreas multiplayer mod that displays nametags and health bars above other players' characters. It defines functions to get a character's bone positions, check distances between players, and render the nametags and bars on screen.

Uploaded by

ytbiel65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

DisableMapHack Lua

The document describes code for a Grand Theft Auto: San Andreas multiplayer mod that displays nametags and health bars above other players' characters. It defines functions to get a character's bone positions, check distances between players, and render the nametags and bars on screen.

Uploaded by

ytbiel65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

local ev = require 'samp.

events'
local ffi = require 'ffi'
local gta = ffi.load('GTASA')

local font = renderCreateFont("Arial", 16, 0x4)


local maxDistance = 0

ffi.cdef[[
typedef struct RwV3d {
float x, y, z;
} RwV3d;

void _ZN4CPed15GetBonePositionER5RwV3djb(void* thiz, RwV3d* posn, uint32_t


bone, bool calledFromCam);
]]

function getBonePosition(ped, bone)


local pedptr = ffi.cast('void*', getCharPointer(ped))
local posn = ffi.new('RwV3d[1]')
gta._ZN4CPed15GetBonePositionER5RwV3djb(pedptr, posn, bone, false)
return posn[0].x, posn[0].y, posn[0].z
end

function ev.onInitGame(playerId, hostName, settings, vehicleModels, unknown)


settings.showPlayerTags = false
settings.playerMarkersMode = 0
maxDistance = settings.nametagDrawDist
return { playerId, hostName, settings, vehicleModels }
end

function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end

while true do
wait(0)

for _, char in ipairs(getAllChars()) do


if char ~= playerPed then
local result, id = sampGetPlayerIdByCharHandle(char)
if result and isCharOnScreen(char) and not sampIsPlayerNpc(id) then
local selfX, selfY, selfZ = getCharCoordinates(playerPed)
local charX, charY, charZ = getCharCoordinates(char)
local distance = getDistanceBetweenCoords3d(selfX, selfY,
selfZ, charX, charY, charZ)
if distance <= maxDistance then
local opaque_color =
bit.bor(bit.band(sampGetPlayerColor(id), 0xFFFFFF), 0xFF000000)
local hdx, hdy, hdz = getBonePosition(char, 5)
local hddr, hddx, hddy = convert3DCoordsToScreenEx(hdx,
hdy, hdz + 0.25)
if hddr and isLineOfSightClear(selfX, selfY, selfZ, charX,
charY, charZ, true, false, false, true, false) then
local nametag = sampGetPlayerNickname(id) .. " (" .. id
.. ")"
renderHealthBar(char, hddx, hddy + 20)
local nametag_len = renderGetFontDrawTextLength(font,
nametag)
local nametag_x = hddx - nametag_len / 2
local nametag_y = hddy - renderGetFontDrawHeight(font)
renderFontDrawText(font, nametag, nametag_x, nametag_y,
opaque_color)
end
end
end
end
end
end
end

function renderHealthBar(char, x, y)
local result, id = sampGetPlayerIdByCharHandle(char)
if result then
local healthPercentage = sampGetPlayerHealth(id) / 100
local armorPercentage = sampGetPlayerArmor(id) / 100
if armorPercentage > 0 then
renderDrawBox(x - 43, y - 13, 86, 12, 0xFF000000)
renderDrawBox(x - 40, y - 10, 80 * armorPercentage, 8, 0xFFC6C5C7)
end
renderDrawBox(x - 43, y, 86, 12, 0xFF000000)
renderDrawBox(x - 40, y + 3, 80 * healthPercentage, 8, 0xFFFF0000)
end
end

You might also like