Author Topic: Python not returning the right object?  (Read 4766 times)

0 Members and 1 Guest are viewing this topic.

Offline Th3Ma5hatt3rTopic starter

  • Newbie
  • *
  • Posts: 6
  • Activity:
    0%
  • Reputation Power: 1
  • Th3Ma5hatt3r has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Python not returning the right object?
« on: March 15, 2014, 11:38:47 AM »
0
I'm using a simple function to try to see if there are any players close by. It should return true at the closest player and it works for the most part. If I run the code below it will find the closest player to me than if I move closer to a different player, but the last found player is still visible. It will return the last found player every time and not the closest player, until the last found player leaves or is to far away. Does anyone have any idea why this might be happening?

Code: [Select]
# This is a list of friendly player types.
Friendly_Player_Types = [0x0190, 0x0191, 0x02EC, 0x02EB, 0x007B]

def ScanForPlayer(ScanDistance):
SetFindDistance(ScanDistance)
FindTypeEx(0xFFFF, 0xFFFF, Ground(), False)
PossiblePlayers = GetFindedList()
#PossiblePlayers.reverse()

for player in PossiblePlayers:
playerType = GetType(player)
playerNotoriety = GetNotoriety(player)
 
print('Found Object - Name: ['+GetName(player)+'] Type: ['+str(playerType)+'] Notoriety: ['+str(playerNotoriety)+'].')
if not(IsNPC(player)):
continue
elif playerType not in Friendly_Player_Types:
continue
elif player == Self():
continue
elif playerNotoriety != 1:
continue
else:
print('Found nearby Player: ['+GetName(player)+'].')
return True
return False

Timer = GetTickCount()
foundPlayer = ScanForPlayer(10)
print('Search Time Took: ['+str(GetTickCount() - Timer)+'] in milliseconds.')
if foundPlayer:
print('Found a player.')
else:
print("Didn't find a player.")

Thanks for taking the time to read my post.

Offline dxrom

  • Master of the milestones!
  • Elite
  • *
  • *
  • Posts: 1080
  • Activity:
    0%
  • Reputation Power: 15
  • dxrom is working their way up.dxrom is working their way up.dxrom is working their way up.
  • KEYBOARD COWBOY, GREAT SAMURAI OF THE INTERNET.
  • Respect: +100
  • Referrals: 1
    • View Profile
Re: Python not returning the right object?
« Reply #1 on: March 15, 2014, 12:43:22 PM »
0
Shouldn't you be stepping through the array of Friendly_Player_Types in order to find each type? I'm unsure how python works, however it looks to me like if there were a player type 0x0190 and then another player type 0x02EB, the player id of type found 0x0190 would be returned, however the player id of type 0x02EB would not be returned because the FindTypeEx statement doesn't step past the first type (0x0190). Also GetFindedList() calls a list of the previous FindTypeEx, aka whatever has shown up for the call FindTypeEx(0xFFFF, 0xFFFF, Ground(), False), so again I believe you need to step through your array of Friendly_Player_Types in order to populate an accurate list.

I could be completely wrong though, I'm bad at programming :X
« Last Edit: March 15, 2014, 12:48:10 PM by dxrom »



 ​_██​_
(ಠ​_ృ)
I do say, ol' Chap! Come play EVE Online! Why here is a 21 Day Free Trial!

Offline slyone

  • Full Member
  • ***
  • Posts: 135
  • Activity:
    0%
  • Reputation Power: 2
  • slyone has no influence.
  • Gender: Male
  • Respect: +40
  • Referrals: 1
    • View Profile
Re: Python not returning the right object?
« Reply #2 on: March 16, 2014, 07:24:16 PM »
0
I'm using a simple function to try to see if there are any players close by. It should return true at the closest player and it works for the most part. If I run the code below it will find the closest player to me than if I move closer to a different player, but the last found player is still visible. It will return the last found player every time and not the closest player, until the last found player leaves or is to far away. Does anyone have any idea why this might be happening?


I tested out your code a bit and added the following after your "Found object" print statement:

Code: [Select]
print( GetX(player), GetY(player), GetZ(player) )
Adding that line just prints the location of each of the objects found.  For me it looks like the function
Code: [Select]
FindTypeEx doesn't return a list sorted closest to farthest.

Let me know if I'm mis-reading something.

-S
Started playing back at the Second Age

Offline Th3Ma5hatt3rTopic starter

  • Newbie
  • *
  • Posts: 6
  • Activity:
    0%
  • Reputation Power: 1
  • Th3Ma5hatt3r has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Python not returning the right object?
« Reply #3 on: March 16, 2014, 09:13:33 PM »
0
I'm using a simple function to try to see if there are any players close by. It should return true at the closest player and it works for the most part. If I run the code below it will find the closest player to me than if I move closer to a different player, but the last found player is still visible. It will return the last found player every time and not the closest player, until the last found player leaves or is to far away. Does anyone have any idea why this might be happening?


I tested out your code a bit and added the following after your "Found object" print statement:

Code: [Select]
print( GetX(player), GetY(player), GetZ(player) )
Adding that line just prints the location of each of the objects found.  For me it looks like the function
Code: [Select]
FindTypeEx doesn't return a list sorted closest to farthest.

Let me know if I'm mis-reading something.

-S

Yes I am starting to think that the list is not sorted either. Currently doing more work on that function. I will let you know what I figure out.

Offline Boydon

  • Moderator
  • **
  • *****
  • Posts: 76
  • Activity:
    0%
  • Reputation Power: 3
  • Boydon has no influence.
  • Respect: +16
  • Referrals: 0
    • View Profile
Re: Python not returning the right object?
« Reply #4 on: March 21, 2014, 01:41:49 AM »
0
You can sort it by yourself using Python sorted:

Code: [Select]
PossiblePlayers = GetFindedList()
SortedPlayers = sorted(PossiblePlayers, key=FindDistance)
Member of the Stealth development team.

Tags: