Jump to content

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


Recommended Posts

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

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

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

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

  • Developer

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Similar Content

  • Activity

    1. 24

      Experimental Renderer

    2. 11

      Multi Language System

    3. 0

      [FREE DESIGN] Interface + Logo + Discord Banner and Avatar

    4. 4

      Feeding game source to LLM

    5. 0

      Quest 6/7 Problem

    6. 5

      Effect weapons

    7. 0

      [C++] Fix Core Downer Using Negative Number in GM Codes

    8. 3

      Crystal Metinstone

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • 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.