[plugin] vGuildStoreDC

i think everybody know that bug where the GS is blocked by another char and the char is not avalable in any way becurse the player is not at home / or its ur char thats blocking it and its running on another pc and all the other farm char will skip the GS becurse of it

well lets say we have a solution for it with this plugin u can DC the blocking char automaticly
it will work with two list´s list 1 is “only send !DC command to the players in the list (list enable otherwise it will send it to any char in the guild if its blocking)” and a 2nd list with like that player is alowed to dc my char ( also with enabled list ) the list are there for preventing abuse so u cant get dc if somebody who dont like u send´s u a !DC via pm command

this plugin is made by @Verya with a tiny bit of help by @JellyBitz the Plugin idea was from me

Tested @ some vsro servers may work for other like k-sro c-sro i-sro…

a little tipp main chars should be able to dc farmchars not other way around otherwise u will be at medusa with ur main char and a farm bot will dc you keep that in mind

NEWEST WORKING VERSION [plugin] vGuildStoreDC - #20 by JellyBitz
FIXES “NOT LOAD CONFIG” by JellyBits

just put it in your plugin folder rename the .txt to .py and relog ur chars :slight_smile:

from phBot import *   **DONT USE THIS ONE SCROLL DOWN TO JellyBits RELEASE !**
import QtBind----------------------------------------------------------------------------------------------------------
import json
import os
import phBotChat
import struct



######################################################################################
#                                                                                    #
#                                  Initializing Vars                                 #
#                                                                                    #
######################################################################################
isConnected = False # avoid possible issues
SERVER_GUILD_STORAGE_DATA_RESPONSE = 0xB250

######################################################################################
#                                                                                    #
#                                  Initializing GUI                                  #
#                                                                                    #
######################################################################################
gui = QtBind.init(__name__,'vGuildStoreDC')

cbx_EnablePlugin = QtBind.createCheckBox(gui, 'cbx_EnablePlugin_clicked','Enable vGuildStoreDC',20,10)
cbx_SendDC = QtBind.createCheckBox(gui, 'cbx_SendDC_clicked','Send DC command to the Blocking Guild Member',20,35)
cbx_SendDC_ListOnly = QtBind.createCheckBox(gui, 'cbx_SendDC_ListOnly_clicked','Send only to Players in List',20,55)
txt_SendingChar = QtBind.createLineEdit(gui, '', 20, 80, 100, 20)
btn_AddSendChar = QtBind.createButton(gui,'btnAddSendChar_clicked',"Add",130,80)
lst_SendingChars = QtBind.createList(gui, 20, 105, 185, 145)
btn_RemoveSendChar = QtBind.createButton(gui,'btnRemSendChar_clicked',"                       Remove                       ",20,255)


cbx_EnableReceiveDC = QtBind.createCheckBox(gui, 'cbx_EnableReceiveDC_clicked','Enable Receive DC command',300,35)
cbx_ReceiveDC_ListOnly = QtBind.createCheckBox(gui, 'cbx_ReceiveDC_ListOnly_clicked','Only Receive DC command from Players in List',300,55)
txt_ReceivingChar = QtBind.createLineEdit(gui, '', 300, 80, 100, 20)
btn_AddReceiveChar = QtBind.createButton(gui,'btnAddReceiveChar_clicked',"Add",410,80)
lst_ReceivingChars = QtBind.createList(gui, 300, 105, 185, 145)
btn_RemoveReceiveChar = QtBind.createButton(gui,'btnRemReceiveChar_clicked',"                       Remove                       ",300,255)



######################################################################################
#                                                                                    #
#                                     Functions                                      #
#                                                                                    #
######################################################################################
# Called when the bot successfully connects to the game server
def connected():
	global isConnected
	isConnected = False
	
# Called when the character enters the game world
def joined_game():
	global isConnected	
	isConnected = True
	config_load()

