Jump to content

HowTo | Old Quest Client Communication


Recommended Posts

Hello,

I want to show you a new guide to make a communication between quest and client. Nowdays we can use game source..bla bla... but if you don't want/don't know how to compyle it, you can use this version (old and good :D). So, let's begin:

### Send informations to client

Spoiler

For quest, we have a command... very simple to use and known by everybody(i guess, haha).


quest communication_test begin -- QUEST NAME MUST BE communication_test.quest !!!	
	state start begin		
		when login begin			
			local number = 5			
			cmdchat("command_name " .. number ) -- So, we'll find 'command_name' in client, in game.py. This is very important, so use a good name...Check if it doesn't exist		
		end	
	end
end

For client we have to add in game.py this:

Look for:


def __ServerCommand_Build(self):		serverCommandList={

Add under this:


"command_name"                            : self.command_name_python,


Now we must create the function in python with name command_name_python or everything you used..
182929TRi3e.jpg.e2aefa098798c5ff6e6f8298

Be careful! You must align text(functions..etc) with TAB key space.



### Start a quest from client (for buttons sometimes...)

Spoiler

The quest looks like this:
 


quest communication_test begin -- QUEST NAME MUST BE communication_test.quest !!!	
	state start begin		
		when login begin			
			cmdchat("quest_name_index "..q.getcurrentquestindex()) --- this command send quest index to client, you'll see now why is important		
		end		
		
		when button or info begin			
			say("Zetsu: It works! Quest is active.")		
		end	
	end
end

For client we have to add in game.py this:

Look for:


def __ServerCommand_Build(self):		serverCommandList={

Add under this:


"quest_name_index"                            : self.YOuCanUseAnyName,

Now, create a function which must looks like:


	def YOuCanUseAnyName(self, questindex):
		constInfo.QUESTNAMEINDEX = questindex # you can use int(questindex) but in special cases



Before the most important thing, we must open constInfo.py and add:


QUESTNAMEINDEX = 0

Without any space in front!

Now, everywhere in python you can use this function:


    def FunctionName(self):
        import event
        import constInfo
        event.QuestButtonClick(int(constInfo.QUESTNAMEINDEX))



Especially for buttons...But you can use it anyway. Don't make this function to be started by quest, cause you will get a "loop", so quest will be actived for infinite times(now it depends how did you code it).



### Get a variable from client (now for 34 & 40k update)

Spoiler

This trick is very important and you must read all the steps carefuly

Quest looks like:


quest communication_test begin -- QUEST NAME MUST BE communication_test.quest !!!	
	state start begin		
		when login begin			
			cmdchat("quest_name_index "..q.getcurrentquestindex())		
		end		
		
		function GetFromClient()			
			cmdchat("init_getInfo")			
			local variables = input(cmdchat("getInfo")) 			
			cmdchat("ignore_getInfo")			
			return variables		
		end		
		
		when button or info begin			
			local things = communication_test.GetFromClient()			
			say(things) -- you can convert it with tonumber("") tostring(0)		
		end	
	end
end

For client we have to add in game.py this:

Look for:


def __ServerCommand_Build(self):		serverCommandList={

Add under this:


"init_getInfo"                            : self.InitTutorialGetInfo,
"getInfo"                            : self.GetInfoTutByZetsu,
"ignore_getInfo"                            : self.IgnoreTutorialGetInfo,

We should start with constInfo. Add these cariables:


IGNORE_GETINFO = 0INFORMATION_TO_SEND = "m2dev-tutByZetsu"

Now, we move to interfacemodule.py

##########################  For 34k+ versions you have: ########


    def OpenQuestWindow(self, skin, idx):
        wnds = ()
            
        q = uiQuest.QuestDialog(skin, idx)
        q.SetWindowName("QuestWindow" + str(idx))
        q.Show()
        if skin:
            q.Lock()
            wnds = self.__HideWindows()
        
            # UNKNOWN_UPDATE
            q.AddOnDoneEvent(lambda tmp_self, args=wnds: self.__ShowWindows(args))
            # END_OF_UNKNOWN_UPDATE
        
        if skin:
            q.AddOnCloseEvent(q.Unlock)
                
        q.AddOnCloseEvent(lambda s = self, qw = q: s.__dict__.__getitem__("wndQuestWindow").remove(qw))
        
        # UNKNOWN_UPDATE
        self.wndQuestWindow.append(q)
        # END_OF_UNKNOWN_UPDATE

Replace it with:
 


    def OpenQuestWindow(self, skin, idx):
        chat.AppendChat(chat.CHAT_TYPE_INFO, str(constInfo.WOD_IGNORE))
        if constInfo.IGNORE_GETINFO == 1: # You see :D constInfo variable which stop/start quest window
            return
        else:   
            wnds = ()
            
            q = uiQuest.QuestDialog(skin, idx)
            q.SetWindowName("QuestWindow" + str(idx))
            q.Show()
            if skin:
                q.Lock()
                wnds = self.__HideWindows()
        
                # UNKNOWN_UPDATE
                q.AddOnDoneEvent(lambda tmp_self, args=wnds: self.__ShowWindows(args))
                # END_OF_UNKNOWN_UPDATE
        
            if skin:
                q.AddOnCloseEvent(q.Unlock)
                
            q.AddOnCloseEvent(lambda s = self, qw = q: s.__dict__.__getitem__("wndQuestWindow").remove(qw))
        
            # UNKNOWN_UPDATE
            self.wndQuestWindow.append(q)
            # END_OF_UNKNOWN_UPDATE

 

#########################For lower versions: ########
-Open uiquest.py
search:


def __init__(self,skin,idx):

Under this add:
 

 


        import constInfo    
        if constInfo.IGNORE_GETINFO == 1:
            return


######################### Lower Version steps end ########

 

And finally for game.py we have to create these functions:


    def InitTutorialGetInfo(self):
        constInfo.IGNORE_GETINFO = 1
    def IgnoreTutorialGetInfo(self):
        constInfo.IGNORE_GETINFO = 0
    def GetInfoTutByZetsu(self):
        #import net # if you work out of game.py (so delete first # if your script doesn't contain "import net")
        net.SendQuestInputStringPacket(str(constInfo.INFORMATION_TO_SEND)) # or any information/variable from any module/file



If you add functions at the end of the game.py don't forget that any PY file have the last line empty!

 

### Send multiple informations to client once

Spoiler

The same as we have done at "Send informations to client" but you will use this:


local var1 = 32
local var2 = "zts"
local var3 = "m2dev"
cmdchat("function_name "..var1.."|"..var2.."|"..var3) 

In the client, the same function,but to get variables you will use something like this:


vararray= fromserver.split("|") # fromserver will be "32|zts|m2dev"
#for var1:
constInfo.VAR_1 = vararray[0]
#for var2:
constInfo.VAR_2 = vararray[1]
#and for var3:
constInfo.VAR_3 = vararray[2]



Kind regards and i hope you understood me! Sorry for mistakes.

  • Metin2 Dev 2
  • Love 17
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 2 months later...
  • 7 months later...
  • 2 months later...
  • 4 years later...

Announcements



×
×
  • 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.