Skip to content

Instantly share code, notes, and snippets.

@VIRUXE
Created January 16, 2023 09:22
Show Gist options
  • Save VIRUXE/082583fe9e043c57d2cb36f1c778dc21 to your computer and use it in GitHub Desktop.
Save VIRUXE/082583fe9e043c57d2cb36f1c778dc21 to your computer and use it in GitHub Desktop.
Query a SA-MP (San Andreas Multiplayer) server to get info on who joins and leaves
import sys
import time
from samp_client.client import SampClient # pip install samp-client
server = sys.argv[1].split(':')
players = []
with SampClient(server[0], int(server[1])) as client:
max_players = client.get_server_info().max_players
players = [player.name for player in client.get_server_clients()]
while len(players) == 0:
print("Lista de jogadores vazia, tentando novamente em 1 segundo...")
time.sleep(1)
players = [player.name for player in client.get_server_clients()]
print(f"{'-' * 60}")
print(f"{len(players)} Jogadores: {', '.join(players)}")
print(f"{'-' * 60}")
while True: # Query the server every 5 seconds
time.sleep(5)
new_players = [player.name for player in client.get_server_clients()]
if new_players and new_players != players:
player_count = len(new_players)
timestamp = time.strftime('%H:%M:%S', time.localtime())
# Find out who joined/left
joined = [player for player in new_players if player not in players]
left = [player for player in players if player not in new_players]
if joined:
print(f"\033[32m{timestamp} Entrou: {', '.join(joined)}\033[0m [{player_count}/{max_players}]")
if left:
print(f"\033[31m{timestamp} Saiu: {', '.join(left)}\033[0m [{player_count}/{max_players}]")
players = new_players
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment