To anyone interested, I wrote this function which detects the presence of other players in the district. You can use it to stop the bot from continuing while other players are in the district.
Example usage (put this in your main loop):
Code:
; ; Checks if there are other players present in the vicinity of the player and logs their names.
Func AreOtherPlayersPresent()
Local $myLoginNumber = DllStructGetData(GetAgentByID(-2), 'LoginNumber') ; Your character's login number
Local $playerNames = "" ; Initialize an empty string to store player names
Local $playerFound = False ; Flag to indicate if any player was found
For $i = 1 To GetMaxAgents() ; Iterates through all possible agent IDs
Local $agent = GetAgentByID($i)
If IsDllStruct($agent) Then ; Checks if $agent is a valid structure
Local $loginNumber = DllStructGetData($agent, 'LoginNumber')
If $loginNumber <> 0 And $loginNumber <> $myLoginNumber Then ; Checks if the agent is a player and not you
Local $playerName = GetPlayerName($agent)
; Adjust the regex to allow spaces in player names.
If $playerName <> "" And StringRegExp($playerName, "^[a-zA-Z0-9 ]+$") Then ; Checks if the name is valid
$playerFound = True
$playerNames &= $playerName & [MENTION=3576271]CRLF[/MENTION] ; Append the player name to the list
EndIf
EndIf
EndIf
Next
If $playerFound Then
Logger("Players detected in the district: " & $playerNames) ; Log all detected player names
Return True ; Returns true as players were found
Else
Logger("No Other Players Found") ; Log when no players are found
Return False ; Returns false as no players were found
EndIf
EndFunc
Code:
; Wait until the district is empty of other players.
While AreOtherPlayersPresent()
Logger("Other players detected. Waiting 5s")
Sleep(10000) ; Wait for 10 seconds before checking again.
WEnd