def get_vGuildStoreDC_path():
	return get_config_path()[:-5]+'_vGuildStoreDC.json'

def config_load():
	if os.path.exists(get_vGuildStoreDC_path()):
		data = {}
		with open(get_vGuildStoreDC_path(),"r") as f:
			data = json.load(f)
		if "Sending Chars" in data:
			for item in data["Sending Chars"]:
				QtBind.append(gui,lst_SendingChars,item)

		if "Receiving Chars" in data:
			for item in data["Receiving Chars"]:
				QtBind.append(gui,lst_ReceivingChars,item)
		# config radiobutton if is saved
		if data['Plugin enabled'] == True:
			QtBind.setChecked(gui, cbx_EnablePlugin, True)

		if data['Send DC'] == True:
			QtBind.setChecked(gui, cbx_SendDC, True)

		if data['Send DC to List only'] == True:
			QtBind.setChecked(gui, cbx_SendDC_ListOnly, True)

		if data['Enable Receive DC'] == True:
			QtBind.setChecked(gui, cbx_EnableReceiveDC, True)

		if data['Enable Receive DC only from List'] == True:
			QtBind.setChecked(gui, cbx_ReceiveDC_ListOnly, True)

def cbx_EnablePlugin_clicked(checked):
	if isConnected:

		if checked == True:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Plugin enabled" in data:
				data['Plugin enabled'] = True
			else:
				data['Plugin enabled'] = True
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Plugin enabled')
		else:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Plugin enabled" in data:
				data['Plugin enabled'] = False
			else:
				data['Plugin enabled'] = False
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Plugin disabled')

def cbx_SendDC_clicked(checked):
	if isConnected:

		if checked == True:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Send DC" in data:
				data['Send DC'] = True
			else:
				data['Send DC'] = True
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Sending DC Command enabled')
		else:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Send DC" in data:
				data['Send DC'] = False
			else:
				data['Send DC'] = False
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Sending DC Command disabled')

def cbx_SendDC_ListOnly_clicked(checked):
	if isConnected:

		if checked == True:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Send DC to List only" in data:
				data['Send DC to List only'] = True
			else:
				data['Send DC to List only'] = True
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Sending DC Command only to List enabled')
		else:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Send DC to List only" in data:
				data['Send DC to List only'] = False
			else:
				data['Send DC to List only'] = False
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Sending DC Command only to List disabled')

def cbx_EnableReceiveDC_clicked(checked):
	if isConnected:

		if checked == True:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Enable Receive DC" in data:
				data['Enable Receive DC'] = True
			else:
				data['Enable Receive DC'] = True
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Receiving DC Command enabled')
		else:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Enable Receive DC" in data:
				data['Enable Receive DC'] = False
			else:
				data['Enable Receive DC'] = False
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Receiving DC Command disabled')

def cbx_ReceiveDC_ListOnly_clicked(checked):
	if isConnected:

		if checked == True:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Enable Receive DC only from List" in data:
				data['Enable Receive DC only from List'] = True
			else:
				data['Enable Receive DC only from List'] = True
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Receiving DC Command only from List enabled')
		else:
			data = {}
			if os.path.exists(get_vGuildStoreDC_path()):
				with open(get_vGuildStoreDC_path(),"r") as f:
					data = json.load(f)
			if "Enable Receive DC only from List" in data:
				data['Enable Receive DC only from List'] = False
			else:
				data['Enable Receive DC only from List'] = False
			with open(get_vGuildStoreDC_path(),"w") as f:
				f.write(json.dumps(data, indent=4, sort_keys=True))
			log('[vGuildStoreDC] Receiving DC Command only from List disabled')

