Jump to content
×
×
  • Create New...
  • 0

How can I restrict name length of players? (34083)


Rumor

Question

quest change_name_item begin
	state start begin
		when 71055.use begin
			say_title("Change of Name List")
			if pc.is_married() then
				say("")
				say("You can't change names when you're married.")
				say("")
				return
			elseif pc.is_polymorphed() then
				say("")
				say("You can't change names when you're transformed.")
				say("")
				return
			elseif pc.has_guild() then
				say("")
				say("You can't change names when you're in a guild.")
				say("")
				return
			elseif party.is_party() then
				say("")
				say("You can't change names when you're in a party.")
				say("")
				return
			elseif pc.get_level() < 80 then
				say("")
				say("You can't change names before level 80.")
				say("")
				return
			elseif get_time() < pc.getqf("next_time") then
				say("")
				say("You've recently changed your name.")
				say("You can't change your name right now.")
				say("")
				return
			end
			say("Please enter the name you want.")
			local name = pc.name
			local str = input()
			local ret = pc.change_name(str)
			say_title("Change of Name List")
			if ret == 0 then
			say("")
				say("You have not relogged since the last time you")
				say("changed your name. Please relog now.")
				say("")
				char_log(0, "CHANGE_NAME", "HAVE NOT RE-LOGIN")
			elseif ret == 1 then
				say("")
				say("There was a problem. Please try again.")
				say("")
				char_log(0, "CHANGE_NAME", "ITEM USE PROBLEM")
			elseif ret == 2 then
				say("")
				say("This name is not available.")
				say("Please select another name.")
				say("")
				char_log(0, "CHANGE_NAME", "CAN NOT USE NAME")
			elseif ret == 3 then
				say("")
				say("This name is not available.")
				say("Please select another name.")
				say("")
				char_log(0, "CHANGE_NAME", "ALREADY USING NAME")
			elseif ret == 4 then
				say("")
				say("Successful name change!")
				say("You cannot change your name again for")
				say("another 24 hours.")
				say("")
				pc.remove_item("71055", 1)
				pc.setqf("next_time", get_time() + time_hour_to_sec(24*1))
				horse.set_name(""..str"'s Horse")
				char_log(0, "CHANGE_NAME", "SUCCESS: from "..name.." to "..str)
				wait()
				pc.warp(pc.get_x()*100, pc.get_y()*100)
			else
				say("")
				say("Unknown error.")
				say("Please notify Rumor with this number:")
				say(ret)
				say("and he will take a look at the issue.")
				say("")
				char_log(0, "CHANGE_NAME", "UNKNOWN NAME")
			end
		end
	end
end

The players are choosing very long names which can't be typed in a private message window or fully seen on their character. I need to be able to limit their name length somehow.

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0
  • Moon

so I would add the function and local then add the rest with an elseif statement somewhere after line 47 right?

