Jump to content

Recommended Posts

Hi. How to use that function in quest? I tried but i always have error in quest compile

 

function pc.make_guild(guild_name, required_money, required_level)
        --[[to clean non alphanumeric characters]]
        local guild_name = string.gsub(guild_name, "[^A-Za-z0-9]", "")
        local guild_len_name = string.len(guild_name)
        --[[to check wrong sized names]]
        if not ((2 < guild_len_name) and (guild_len_name < 12)) then
            say_reward("The name should not have special characters and its length should be between 3-11 characters!")
            return
        end
        --[[to check required level]]
        if not (pc.get_level() >= required_level) then
            say_reward(string.format("Level too low. Needed: %d", required_level))
            return false
        end
        --[[to check required money]]
        if not (pc.get_gold() >= required_money) then
            say_reward(string.format("Not enough money. Needed: %d", required_money))
            return false
        end
        --[[to check already guilded people]]
        if (pc.hasguild() or pc.isguildmaster()) then
            say_reward("You're already inside a guild.")
            return
        end
        --[[to add a user-validation check]]
        say(string.format("Are you sure you wanna create such guild?[ENTER]%s", guild_name))
        if select("Yes", "No")==2 then
            return false
        end
        --[[create the guild and process the return value]]
        local ret = pc.make_guild0(guild_name)
        if ret==-2 then
            say_reward("[NO] guild name is invalid (strlen <2 or >11!)")
        elseif ret==-1 then
            say_reward("[NO] guild name is invalid (special chars found!)")
        elseif ret==0 then
            say_reward("[NO] guild not created (guild name already present or already member of a guild)")
        elseif ret==1 then
            pc.change_gold(-required_money)
            say_reward("[YES] guild created")
            return true
        elseif ret==2 then
            say_reward("[NO] player already part of a guild")
        elseif ret==3 then
            say_reward("[NO] player already guild master")
        end
        return false
    end

 

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

16 minut temu, ragem0re napisał:

then post your error..

Ahh sorry, im stupid

 

Error 
QUEST : new_guild
STATE : start
guild/new_guild.quest:3:assertion failure : t.token == '('
Abort (core dumped)

 

Quest

quest new_guild begin
	state start begin
		function pc.make_guild(guild_name, required_money, required_level)
			--[[to clean non alphanumeric characters]]
			local guild_name = string.gsub(guild_name, "[^A-Za-z0-9]", "")
			local guild_len_name = string.len(guild_name)
			--[[to check wrong sized names]]
			if not ((2 < guild_len_name) and (guild_len_name < 12)) then
				say_reward("The name should not have special characters and its length should be between 3-11 characters!")
				return
			end
			--[[to check required level]]
			if not (pc.get_level() >= required_level) then
				say_reward(string.format("Level too low. Needed: %d", required_level))
				return false
			end
			--[[to check required money]]
			if not (pc.get_gold() >= required_money) then
				say_reward(string.format("Not enough money. Needed: %d", required_money))
				return false
			end
			--[[to check already guilded people]]
			if (pc.hasguild() or pc.isguildmaster()) then
				say_reward("You're already inside a guild.")
				return
			end
			--[[to add a user-validation check]]
			say(string.format("Are you sure you wanna create such guild?[ENTER]%s", guild_name))
			if select("Yes", "No")==2 then
				return false
			end
			--[[create the guild and process the return value]]
			local ret = pc.make_guild0(guild_name)
			if ret==-2 then
				say_reward("[NO] guild name is invalid (strlen <2 or >11!)")
			elseif ret==-1 then
				say_reward("[NO] guild name is invalid (special chars found!)")
			elseif ret==0 then
				say_reward("[NO] guild not created (guild name already present or already member of a guild)")
			elseif ret==1 then
				pc.change_gold(-required_money)
				say_reward("[YES] guild created")
				return true
			elseif ret==2 then
				say_reward("[NO] player already part of a guild")
			elseif ret==3 then
				say_reward("[NO] player already guild master")
			end
			return false
		end
		when 20016.chat."new guild" begin
			local guild_name = input()
			local required_money = 5435
			local required_level = 75
			new_guild.pc.make_guild(guild_name, required_money, required_level)
		end
	end
end
		

Link to comment
Share on other sites

  • Bot
7 minutes ago, ragem0re said:

this seems wrong for me.

i don't know about lua functions :ph34r:

It seems wrong, but works fine. For example if you write:

int x = 7 + 4; in other languages, while running the programm will first add 7+4 and then initialize the sum of it: 11 to the variable x.

The same is done in this case I guess. It replaces the given variable with a pattern, so anything else than A-Z, a-z and 0-9 will be replaced with "" and then initializes this "sum" to the local variable guild_name, wich he can use in the further function.

 

King Regards

Cyber

english_banner.gif

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



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