def btnAddSendChar_clicked():
	if isConnected:
		NewSendingchar = QtBind.text(gui, txt_SendingChar)
		CurrentSendingChars = QtBind.getItems(gui, lst_SendingChars)
		if not NewSendingchar == "":
			if not NewSendingchar in CurrentSendingChars:
				data = {}
				if os.path.exists(get_vGuildStoreDC_path()):
					with open(get_vGuildStoreDC_path(),"r") as f:
						data = json.load(f)
				if "Sending Chars" in data:
					data['Sending Chars'].append(NewSendingchar)
				else:
					data['Sending Chars'] = [NewSendingchar]
				with open(get_vGuildStoreDC_path(),"w") as f:
					f.write(json.dumps(data, indent=4, sort_keys=True))
				QtBind.append(gui, lst_SendingChars, NewSendingchar)
				log("[vGuildStoreDC] Added new Sending Char: ["+NewSendingchar+"]")
			else:
				log("[vGuildStoreDC] This Char is already in List")

def btnRemSendChar_clicked():
	if isConnected:
		SelectedSendingChar = QtBind.text(gui, lst_SendingChars)
		data = {}
		if os.path.exists(get_vGuildStoreDC_path()):
			with open(get_vGuildStoreDC_path(),"r") as f:
				data = json.load(f)
		if "Sending Chars" in data:
			data['Sending Chars'].remove(SelectedSendingChar)
		with open(get_vGuildStoreDC_path(),"w") as f:
			f.write(json.dumps(data, indent=4, sort_keys=True))
		QtBind.remove(gui, lst_SendingChars, SelectedSendingChar)
		log("[vGuildStoreDC] Removed Sending Char: ["+SelectedSendingChar+"]")

def btnAddReceiveChar_clicked():
	if isConnected:
		NewReceivingChar = QtBind.text(gui, txt_ReceivingChar)
		CurrentReceivingChars = QtBind.getItems(gui, lst_ReceivingChars)
		if not NewReceivingChar == "":
			if not NewReceivingChar in CurrentReceivingChars:
				data = {}
				if os.path.exists(get_vGuildStoreDC_path()):
					with open(get_vGuildStoreDC_path(),"r") as f:
						data = json.load(f)
				if "Receiving Chars" in data:
					data['Receiving Chars'].append(NewReceivingChar)
				else:
					data['Receiving Chars'] = [NewReceivingChar]
				with open(get_vGuildStoreDC_path(),"w") as f:
					f.write(json.dumps(data, indent=4, sort_keys=True))
				QtBind.append(gui, lst_ReceivingChars, NewReceivingChar)
				log("[vGuildStoreDC] Added new Receiving Char: ["+NewReceivingChar+"]")
			else:
				log("[vGuildStoreDC] This Char is already in List")

def btnRemReceiveChar_clicked():
	if isConnected:
		SelectedReceivingChar = QtBind.text(gui, lst_ReceivingChars)
		data = {}
		if os.path.exists(get_vGuildStoreDC_path()):
			with open(get_vGuildStoreDC_path(),"r") as f:
				data = json.load(f)
		if "Receiving Chars" in data:
			data['Receiving Chars'].remove(SelectedReceivingChar)
		with open(get_vGuildStoreDC_path(),"w") as f:
			f.write(json.dumps(data, indent=4, sort_keys=True))
		QtBind.remove(gui, lst_ReceivingChars, SelectedReceivingChar)
		log("[vGuildStoreDC] Removed Receiving Char: ["+SelectedReceivingChar+"]")

def handle_chat(t,player,msg):	
	if QtBind.isChecked(gui, cbx_EnablePlugin):
		if msg == "!DC":
			if QtBind.isChecked(gui, cbx_EnableReceiveDC):
				if QtBind.isChecked(gui, cbx_ReceiveDC_ListOnly):
					ReceivingChars = QtBind.getItems(gui, lst_ReceivingChars)
					if player in ReceivingChars:
						log("[vGuildStoreDC] Disconnect because of receiving DC Command from "+player)
						disconnect()
				else:
					log("[vGuildStoreDC] Disconnect because of receiving DC Command from "+player)
					disconnect()
			else:
				log("not checked")
		