quest change_name_item begin
    state start begin
		function isLongName(name)
			return string.len(name) < 16
		end
        when 71055.use begin
            say_title("Change of Name List")
            if pc.is_married() then
                say("")
                say("You can't change names when you're married.")
                say("")
                return
            elseif pc.is_polymorphed() then
                say("")
                say("You can't change names when you're transformed.")
                say("")
                return
            elseif pc.has_guild() then
                say("")
                say("You can't change names when you're in a guild.")
                say("")
                return
            elseif party.is_party() then
                say("")
                say("You can't change names when you're in a party.")
                say("")
                return
            elseif pc.get_level() < 80 then
                say("")
                say("You can't change names before level 80.")
                say("")
                return
            elseif get_time() < pc.getqf("next_time") then
                say("")
                say("You've recently changed your name.")
                say("You can't change your name right now.")
                say("")
                return
            end
            say("Please enter the name you want.")
            local name = pc.name
            local str = input()
			if(change_name_item.isLongName(tostring(str)) == false) then
				say_title("Error 1")
				say("")
				---
				say("I'm sorry but your name very long")
				say("and you don't do this. ")
				return
			end
            local ret = pc.change_name(str)
            say_title("Change of Name List")
            if ret == 0 then
            say("")
                say("You have not relogged since the last time you")
                say("changed your name. Please relog now.")
                say("")
                char_log(0, "CHANGE_NAME", "HAVE NOT RE-LOGIN")
            elseif ret == 1 then
                say("")
                say("There was a problem. Please try again.")
                say("")
                char_log(0, "CHANGE_NAME", "ITEM USE PROBLEM")
            elseif ret == 2 then
                say("")
                say("This name is not available.")
                say("Please select another name.")
                say("")
                char_log(0, "CHANGE_NAME", "CAN NOT USE NAME")
            elseif ret == 3 then
                say("")
                say("This name is not available.")
                say("Please select another name.")
                say("")
                char_log(0, "CHANGE_NAME", "ALREADY USING NAME")
            elseif ret == 4 then
                say("")
                say("Successful name change!")
                say("You cannot change your name again for")
                say("another 24 hours.")
                say("")
                pc.remove_item("71055", 1)
                pc.setqf("next_time", get_time() + time_hour_to_sec(24*1))
                horse.set_name(""..str"'s Horse")
                char_log(0, "CHANGE_NAME", "SUCCESS: from "..name.." to "..str)
                wait()
                pc.warp(pc.get_x()*100, pc.get_y()*100)
            else
                say("")
                say("Unknown error.")
                say("Please notify Rumor with this number:")
                say(ret)
                say("and he will take a look at the issue.")
                say("")
                char_log(0, "CHANGE_NAME", "UNKNOWN NAME")
            end
        end
    end
end

Like this?

Plain logic saves lives.

Link to comment
Share on other sites

  • 0

oh I was going to do it this way:

quest change_name_item begin
	state start begin
		when 71055.use begin
			say_title("Change of Name List")
			if pc.is_married() then
				say("")
				say("You can't change names when you're married.")
				say("")
				return
			elseif pc.is_polymorphed() then
				say("")
				say("You can't change names when you're transformed.")
				say("")
				return
			elseif pc.has_guild() then
				say("")
				say("You can't change names when you're in a guild.")
				say("")
				return
			elseif party.is_party() then
				say("")
				say("You can't change names when you're in a party.")
				say("")
				return
			elseif pc.get_level() < 80 then
				say("")
				say("You can't change names before level 80.")
				say("")
				return
			elseif get_time() < pc.getqf("next_time") then
				say("")
				say("You've recently changed your name.")
				say("You can't change your name right now.")
				say("")
				return
			end
			say("Please enter the name you want.")
				function isLongName(name)
					return string.len(name) < 16
				end
			local name = pc.name
			local length = input()
			local str = input()
			local ret = pc.change_name(str)
			say_title("Change of Name List")
			if ret == 0 then
			say("")
				say("You have not relogged since the last time you")
				say("changed your name. Please relog now.")
				say("")
				char_log(0, "CHANGE_NAME", "HAVE NOT RE-LOGIN")
			elseif ret == 1 then
				say("")
				say("There was a problem. Please try again.")
				say("")
				char_log(0, "CHANGE_NAME", "ITEM USE PROBLEM")
			elseif ret == 2 then
				say("")
				say("This name is not available.")
				say("Please select another name.")
				say("")
				char_log(0, "CHANGE_NAME", "CAN NOT USE NAME")
			elseif ret == 3 then
				say("")
				say("This name is not available.")
				say("Please select another name.")
				say("")
				char_log(0, "CHANGE_NAME", "ALREADY USING NAME")
			elseif(isLongName(tostring(length)) == false) then
				say("")
				say("Your name is too long.")
				say("Please select another.")
				say("")
				char_log(0, "CHANGE_NAME", "NAME TOO LONG")
			elseif ret == 4 then
				say("")
				say("Successful name change!")
				say("You cannot change your name again for")
				say("another 24 hours.")
				say("")
				pc.remove_item("71055", 1)
				pc.setqf("next_time", get_time() + time_hour_to_sec(24*1))
				horse.set_name(""..str"'s Horse")
				char_log(0, "CHANGE_NAME", "SUCCESS: from "..name.." to "..str)
				wait()
				pc.warp(pc.get_x()*100, pc.get_y()*100)
			else
				say("")
				say("Unknown error.")
				say("Please notify Rumor with this number:")
				say(ret)
				say("and he will take a look at the issue.")
				say("")
				char_log(0, "CHANGE_NAME", "UNKNOWN NAME")
			end
		end
	end
