Python script to read players around

08/03/2018 17:49 Reff#1
Hello!
On the GF client.
I'm trying to read if there are players around me with this code:
Code:
import chr,time,thread,chat,threading

start_time = time.time()

def isInstance(vid):
	if chr.HasInstance(vid):
		return True
	return False

def isSelf(vid):
	if chr.GetNameByVID(vid) == chr.GetName():
		return True
	return False

def isPlayer(vid):
	if isInstance(vid):
		if chr.GetInstanceType(vid) == chr.INSTANCE_TYPE_PLAYER:
			return True
	return False

def SCAN():
	playerlist = []
	for x in xrange(10000000):
		if isInstance(x) and isPlayer(x) and not isSelf(x) and not x in playerlist:
			playerlist.append(x)
	return playerlist

def f1():
	PLRS = SCAN()
	chat.AppendChat(3, "Scan finished. {} players found.".format(len(PLRS)))
	chat.AppendChat(2, "Took {}.".format(time.time()-begin))

t1 = threading.Thread(name='SCAN', target=f1)
t1.start()
t1.join()
But for some reason it won't run?
I don't know why. And do you think this is the best method to do it? I couldn't find any functions to list players around me so I'm scanning for every possible VID number.

If anyone can give me some light :) Thank you
08/03/2018 17:50 M7TRA#2
Maybe gamforge patched the threading module out with the update.
And i think you import threading wrong. I remember its something like
PHP Code:
from threading import Thread 
You import both threading and thread but they are 2 different modules.
08/03/2018 17:56 Reff#3
Quote:
Originally Posted by M7TRA View Post
Maybe gamforge patched the threading module out with the update.
And i think you import threading wrong. I remember its something like
PHP Code:
from threading import Thread 
You import both threading and thread but they are 2 different modules.
I tried importing it both ways. It was indeed working yesterday before patch, now I just can't use it. It seems like when I do import threading it's like threading doesn't exist.

And using this:
Code:
thread.start_new_thread(f1,())
Isn't instantaneous, and sometimes it does not even run too.
08/03/2018 17:58 M7TRA#4
OK, it seems like its patched then..
08/03/2018 18:03 Reff#5
Quote:
Originally Posted by M7TRA View Post
OK, it seems like its patched then..
-> thread.start_new_thread(f1,())
This works though for basic tasks, just my code for some reason makes it slow. I don't have much experience with python.

Does anyone know any alternatives? Ways to find players around me within the script.
08/03/2018 18:05 M7TRA#6
Quote:
Originally Posted by nunuh22 View Post
-> thread.start_new_thread(f1,())
This works though for basic tasks, just my code for some reason makes it slow. I don't have much experience with python.

Does anyone know any alternatives? Ways to find players around me within the script.
strange i dont know dude..
08/07/2018 13:33 Reff#7
I fixed the threading use by adding the compiled threading.pyc back to metin2 lib folder.
Still, my method of reading players around me is too slow. :( If anyone's got a better way and they're willing to share?:)
I'm trying to do this through python only but I'll take any suggestion.