Jump to content

VegaS™

Forum Moderator
  • Posts

    656
  • Joined

  • Last visited

  • Days Won

    187
  • Feedback

    100%

Posts posted by VegaS™

  1. On 10/2/2019 at 1:32 AM, dracaryS said:
    
    class QueuePython(object):
    	def __init__(self):
    		self.eventList=[]
    	def __del__(self):
    		if len(self.eventList) > 0:
    			self.eventList.clear()
    	def Process(self):
    		if len(self.eventList) > 0:
    			for j in xrange(len(self.eventList)):
    				if app.GetTime() > self.eventList[j]["time"]:
    					i = self.eventList[j]["func"]()
    					if i == 0:
    						self.eventList[j].clear()
    					else:
    						self.eventList[j]["time"] = app.GetTime()+i
    	def AppendEvent(self,name,func,time):
    		self.eventList.append({"name":str(name),"func":__mem_func__(func),"time":int(app.GetTime()+time)})

    Thanks for release, the idea isn't bad, but there're some bad things. 
    I'll show you the problems part and how can be improved, there're just advices, i hope you'll get them.

    • def __del__(self):
      	if len(self.eventList) > 0:
      		self.eventList.clear()

    If you're using Python 2+ or Python 3.2 and below, you can't use the clear() method (allowed on 3.3+), also as i said in the second message you don't need to check the length of the list, already the clear() method doing that inside and there's no reason to put it to __del__ method, it will be called when the object is garbage collected. if you really want to use in future, something outside of this and want just to check the list if isn't empty, is enough to do it just with if some_list, like a normal boolean, there no need to check the length of the list if you don't use it in your code.

    • if len(self.eventList) > 0:
      	for j in xrange(len(self.eventList)):
      		[...]

    You don't have to check the list if you already did a numeric range loop or iterator based loop.

    Spoiler
    
    self.eventList = []
    ''' example 1 '''
    for i in xrange(len(self.eventList)):
        print (self.eventList[i])
    ''' example 2 '''
    for event in self.eventList:
        print (event)
    #<nothing will be printed>
    • app.GetTime() +  time

    I would say to use app.GetGlobalTimeStamp() instead of app.GetTime(), if you teleport while the event is running, the event function will run after 10 seconds like. While app.GetGlobalTimeStamp() will run after the specific time, because is the server timestamp and is updated on each enter in game.

    • if i == 0:
      	self.eventList[j].clear()

    I would put here an big exclamation, with this you creating 999999999 lines in syserr, what you do here is like:

    While Process() function is called in OnUpdate, so, your condition trying to get the returned value from an specific function, what means the next update time or 0 to destroy the event/clear it. Everything's fine until you return 0 and event should be stopped yes? But there is a problem, you clear the specific dictionary of event and still remained in the list [{}], and the Process() function will take your self.eventList with the items included, the empty dictionaries from your events, and of course even if you've [{}, {}, {}], that doesn't mean your list is empty, have 3 items, so, the loop will trying to read an empty dictionary and you'll get key errors in each milisecond. The method which you need is to delete the dictionary itself from the list after the result value from the function is 0, like this:

    Spoiler
    
    del self.eventList[j]

    _______________________________________

    I wrote fast some self extensions,  if somebody is interested i'll do another updates in the next days.

    • You can use unlimited arguments on functions, now is using the apply method which returns the result of a function or class object called with supplied arguments,  with the old structure you could use just one argument.
    • You can lock/unlock an event for being processed, it's like a prevent in some actions, if the event is created and you want to do something, you should lock the event, do some actions then you can unlock it again and the process function will run where remained.
    • Delete an event instantly and force it to stop the process.
    • Adding return t.EXIT inside of the running function, will delete the event too.
    • Functions to check if an event exists or is locked or not.
    • Check if the function is a method type.
    • Delete the events with a properly method.
    • Using app.GetGlobalTimeStamp() now will give you the chance to run the event after teleport where timer remained instantly.
    Spoiler
    
    t = ui.Queue()
    # ex1
    t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run)
    # ex2
    t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run, eventFuncArgs=player.GetLevel())
    # ex3
    t.AppendEvent(eventName='RUN', eventStartTime=0, eventFunc=self.Run, eventFuncArgs=(player.GetLevel(), player.GetName()))
    # ex4
    t.AppendEvent('UPDATE', 0, self.Update, {'data' : (1, True, (14, 12), [5, 1], 'Corsair')})
    
    # Others:
    if t.GetEvent('RUN'):
    	print ("The event exists.")
    
    if t.GetIsLockedEvent('RUN'):
    	print ("The event exists but is locked.")
        
    t.LockEvent('RUN')
    t.UnlockEvent('RUN')
    t.DeleteEvent('RUN')

    _______________________________________

    The code:

    This is the hidden content, please

    PS: Don't quote this reply, will be updated.

    • Metin2 Dev 9
    • Good 4
    • Love 17
  2. M2 Download Center

    This is the hidden content, please
    ( Internal )

    This is the hidden content, please
    ( GitHub )

    I added two years ago a small function that allow you to make a struct like C++ for different purposes.

    # Example #1

        pack = ui.RegisterStructClass('a b c')(15, {}, [])
        pack.a += 50
        pack.b.update({0: 250})
        pack.c.append(100)
        print (pack.a, pack.b, pack.c)

    # Example #2.

        def Transfer(self, p):
    		print(p.szName, p.lX, p.lY)
    
        self.Transfer(ui.RegisterStructClass('szName lX lY')(GetName(), GetX(), GetY()))

    # Example #3.

    config = ui.RegisterStructClass('width height default_size_dict rank_list text')(450, 300, {'w': 400, 'h': 500}, [1, 2, 3], 'Metin2')
    
    print (
    	config.width, config.height, config.text,
    	config.default_size_dict.get('w'), config.default_size_dict.get('h'),
    	config.rank_list
    )

    Repository:

    This is the hidden content, please

    • Metin2 Dev 10
    • kekw 1
    • Sad 1
    • Lmao 1
    • Good 3
    • Love 1
    • Love 6
  3. 29 minutes ago, ReFresh said:

    Could it look like this?

    No, you need to add the condition before inserting the entity.

    Spoiler
    
    class CFuncViewInsert
    {
    	private:
    		int dwViewRange;
    
    	public:
    		LPENTITY m_me;
    
    		CFuncViewInsert(LPENTITY ent) :
    			dwViewRange(VIEW_RANGE + VIEW_BONUS_RANGE),
    			m_me(ent)
    		{
    		}
    
    		void operator () (LPENTITY ent)
    		{
    			// 오브젝트가 아닌 것은 거리를 계산하여 거리가 멀면 추가하지 않는다.
    			if (!ent->IsType(ENTITY_OBJECT))
    				if (DISTANCE_APPROX(ent->GetX() - m_me->GetX(), ent->GetY() - m_me->GetY()) > dwViewRange)
    					return;
    				
    #ifdef HIDDEN_OX
    			if (ent->IsType(ENTITY_CHARACTER) && m_me->IsType(ENTITY_CHARACTER))
    			{
    				const LPCHARACTER chMe = static_cast<LPCHARACTER>(m_me);
    				const LPCHARACTER chEnt = static_cast<LPCHARACTER>(ent);
    
    				if (chMe->GetMapIndex() == OXEVENT_MAP_INDEX && !chMe->IsGM() && !chEnt->IsGM())
    					return;		
    			}
    #endif
    			// 나를 대상에 추가
    			m_me->ViewInsert(ent);
    
    			// 둘다 캐릭터면
    			if (ent->IsType(ENTITY_CHARACTER) && m_me->IsType(ENTITY_CHARACTER))
    			{
    				LPCHARACTER chMe = (LPCHARACTER) m_me;
    				LPCHARACTER chEnt = (LPCHARACTER) ent;
    
    				// 대상이 NPC면 StateMachine을 킨다.
    				if (chMe->IsPC() && !chEnt->IsPC() && !chEnt->IsWarp() && !chEnt->IsGoto())
    					chEnt->StartStateMachine();
    			}
    		}
    };

     

    Don't forget:

    • entity_view.cpp
    #include "OXEvent.h"
    • service.h
    #define HIDDEN_OX

     

     

  4. The idea isn't so bad, but the code has too many useless lines, here's what you can do to improve it.

     

    	def RefreshPickupFilter(self):
    		#Weapon
    		if systemSetting.IsPickUpFilterWeapon():
    			self.PickUpFilterList[0].Down()
    		else:
    			self.PickUpFilterList[0].SetUp()
    		#Armor
    		if systemSetting.IsPickUpFilterArmor():
    			self.PickUpFilterList[1].Down()
    		else:
    			self.PickUpFilterList[1].SetUp()
    		#Ear
    		if systemSetting.IsPickUpFilterEar():
    			self.PickUpFilterList[2].Down()
    		else:
    			self.PickUpFilterList[2].SetUp()
    		#Neck
    		if systemSetting.IsPickUpFilterNeck():
    			self.PickUpFilterList[3].Down()
    		else:
    			self.PickUpFilterList[3].SetUp()
    		#Foots
    		if systemSetting.IsPickUpFilterFoots():
    			self.PickUpFilterList[4].Down()
    		else:
    			self.PickUpFilterList[4].SetUp()		
    		#Shield
    		if systemSetting.IsPickUpFilterShield():
    			self.PickUpFilterList[5].Down()
    		else:
    			self.PickUpFilterList[5].SetUp()		
    		#Book
    		if systemSetting.IsPickUpFilterBook():
    			self.PickUpFilterList[6].Down()
    		else:
    			self.PickUpFilterList[6].SetUp()		
    		#Stone
    		if systemSetting.IsPickUpFilterStone():
    			self.PickUpFilterList[7].Down()
    		else:
    			self.PickUpFilterList[7].SetUp()		
    		#Etc
    		if systemSetting.IsPickUpFilterEtc():
    			self.PickUpFilterList[8].Down()
    		else:
    			self.PickUpFilterList[8].SetUp()

    To:

    def RefreshPickupFilter(self):
    	checkFilterList = (
    		systemSetting.IsPickUpFilterWeapon(), systemSetting.IsPickUpFilterArmor(),
    		systemSetting.IsPickUpFilterEar(), systemSetting.IsPickUpFilterNeck(),
    		systemSetting.IsPickUpFilterFoots(), systemSetting.IsPickUpFilterShield(),
    		systemSetting.IsPickUpFilterBook(), systemSetting.IsPickUpFilterStone(),
    		systemSetting.IsPickUpFilterEtc()
    	)
    	
    	for child, flag in zip(self.PickUpFilterList, checkFilterList):
    		if flag:
    			child.Down()
    		else:
    			child.SetUp()

     

    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterWeapon"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterArmor"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterEar"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterNeck"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterFoots"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterShield"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterBook"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterStone"))
    			self.PickUpFilterList.append(GetObject("Pick_Up_FilterEtc"))

    To:

    for name in ('Weapon','Armor','Ear','Neck','Foots','Shield','Book','Stone','Etc'):
    	self.PickUpFilterList.append(GetObject("Pick_Up_Filter{}".format(name)))

     

    		self.PickUpFilterList[0].SetToggleUpEvent(self.__OnClickPickupFilterButtonWeapon) # Weapon
    		self.PickUpFilterList[0].SetToggleDownEvent(self.__OnClickPickupFilterButtonWeapon) # Weapon
    		self.PickUpFilterList[1].SetToggleUpEvent(self.__OnClickPickupFilterButtonArmor) # Armor
    		self.PickUpFilterList[1].SetToggleDownEvent(self.__OnClickPickupFilterButtonArmor) # Armor
    		self.PickUpFilterList[2].SetToggleUpEvent(self.__OnClickPickupFilterButtonEar) # Ear
    		self.PickUpFilterList[2].SetToggleDownEvent(self.__OnClickPickupFilterButtonEar) # Ear
    		self.PickUpFilterList[3].SetToggleUpEvent(self.__OnClickPickupFilterButtonNeck) # Neck
    		self.PickUpFilterList[3].SetToggleDownEvent(self.__OnClickPickupFilterButtonNeck) # Neck
    		self.PickUpFilterList[4].SetToggleUpEvent(self.__OnClickPickupFilterButtonFoots) # Foots
    		self.PickUpFilterList[4].SetToggleDownEvent(self.__OnClickPickupFilterButtonFoots) # Foots
    		self.PickUpFilterList[5].SetToggleUpEvent(self.__OnClickPickupFilterButtonShield) # Shield
    		self.PickUpFilterList[5].SetToggleDownEvent(self.__OnClickPickupFilterButtonShield) # Shield
    		self.PickUpFilterList[6].SetToggleUpEvent(self.__OnClickPickupFilterButtonBook) # Books
    		self.PickUpFilterList[6].SetToggleDownEvent(self.__OnClickPickupFilterButtonBook) # Books
    		self.PickUpFilterList[7].SetToggleUpEvent(self.__OnClickPickupFilterButtonStone) # Stone
    		self.PickUpFilterList[7].SetToggleDownEvent(self.__OnClickPickupFilterButtonStone) # Stone
    		self.PickUpFilterList[8].SetToggleUpEvent(self.__OnClickPickupFilterButtonEtc) # Etc
    		self.PickUpFilterList[8].SetToggleDownEvent(self.__OnClickPickupFilterButtonEtc) # Etc

    To:

    eventFuncList = (
    	self.__OnClickPickupFilterButtonWeapon, self.__OnClickPickupFilterButtonArmor, self.__OnClickPickupFilterButtonEar,
    	self.__OnClickPickupFilterButtonNeck, self.__OnClickPickupFilterButtonFoots, self.__OnClickPickupFilterButtonShield,
    	self.__OnClickPickupFilterButtonBook, self.__OnClickPickupFilterButtonStone, self.__OnClickPickupFilterButtonEtc
    )
    
    for child, event in zip(self.PickUpFilterList, eventFuncList):
    	child.SetToggleUpEvent(event)
    	child.SetToggleDownEvent(event)

     

    • Metin2 Dev 25
    • Not Good 2
    • Confused 1
    • Lmao 1
    • Good 8
    • Love 4
    • Love 42
  5. On 9/23/2019 at 10:29 PM, Rakancito said:
    
    		if (pkAttacker->IsRiding())
    		{
    			bool bAttacking = (get_dword_time() - pkAttacker->GetLastAttackTime()) < 800;
    			if (!bAttacking)
    				return BATTLE_NONE;
    		}
    		else
    		{
    			bool bAttacking = (get_dword_time() - pkAttacker->GetLastAttackTime()) < 750;
    			if (!bAttacking)
    				return BATTLE_NONE;
    		}

    Let's don't kill the source with dozens of useless lines and duplicated.

    		const bool bAttacking = (get_dword_time() - pkAttacker->GetLastAttackTime()) < pkAttacker->IsRiding() ? 800 : 700;
    		if (!bAttacking)
    			return BATTLE_NONE;

     

    • Love 3
  6. On 9/25/2019 at 1:50 AM, ManiacRobert said:
    Spoiler
    		void operator () (LPENTITY ent)
    		{
    			// 오브젝트가 아닌 것은 거리를 계산하여 거리가 멀면 추가하지 않는다.
    			if (!ent->IsType(ENTITY_OBJECT))
    				if (DISTANCE_APPROX(ent->GetX() - m_me->GetX(), ent->GetY() - m_me->GetY()) > dwViewRange)
    					return;
    
    #ifdef HIDDEN_OX
    			if (ent->IsType(ENTITY_CHARACTER) && m_me->IsType(ENTITY_CHARACTER))
    			{
    					LPCHARACTER chMe = (LPCHARACTER)m_me;
    					LPCHARACTER chEnt = (LPCHARACTER)ent;
    					if (chMe->IsPC() && chEnt->IsPC() && !chMe->IsGM() && !chEnt->IsGM() && chMe->GetMapIndex() == 113 && chEnt->GetMapIndex() == 113)
    						return;		
    			}
    #endif

     

     

    Since already is a check for distance, is impossible that the entity to be in another map, so is enough to check if you're in the map.

    This is the hidden content, please

    • Metin2 Dev 38
    • Dislove 1
    • Good 8
    • Love 2
    • Love 16
  7. 78b6b6f33109305b07a6aacdeb256c14.png
    Check if passed 10 seconds after the action for:

    • Safebox, exchange, shop, refine

    Check if the window is open:

    • Exchange, shop, private shop, safebox, cube

    How-To-Use: (already a lot of metin2 quests using this)

    Spoiler
    
    when 50513.use begin
    	if not pc.can_warp() then
    		syschat("Wait 10 seconds, you can't make this right now.")
    		return
    	end
    	-----
    end

     

    • Love 1
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.