Jump to content
  • 0
Sign in to follow this  
Rumor

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

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.

Share this post


Link to post

9 answers to this question

Recommended Posts

  • 0
function isLongName(name)
	return string.len(name) < 16
end

local readMe = input()
if(isLongName(tostring(readMe)) == false) then
	print("Your name is very long !...")
else
	print("Your name is not very long.. ")
end

Regards.

  • Love 1

Share this post


Link to post
  • 0

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

Share this post


Link to post
  • 0

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?

Share this post


Link to post
  • 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

Share this post


Link to post
  • 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

Share this post


Link to post
  • 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.

Share this post


Link to post
  • 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?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
  • Recently Browsing   0 members

    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.