Jump to content

[ pc.setqf ] from input ?


Go to solution Solved by Syreldar,

Recommended Posts

hi dev's

i asked how can i  block a player from entering a map by using   pc.setqf  and pc.getqf

by give him a pc.setqf  from input

ex :

i will use that check in quest

 

    if pc.getqf("cannot_enter") == 1 then
        say(" u can't enter the map ")
    else
        pc.warp( 947100 , 169800 )
    end

now i want to give a player ( not me ) a ( pc.setqf ) from input by typing his name

 

quest test begin
	state start begin
		when 10581.chat." Block Player " with pc.is_gm() begin
			say_event_title(mob_name(10581))
			say()
			say(" type the name of the player which u want to block here  ")
			local name = input();	
			
			---------------------------- Error 404 ): ----------------------------------

			-- How can i set a
			pc.setqf("cannot_enter", 1)
			-- for the name from input ?
			
		end
	end
end

 

 

Edited by Ropen
add some thing
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Premium
  • Solution
quest test begin
	state start begin
		when 10581.chat."Block Player" with pc.is_gm() begin
			say_event_title(string.format("%s:[ENTER]", mob_name(10581)))
			say("Type the name of the player whom you want to")
			say("lock out of accessing this map.[ENTER]")
			local player_name = input();
			-- yield
			say_event_title(string.format("%s:[ENTER]", mob_name(10581)))
			local player_vid = find_pc_by_name(player_name);
			if (player_vid == 0) then
  				return say_reward(string.format("The player `%s` is offline or in another core.", player_name));
  			end -- if

  			local old_vid = pc.select(player_vid, player_vid);
  			pc.setf("map_control", "cannot_enter", 1);
			pc.select(old_vid, old_vid);
			say("Operation complete.[ENTER]")
		end -- when
	end -- state
end -- quest

 

The quest is limited due to the fact that if the player is offline or in a separate core you won't be able to reach out to him to assign the flag.

This can be solved via query, i'll give you a rough example of the code using @ martysama0134's mysql_direct_query function, you can find it here paired with other useful functions: https://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/3327940-release-mysql_direct_query-get_table_postfix-mysql_escape_string-written-c-lua.html

Keep in mind that this code works but you'll still have to properly escape the string on the input in order to avoid possible sqli.

local results, ret = mysql_direct_query(string.format("SELECT `id` FROM `player`.`player` WHERE `name` = '%s' LIMIT 1;", player_name));
if (results > 0) then
	mysql_direct_query(string.format("INSERT INTO `player`.`quest`(`dwPID`, `szName`, `szState`, `lValue`) VALUES (%d, 'map_control', 'cannot_enter', 1) ON DUPLICATE KEY UPDATE `lValue` = 1;", ret[1].id))
else
	say_reward(string.format("The player `%s` was not found.[ENTER]", player_name))
end -- if/else
Edited by Syreldar

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

  • Premium
11 minutes ago, Ropen said:

so if i want to check i will use

pc.getf ?

Yes

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

 

if i used  mysql_direct_query like that

local name = input();
mysql_direct_query("UPDATE player.player SET block_map = '1' WHERE name = "..name..""); 

 

could i use mysql_direct_query to get block_map value ? and relying on it block the player like that ?

local myname = pc.get_name() ;
local results, ret = mysql_direct_query(string.format("SELECT `block_map` FROM `player`.`player` WHERE `name` = '%s' LIMIT 1;", myname));
			
if (results > 0) then
	say ("u can't enter")
else
	pc.warp( 947100 , 169800 )
end -- if/else

Is it an effective method ? or will there be problems ?

Edited by Ropen
Link to comment
Share on other sites

  • Premium
3 hours ago, Ropen said:

 

if i used  mysql_direct_query like that

local name = input();
mysql_direct_query("UPDATE player.player SET block_map = '1' WHERE name = "..name..""); 

 

could i use mysql_direct_query to get block_map value ? and relying on it block the player like that ?

local myname = pc.get_name() ;
local results, ret = mysql_direct_query(string.format("SELECT `block_map` FROM `player`.`player` WHERE `name` = '%s' LIMIT 1;", myname));
			
if (results > 0) then
	say ("u can't enter")
else
	pc.warp( 947100 , 169800 )
end -- if/else

Is it an effective method ? or will there be problems ?

Why? You check with the flag still no reason to use a query to check it.

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

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.