Jump to content
  • 0
Sign in to follow this  
DarkWolf

mysql_query check problem

Question

Hi, i'm trying to create a quest where the player name is registered and checked if the name is already on the DB, but i'm getting a problem when the quest makes the check it return itself and don't registe the player name and doesn't show the massage: "The player was registered successfully!"

Can someone help me pls.

quest P_registration begin
    state start begin
		when GM_helper.chat."Palyer registration" begin
			say_title("GM helper")
			say("")
			say("Do you want register a player?")
			say("")
			local s = select("Yes", "No") 
			if s == 1 then
				say_title(""..mob_name(npc.get_race).."")
				say("")
				say("Write the player name:")
				say("")
				local playername = input ()
				if (playername == "" or playername == nil) then 
					say_title(""..mob_name(npc.get_race).."")
					say("")
					say("Not written the player name.")
					say("")
					return 
				end
				local namecheck = mysql_query("SELECT player_name FROM player.event_test WHERE player_name='"..playername.."'")
				if namecheck.player_name[1] == playername then
					say_title(""..mob_name(npc.get_race).."")
					say("")
					say("The player is already registered.")
					say("Please, insert a new name.")
					say("")
					return
				else 
					mysql_query("INSERT player.event_test SET player_name='"..playername.."'")
					say_title(""..mob_name(npc.get_race).."")
					say("")
					say("The player was registered successfully!")
					say("")
					return
				end
			else
				return
			end
		end
	end
end

Best regards,

 

DarkWolf

Share this post


Link to post

8 answers to this question

Recommended Posts

  • 0

Try this, maybe it will works:

quest P_registration begin
    state start begin
        when GM_helper.chat."Player registration" begin
            say_title("GM helper")
            say("")
            say("Do you want register a player?")
            say("")
            local s = select("Yes", "No") 
            if s == 1 then
                say_title(""..mob_name(npc.get_race).."")
                say("")
                say("Write the player name:")
                say("")
                local playername = input ()
                if (playername == "" or playername == nil) then
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("Not written the player name.")
                    say("")
                    return
                end
                local namecheck = mysql_query("SELECT name from event_test WHERE player_name = '".. playername .."'")
                if table.getn(namecheck) > 0 then
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("The player is already registered.")
                    say("Please, insert a new name.")
                    say("")
                    return
                else
					mysql_query("INSERT INTO event_test SET player_name='".. playername .."'")
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("The player was registered successfully!")
                    say("")
                    return
                end
            else
                return
            end
        end
    end
end
  • Love 2

Share this post


Link to post
  • 0
if(tostring(namecheck.player_name[1]) == tostring(playername)) then

try with this.

 

Regards.

  • Love 1

Share this post


Link to post
  • 0

You don't need to cast it to a string.

Which mysql query function do you use?

Share this post


Link to post
  • 0
if(tostring(namecheck.player_name[1]) == tostring(playername)) then

try with this.

 

Regards.

 

 

still doing the same. :(

Share this post


Link to post
  • 0

Which you're using mysql_query function please paste here. 

 

Regards.

Share this post


Link to post
  • 0

Which you're using mysql_query function please paste here. 

 

Regards.

 

 

You don't need to cast it to a string.

Which mysql query function do you use?

mysql_query = function(query) 
    local rt = io.open('CONFIG','r'):read('*all') 
    local pre= string.gsub(rt,'.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+)%s(%S+).+','-h%1 -u%2 -p%3 -D%4') 
    math.randomseed(os.time()) 
    local fi,t,out = 'mysql_data_'..math.random(10^9)+math.random(2^4,2^10),{},{} 
    os.execute('mysql '..pre..' --e='..string.format('%q',query)..' > '..fi)   
    for av in io.open(fi,'r'):lines() do table.insert(t,split(av,'t')) end; os.remove(fi); 
    for i = 2, table.getn(t) do table.foreach(t[i],function(a, 
        out[i-1]        = out[i-1] or {} 
        out[i-1][a]        = b 
        out[t[1][a]]    = out[t[1][a]] or {} 
        out[t[1][a]][i-1]    = b 
    end) end 
    return out 
end

mysql_query by Mijago

Share this post


Link to post
  • 0

 

Try this, maybe it will works:

quest P_registration begin
    state start begin
        when GM_helper.chat."Player registration" begin
            say_title("GM helper")
            say("")
            say("Do you want register a player?")
            say("")
            local s = select("Yes", "No") 
            if s == 1 then
                say_title(""..mob_name(npc.get_race).."")
                say("")
                say("Write the player name:")
                say("")
                local playername = input ()
                if (playername == "" or playername == nil) then
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("Not written the player name.")
                    say("")
                    return
                end
                local namecheck = mysql_query("SELECT name from event_test WHERE player_name = '".. playername .."'")
                if table.getn(namecheck) > 0 then
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("The player is already registered.")
                    say("Please, insert a new name.")
                    say("")
                    return
                else
					mysql_query("INSERT INTO event_test SET player_name='".. playername .."'")
                    say_title(""..mob_name(npc.get_race).."")
                    say("")
                    say("The player was registered successfully!")
                    say("")
                    return
                end
            else
                return
            end
        end
    end
end

 

IT WORKS!!! OMG THANK YOU SO MUCH!!! :)

Share this post


Link to post
  • 0

IT WORKS!!! OMG THANK YOU SO MUCH!!! :)

 

You're welcome :)

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.