How does it work?
There are three major steps:
Iterate through the list of entities.
Determine the closest distance between the local player and an enemy.
Play a sound with a custom frequency and duration, depending on how close or far the enemy is.
Example Code
I've made a simple Sonar/Sound ESP for Assault Cube to show how it works.
The distance between the entities is calculated using d = √ [(x2 – x1)^2 + (y2 – y1)^2 + (z2 – z1)^2]
main.py
# AssaultCube 1.3.0.2
import pyMeow as pm
from math import sqrt, inf
from winsound import Beep
from time import sleep
class Config:
distance = 80
class Offsets:
LocalPlayer = 0x18AC00
EntityList = 0x18AC04
PlayerCount = 0x18AC0C
pHeadpos = 0x4
pTeam = 0x30C
pHealth = 0xEC
class Entity:
def __init__(self, proc, pawn):
self.proc = proc
self.pawn = pawn
@property
def team(self):
return pm.r_int(self.proc, self.pawn + Offsets.pTeam)
@property
def health(self):
return pm.r_int(self.proc, self.pawn + Offsets.pHealth)
@property
def headpos(self):
return pm.r_vec3(self.proc, self.pawn + Offsets.pHeadpos)
def distance(player, entity):
return sqrt((player["x"] - entity["x"])**2 + (player["y"] - entity["y"])**2 + (player["z"] - entity["z"])**2)
def main():
proc = pm.open_process("ac_client.exe")
base = pm.get_module(proc, "ac_client.exe")["base"]
print("Started Sonar ESP.")
while True:
pCount = pm.r_int(proc, base + Offsets.PlayerCount)
if pCount > 1:
entities = pm.r_ints(proc, pm.r_int(proc, base + Offsets.EntityList), pCount)
localplayer = Entity(proc, pm.r_int(proc, base + Offsets.LocalPlayer))
lowestDist = inf
for entityAddr in entities[1:]: # Loop through the entity list
try:
entity = Entity(proc, entityAddr)
if localplayer.team != entity.team and entity.health > 0:
# Calculate the distance
dist = distance(localplayer.headpos, entity.headpos)
if dist < lowestDist:
lowestDist = dist
except:
continue
if lowestDist < Config.distance: # -> Play the sound
pitch = max(1500, 3200 - 10 * lowestDist)
duration = max(120, 10 * lowestDist)
Beep(int(pitch), int(duration))
sleep(duration/1500)
else:
sleep(.5)
if __name__ == "__main__":
main()
Preview
Others
I've made a Sound ESP for Counter-Strike 2 too. You can check it out here.