def handle_joymax(opcode, data):
	if opcode == SERVER_GUILD_STORAGE_DATA_RESPONSE:
		result = data[0]
		if result == 2: # Error
			reasonCode = struct.unpack_from('<H',data,1)[0]
			if reasonCode == 19528: # .. 48 4C ..
				charLength = struct.unpack_from('<H',data,3)[0]
				charName = struct.unpack_from('<' + str(charLength) + 's',data,5)[0].decode('cp1252')
				if QtBind.isChecked(gui, cbx_EnablePlugin):
					if QtBind.isChecked(gui, cbx_SendDC):
						if QtBind.isChecked(gui, cbx_SendDC_ListOnly):
							CurrentSendingChars = QtBind.getItems(gui, lst_SendingChars)
							if charName in CurrentSendingChars:
								log("vGuildStoreDC: "+charName+" is using guild storage! Trying disconnect him...")
								phBotChat.Private(charName,"!DC")
						else:
							log("vGuildStoreDC: "+charName+" is using guild storage! Trying disconnect him...")
							phBotChat.Private(charName,"!DC")
	return True

log('[%s] by Chefkoch, Verya & JellyBitz Loaded' % __name__)
4 Likes

What about DC only at training area?

# Check if the character is inside training area
def inTrainingArea():
	# Get my current position
	mPos = get_position()
	# Get current training area setup
	tArea = get_training_area()

	# Get radius and position (I guess, not even sure what this dictionary has)
	tRad = tArea['radius']
	tPos = tArea['position']

	# Compare coordinates but only if they are at the same regional map
	if (mPos['region'] <= 32767 and tPos['region'] <= 32767) or mPos['region'] == tPos['region']:
		# compare world map or in the same dungeon only
		if round(GetDistance(mPos['x'], mPos['y'],tPos['x'],tPos['y']),2) <= tRad:
			return True
	return False

# Calc the distance from point A to B
def GetDistance(ax,ay,bx,by):
	return ((bx-ax)**2 + (by-ay)**2)**(0.5)
2 Likes

i will test it later this day if u allow me to use it for the plugin

i just have to copy paste it right ?
@JellyBitz
if i just copy past it it will not load

1 Like

I can use it if you can add above idea, great work.

question the main char will dc the farm char when they went back to town right ?
that mean if i have 20 char
19 char stucked in gs because 1 char
my main need to comeback to toown first and try to enter the gs to dc the char that stucking the gs ?

another question lets say that the 19 char is waiting in gs
and the main dced the char that was stucking is he gonna dc every char entering before him ?

@Mo7ammadQ8

  1. just if the main enters the GS and gets a notice that char xxxx is using the gs then it will send the dc command
    u can set it up that the farm char 1 can dc farm char 2 farm char 2 can only dc farm char 3 and so on 1>2 2>3 3>4 … and main char cant be dced and main char can dc all also u should set “skip gs if member is close " and at least try 3x for gs”

  2. no just that char that was blocking the gs

great, i will test it later … thank you <3

Anyone can implement if inTrainingArea thing? I tried but its not working.

try the upper one thats working but its doesnt have the “only at traings area” option

I need only at training area feature mate. My army (30+ accs) having issues with it atm. They are keep dcing other ones at guild storage (infinite loop lol)

make it like this

its a setup problem if you set everyone can dc everyone it will always dc … ofc it does its just logic…

Hi @Chefkoch, I have downladed the plugin and have it loaded to the bot. However, I couldn’t add the name of the character who will send the DC to command to the list no matter how many times I tried to click the button. Is there a way that I can trouble shoot this?

@raiallen did you restarted the bot after adding it and check if the folder is maybe write protected

1 Like

Actually, It worked after I restarted the bot. Thank you very much!

I have another problem while using this plugin. It doesn’t save the settings. I have to keep on enable the plugin every time I play for every single character. Is this a normal behavior?

