[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 ***

vGuildStoreDC.txt (13.0 KB)
just put it in your plugin folder rename the .txt to .py and relog ur chars :slight_smile:

from phBot import *
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__)
3 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 && tPos['region'] <= 32767) || 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)
1 Like

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