end

Link to comment
Share on other sites

  • 0

I've got this now

quest change_name_item begin
    state start begin
        function isLongName(name)
            return string.len(name) < 16
        end
        when 71055.use begin
            say_title("Change of Name List")
            if pc.is_married() then
                say("")
                say("You can't change names when you're married.")
                say("")
                return
            elseif pc.is_polymorphed() then
                say("")
                say("You can't change names when you're transformed.")
                say("")
                return
            elseif pc.has_guild() then
                say("")
                say("You can't change names when you're in a guild.")
                say("")
                return
            elseif party.is_party() then
                say("")
                say("You can't change names when you're in a party.")
                say("")
                return
            elseif pc.get_level() < 80 then
                say("")
                say("You can't change names before level 80.")
                say("")
                return
            elseif get_time() < pc.getqf("next_time") then
                say("")
                say("You've recently changed your name.")
                say("You can't change your name right now.")
                say("")
                return
            end
            say("Please enter the name you want.")
            local name = pc.name
            local str = input()
            if(change_name_item.isLongName(tostring(str)) == false) then
                say_title("Change of Name List")
                say("")
                say("The entered name is too long.")
                say("Please select another name.")
				say("")
				char_log(0, "CHANGE_NAME", "NAME TOO LONG")
                return
            end
            local ret = pc.change_name(str)
            say_title("Change of Name List")
            if ret == 0 then
            say("")
                say("You have not relogged since the last time you")
                say("changed your name. Please relog now.")
                say("")
                char_log(0, "CHANGE_NAME", "HAVE NOT RE-LOGIN")
            elseif ret == 1 then
                say("")
                say("There was a problem. Please try again.")
                say("")
                char_log(0, "CHANGE_NAME", "ITEM USE PROBLEM")
            elseif ret == 2 then
                say("")
                say("This name is not avaliable.")
                say("Please select another name.")
                say("")
                char_log(0, "CHANGE_NAME", "CAN NOT USE NAME")
            elseif ret == 3 then
                say("")
                say("This name is not avaliable.")
                say("Please select another name.")
                say("")
                char_log(0, "CHANGE_NAME", "ALREADY USING NAME")
            elseif ret == 4 then
                say("")
                say("Successful name change!")
                say("You cannot change your name again for")
                say("another 24 hours.")
                say("")
                pc.remove_item("71055", 1)
                pc.setqf("next_time", get_time() + time_hour_to_sec(24*1))
                horse.set_name(""..str"'s Horse")
                char_log(0, "CHANGE_NAME", "SUCCESS: from "..name.." to "..str)
                wait()
                pc.warp(pc.get_x()*100, pc.get_y()*100)
            else
                say("")
                say("Unknown error.")
                say("Please notify Rumor with this number:")
                say(ret)
                say("and he will take a look at the issue.")
                say("")
                char_log(0, "CHANGE_NAME", "UNKNOWN NAME")
            end
        end
    end
end

Link to comment
Share on other sites

  • 0

When you create a function in a questfile, you always have to use it like: quest_name.function_name, otherwise the game will try to find that function, in questlib or in game core. And it'll return nil because that function doesn't exists.

All you needed was adding string.len(str) < 16.

when you return 0 and server doesn't boot:

unknown.png

Link to comment
Share on other sites

  • 0

When you create a function in a questfile, you always have to use it like: quest_name.function_name, otherwise the game will try to find that function, in questlib or in game core.

All you needed was adding string.len(str) < 16.

Yeah I know that about functions, I just didn't know how to add this limitation to the scroll. The latest quest I posted should work fine, right?

Link to comment
Share on other sites

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Metin2 Dev Github
  • Activity

    1. 0

      max level exp

    2. 8

      Quest States Core Crash Item Dupe Bug Fix

    3. 23

      Umbra / Soft4Win / SNap! scammer exposed!

    4. 46

      Ship Defense (Hydra Dungeon)

    5. 10

      Rodnia Glory | A REAL SPEED SERVER | Start 02.09.2022

    6. 0

      Avery seeks an experienced team manager

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.