you can also do it the the config file and then save it maybe this works better

1 Like

check whether you have write access to the folder

1 Like

@Verya got the same problem … idk json file seems right ( yes its read only windows does not let me change it and reinstalling windows also dont help it seems like all folder/files on all disks are read only by default (w10 and w7 ) but i still can change/save all files in windows) thats my current
file: Retro_Redhead.Normal_vGuildStoreDC.json

{
“Enable Receive DC”: true,
“Enable Receive DC only from List”: true,
“Plugin enabled”: true,
“Receiving Chars”: [
“1”
],
“Send DC”: true,
“Send DC to List only”: true,
“Sending Chars”: [
“1”
]
}

result : plugin loaded nothing is selected in the plugin

it dont seam to load properly maybe it has something to do with the profiles

stopped using the plugin awhile back because it’s not memorizing the settings. I have already given all folders access to write and applied the settings and it still not saving my choice in the bot. Every time i got disconnected everything will have to start from the beginning.

I fixed it a little bit… I barely added “in_training_area()” check, but I didn’t test since I don’t know which values can be found with phbot API.

I’m dropping it here if you don’t mind.

from phBot import *
import QtBind
import json
import os
import phBotChat
import struct

######################################################################################
#                                                                                    #
#                                  Initializing Vars                                 #
#                                                                                    #
######################################################################################
isConnected = False # avoid possible issues
character_data = None
SERVER_GUILD_STORAGE_DATA_RESPONSE = 0xB250

######################################################################################
#                                                                                    #
#                                  Initializing GUI                                  #
#                                                                                    #
######################################################################################
gui = QtBind.init(__name__,'vGuildStoreDC')

cbx_EnablePlugin = QtBind.createCheckBox(gui, 'cbx_EnablePlugin_clicked','Enable vGuildStoreDC',20,10)
cbx_SendDC = QtBind.createCheckBox(gui, 'cbx_SendDC_clicked','Send DC command to the Blocking Guild Member',20,35)
cbx_SendDC_ListOnly = QtBind.createCheckBox(gui, 'cbx_SendDC_ListOnly_clicked','Send only to Players in List',20,55)
txt_SendingChar = QtBind.createLineEdit(gui, '', 20, 80, 100, 20)
btn_AddSendChar = QtBind.createButton(gui,'btnAddSendChar_clicked',"Add",130,80)
lst_SendingChars = QtBind.createList(gui, 20, 105, 185, 145)
btn_RemoveSendChar = QtBind.createButton(gui,'btnRemSendChar_clicked',"                       Remove                       ",20,255)

cbx_EnableReceiveDC = QtBind.createCheckBox(gui, 'cbx_EnableReceiveDC_clicked','Enable Receive DC command',300,35)
cbx_ReceiveDC_ListOnly = QtBind.createCheckBox(gui, 'cbx_ReceiveDC_ListOnly_clicked','Only Receive DC command from Players in List',300,55)
txt_ReceivingChar = QtBind.createLineEdit(gui, '', 300, 80, 100, 20)
btn_AddReceiveChar = QtBind.createButton(gui,'btnAddReceiveChar_clicked',"Add",410,80)
lst_ReceivingChars = QtBind.createList(gui, 300, 105, 185, 145)
btn_RemoveReceiveChar = QtBind.createButton(gui,'btnRemReceiveChar_clicked',"                       Remove                       ",300,255)

######################################################################################
#                                                                                    #
#                                     Functions                                      #
#                                                                                    #
######################################################################################
# Called when the bot successfully connects to the game server
def connected():
	global isConnected
	isConnected = False
	
# Called when the character enters the game world
def joined_game():
	global isConnected, character_data
	isConnected = True
	character_data = get_character_data()
	config_load()

def get_vGuildStoreDC_path():
	return get_config_dir() + character_data['server'] + "_" + character_data['name'] + "_vGuildStoreDC.json"

