What's new
What's new

New messages New topics Systems Serverfiles 3D Models Web Scripting

Metin2Resources

👋 Welcome to Metin2 Resources — your hub for professional Metin2 server development.

Create a free account to access advanced systems, serverfiles, tutorials and connect with other developers.

🚀 Join today and start building better.

[Py] PM with Patch Notes (Tutorial)

RESOURCES HUB

Premium
📜 Messages 299
👍 Reactions 2,196
🏆 Points 425
🌐 Website metin2global.to
Add a little "system" on your Metin2 server, when you make an update -> players get a PM (Whisper) with what changes have been made to the server.

It is written only in python + LUA (quest), very simple to implement by anyone!
- All players will receive this Private Message when they connect to the server.
- It appears only once, so players will not receive this message every time they log in, only the first time.
x1k1iKJ.gif


We open game.py and search for:
Code:
"mall"
We add:
Code:
"open_notice_info"        : self.__open_notice_info,
"write_notice_info"        : self.__write_notice_info,
We are looking for:
Code:
__InGameShop_Show(self,url):
We add:
Code:
def __open_notice_info(self):
    self.interface.RegisterGameMasterName("<--System-->")
    self.interface.RecvWhisper("<--System-->")
        
def __write_notice_info(self,text):
    chat.AppendWhisper(chat.WHISPER_TYPE_CHAT, "<--System-->", text.replace("_", " "))
This is what it should look like:

file.php

Install the next quest:
Code:
quest reizo_notice begin
    state start begin
        function read_notice_line(l)
            return readline("/quest/notice/notice.txt", l)
        end
        
        when login begin
            local qf = readline("/quest/notice/qf.txt", 1)
            local lineas = 0
            if tonumber(qf) > pc.getqf("reizo_notice") then
                for line in io.lines("/quest/notice/notice.txt") do lineas = lineas + 1 end
                cmdchat("open_notice_info")
                for i = 1,lineas do
                    cmdchat("write_notice_info "..string.gsub(reizo_notice.read_notice_line(i), ' ', '_'))
                end
                pc.setqf("reizo_notice", qf)
            end
        end
    end
end
Now, we create a folder in the "quest" folder called "notice" and add 2 txt with the names: notice.txt and qf.txt.

In qf.txt you will have to put a number for example 0 we add a 0 and hit save, and in notice we put what we want to appear in pm.

In case we don't have the readline function we add:
Code:
function readline(path, x)
    local linetable = {}
    for line in io.lines(path) do
        table.insert(linetable, line)
    end
    return linetable[x]
end
We add the following to quest_functions:
Code:
readline
io.lines
How do I add a new message?
1) Open notice.txt from the notice fodler, and add the message that you want to appear in PM to players.
2) Open qf.txt and change the number there +1. That is if we have 0, we change it to 1.

Now, the message will appear to the players at first login.

If we did another update, we do the same. We change the message in notice.txt and change in qf.txt from 1 --> to 2.
Now the new message will appear again to players at first login.
 

Latest posts

Back
Top Bottom