def config_load():
	if os.path.exists(get_vGuildStoreDC_path()):
		data = {}
		with open(get_vGuildStoreDC_path(),"r") as f:
			data = json.load(f)
		if "Sending Chars" in data:
			for item in data["Sending Chars"]:
				QtBind.append(gui,lst_SendingChars,item)

		if "Receiving Chars" in data:
			for item in data["Receiving Chars"]:
				QtBind.append(gui,lst_ReceivingChars,item)
		# config radiobutton if is saved
		if data['Plugin enabled'] == True:
			QtBind.setChecked(gui, cbx_EnablePlugin, True)

		if data['Send DC'] == True:
			QtBind.setChecked(gui, cbx_SendDC, True)

		if data['Send DC to List only'] == True:
			QtBind.setChecked(gui, cbx_SendDC_ListOnly, True)

		if data['Enable Receive DC'] == True:
			QtBind.setChecked(gui, cbx_EnableReceiveDC, True)

		if data['Enable Receive DC only from List'] == True:
			QtBind.setChecked(gui, cbx_ReceiveDC_ListOnly, True)

# Save all configs
def config_save():
	if isConnected:
		# Init dict
		data = {}
		# Save current settings
		data['Plugin enabled'] = QtBind.isChecked(gui,cbx_EnablePlugin)

		data['Sending Chars'] = QtBind.getItems(gui,lst_SendingChars)
		data['Receiving Chars'] = QtBind.getItems(gui,lst_ReceivingChars)

		data['Send DC'] = QtBind.isChecked(gui,cbx_SendDC)
		data['Send DC to List only'] = QtBind.isChecked(gui,cbx_SendDC_ListOnly)
		data['Enable Receive DC'] = QtBind.isChecked(gui,cbx_EnableReceiveDC)
		data['Enable Receive DC only from List'] = QtBind.isChecked(gui,cbx_ReceiveDC_ListOnly)

		# Overrides
		with open(get_vGuildStoreDC_path(),"w") as f:
			f.write(json.dumps(data, indent=4, sort_keys=True))
		log("[vGuildStoreDC] Configs has been saved")

def cbx_EnablePlugin_clicked(checked):
	if isConnected:
		log('[vGuildStoreDC] Plugin '+('enabled' if checked else 'disabled'))
		config_save()

def cbx_SendDC_clicked(checked):
	if isConnected:
		log('[vGuildStoreDC] Sending DC Command '+('enabled' if checked else 'disabled'))
		config_save()

def cbx_SendDC_ListOnly_clicked(checked):
	if isConnected:
		log('[vGuildStoreDC] Sending DC Command only to List '+('enabled' if checked else 'disabled'))
		config_save()

def cbx_EnableReceiveDC_clicked(checked):
	if isConnected:
		log('[vGuildStoreDC] Receiving DC Command '+('enabled' if checked else 'disabled'))
		config_save()

def cbx_ReceiveDC_ListOnly_clicked(checked):
	if isConnected:
		log('[vGuildStoreDC] Receiving DC Command only from List '+('enabled' if checked else 'disabled'))
		config_save()

def btnAddSendChar_clicked():
	if isConnected:
		NewSendingchar = QtBind.text(gui, txt_SendingChar)
		CurrentSendingChars = QtBind.getItems(gui, lst_SendingChars)
		if NewSendingchar:
			if not NewSendingchar in CurrentSendingChars:
				QtBind.append(gui, lst_SendingChars, NewSendingchar)
				log("[vGuildStoreDC] Added new Sending Char: ["+NewSendingchar+"]")
				config_save()
			else:
				log("[vGuildStoreDC] This Char is already in List")

def btnRemSendChar_clicked():
	if isConnected:
		SelectedSendingChar = QtBind.text(gui, lst_SendingChars)
		# Check if something is selected
		if SelectedSendingChar:
			QtBind.remove(gui, lst_SendingChars, SelectedSendingChar)
			log("[vGuildStoreDC] Removed Sending Char: ["+SelectedSendingChar+"]")
			config_save()

def btnAddReceiveChar_clicked():
	if isConnected:
		NewReceivingChar = QtBind.text(gui, txt_ReceivingChar)
		CurrentReceivingChars = QtBind.getItems(gui, lst_ReceivingChars)
		if NewReceivingChar:
			if not NewReceivingChar in CurrentReceivingChars:
				QtBind.append(gui, lst_ReceivingChars, NewReceivingChar)
				log("[vGuildStoreDC] Added new Receiving Char: ["+NewReceivingChar+"]")
				config_save()
			else:
				log("[vGuildStoreDC] This Char is already in List")

def btnRemReceiveChar_clicked():
	if isConnected:
		SelectedReceivingChar = QtBind.text(gui, lst_ReceivingChars)
		# Check if something is selected
		if SelectedReceivingChar:
			QtBind.remove(gui, lst_ReceivingChars, SelectedReceivingChar)
			log("[vGuildStoreDC] Removed Receiving Char: ["+SelectedReceivingChar+"]")
			config_save()

def handle_chat(t,player,msg):	
	if QtBind.isChecked(gui, cbx_EnablePlugin):
		if msg == "!DC":
			if QtBind.isChecked(gui, cbx_EnableReceiveDC):
				if QtBind.isChecked(gui, cbx_ReceiveDC_ListOnly):
					ReceivingChars = QtBind.getItems(gui, lst_ReceivingChars)
					if player in ReceivingChars:
						log("[vGuildStoreDC] Disconnect because of receiving DC Command from "+player)
						disconnect()
				else:
					log("[vGuildStoreDC] Disconnect because of receiving DC Command from "+player)
					disconnect()
			else:
				log("[vGuildStoreDC] Receive DC command is disabled ("+player+")")

def handle_joymax(opcode, data):
	if opcode == SERVER_GUILD_STORAGE_DATA_RESPONSE:
		result = data[0]
		if result == 2: # Error
			reasonCode = struct.unpack_from('<H',data,1)[0]
			if reasonCode == 19528: # .. 48 4C ..
				charLength = struct.unpack_from('<H',data,3)[0]
				charName = struct.unpack_from('<' + str(charLength) + 's',data,5)[0].decode('cp1252')
				if QtBind.isChecked(gui, cbx_EnablePlugin):
					if QtBind.isChecked(gui, cbx_SendDC):
						if QtBind.isChecked(gui, cbx_SendDC_ListOnly):
							CurrentSendingChars = QtBind.getItems(gui, lst_SendingChars)
							if charName in CurrentSendingChars:
								log("[vGuildStoreDC] "+charName+" is using guild storage! Trying disconnect him...")
								phBotChat.Private(charName,"!DC")
						else:
							log("[vGuildStoreDC] "+charName+" is using guild storage! Trying disconnect him...")
							phBotChat.Private(charName,"!DC")
	return True

# Check if the character is inside training area
def in_training_area():
	# Calc the distance from point A to B
	def calc_distance(ax,ay,bx,by):
		return ((bx-ax)**2 + (by-ay)**2)**(0.5)

	# Get my current position
	mPos = get_position()
	# Get current training area setup
	tArea = get_training_area()

	# Get radius and position (Not even sure what this dictionary has, phbot API has no info about it)
	tRad = tArea['radius']
	tPos = tArea['position']

	# Compare coordinates but only if they are at the same regional map (Donwhang is not taken on consideration)
	if (mPos['region'] <= 32767 and tPos['region'] <= 32767) or mPos['region'] == tPos['region']:
		# compare world map or in the same dungeon only
		if round(calc_distance(mPos['x'], mPos['y'],tPos['x'],tPos['y']),2) <= tRad:
			return True
	return False

log('[%s] by Chefkoch, Verya & JellyBitz Loaded' % __name__)
5 Likes