mkhzaleh 131 Report post Posted March 6, 2019 (edited) Helo!~ i was trying to make this as card , seems work but how we can make a check if the name is exist or not? for example local String = "if NOT EXISTS (SELECT * from "..SQL.GameDB.Name..".dbo.guild where guild_name = '"..name.."'" this what i have done ---the sql Query function GuildChangeName(role,name1,name2)--new name / old name name1 = string.lower(name1) local length = string.len(name1) if ((length < 5) or (length > 16)) then PopupNotice(role, "The length of the Guild's name must be from 5 to 16 characters!") return 0 end local String = "UPDATE "..SQL.GameDB.Name..".dbo.guild SET guild_name ='"..name1.."' WHERE guild_name = '"..name2.."'" local Connect, ConnectID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL("query", ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL("fetch", ConnectID, Query) LuaSQL("freehandle", ConnectID, Query) LuaSQL("close", ConnectID) -- LG("GuildChangeName","guild has been changed from["..name2.."] to [ "..name1.." ] ") end end end ------get guild leader id ---- function GuildLeaderID(Player) local Guild_ID = GetChaGuildID(Player) local String = "SELECT leader_id FROM GameDB.dbo.guild WHERE guild_id = '"..Guild_ID.."'" local Connect, ConnectID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL("query", ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL("fetch", ConnectID, Query) LuaSQL("freehandle", ConnectID, Query) LuaSQL("close", ConnectID) return Data["leader_id"] end end end ----- ---the function -- --guild change name card --- function guildchange(role,name1) local leaderid = GuildLeaderID(role) local guildid = GetChaGuildID(role) local guildname = GetGuildName(guildid) local Playerid = GetPlayerID(GetChaPlayer(role)) local chaname = GetChaDefaultName(role) local length = string.len(name1) if ((length < 5) or (length > 16)) then PopupNotice(role, "The length of the Guild's name must be from 5 to 16 characters!") return 0 end if ""..Playerid.."" ~= leaderid then PopupNotice(role, "Please Give This Card to Your Guild Master!") return 0 end -- Notice("player"..Playerid..leaderid) if CheckBagItem(role,19769) >= 1 then TakeItem(role, 0, 19769, 1) GuildChangeName(role,name1,guildname) HelpInfo(role,0,"You Have Changed Your Guild Name from ["..guildname.."] to {"..name1.."] congratulations~!") LG("GuildChangeName","Player ["..chaname.." ] Changed his guild name from ["..guildname.." ] to "..name1.."]") else PopupNotice(role, "You Don't have Change Guild Name Card!") return 0 end end ---handle chat , cmd.list['guildchangename'] = { gm = 0, param = {"string"}, func = function(role, param) guildchange(role,param[1]) end } ----------- "NOTE" its already don't change the name if exist " Edited March 6, 2019 by mkhzaleh Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted March 6, 2019 (edited) Hello @mkhzaleh! Please note that it's just a sketch, i didn't tested and not sure if the local Data is the correct function which will return integer line numbers from a result. Take a look on the sample below and try scripting. - Create a function and use SELECT * to return all columns from guilds with the new guild name; - Check if the column arealdy exists, if value > 0 then returns 1 else return 0; - Call the new function created on conditions of guild name change function; -- The function which will return all columns with the new guild name, return LUA_TRUE = exists, return LUA_FALSE = doesn't exists; function GuildNameTaken(NewName) local String = "SELECT * FROM GameDB.dbo.guild WHERE guild_name = '"..NewName.."'" local Connect, ConnectID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL("query", ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL("fetch", ConnectID, Query) if Data > 0 then return LUA_TRUE else return LUA_FALSE end LuaSQL("freehandle", ConnectID, Query) LuaSQL("close", ConnectID) end end end -- Call on the guild name change condition function if GuildNameTaken(name1) == LUA_TRUE then PopupNotice(role, "Guild name arealdy taken!") return 0 end Edited March 6, 2019 by Satan 1 Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted March 6, 2019 (edited) 4 hours ago, Satan said: Hello @mkhzaleh! Please note that it's just a sketch, i didn't tested and not sure if the local Data is the correct function which will return integer line numbers from a result. Take a look on the sample below and try scripting. - Create a function and use SELECT * to return all columns from guilds with the new guild name; - Check if the column arealdy exists, if value > 0 then returns 1 else return 0; - Call the new function created on conditions of guild name change function; -- The function which will return all columns with the new guild name, return LUA_TRUE = exists, return LUA_FALSE = doesn't exists; function GuildNameTaken(NewName) local String = "SELECT * FROM GameDB.dbo.guild WHERE guild_name = '"..NewName.."'" local Connect, ConnectID = LuaSQL("connect", SQL.GameDB.Host, SQL.GameDB.User, SQL.GameDB.Password) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL("query", ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL("fetch", ConnectID, Query) if Data > 0 then return LUA_TRUE else return LUA_FALSE end LuaSQL("freehandle", ConnectID, Query) LuaSQL("close", ConnectID) end end end -- Call on the guild name change condition function if GuildNameTaken(name1) == LUA_TRUE then PopupNotice(role, "Guild name arealdy taken!") return 0 end helo @Satan ::) thanks for your time , in my case now works fine with this function :) Close the topic :) Edited March 6, 2019 by mkhzaleh 1 Quote Share this post Link to post Share on other sites
Eviles 179 Report post Posted March 6, 2019 Well done @mkhzaleh! So, the local Data return the table. I've done that right now and working also... function GuildNameTaken(GuildName) local String = "SELECT * FROM "..SQL.GameDB..".dbo.guild WHERE guild_name = '"..GuildName.."'" local Connect, ConnectID = LuaSQL(SQL.Connect, SQL.Host, SQL.UID, SQL.PWD) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL(SQL.Query, ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL(SQL.Fetch, ConnectID, Query) if (type(Data) == "table") then if (tostring(Data["guild_name"]) == GuildName) then return LUA_TRUE else return LUA_FALSE end end LuaSQL(SQL.FreeHandle, ConnectID, Query) LuaSQL(SQL.Close, ConnectID) end end end 1 Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted March 6, 2019 1 minute ago, Satan said: Well done @mkhzaleh! So, the local Data return the table. I've done that right now and working also... function GuildNameTaken(GuildName) local String = "SELECT * FROM "..SQL.GameDB..".dbo.guild WHERE guild_name = '"..GuildName.."'" local Connect, ConnectID = LuaSQL(SQL.Connect, SQL.Host, SQL.UID, SQL.PWD) if Connect == SQL_SUCCESS_WITH_INFO then local Success, Query = LuaSQL(SQL.Query, ConnectID, String) if Success == SQL_SUCCESS_WITH_INFO then local Data = LuaSQL(SQL.Fetch, ConnectID, Query) if (type(Data) == "table") then if (tostring(Data["guild_name"]) == GuildName) then return LUA_TRUE else return LUA_FALSE end end LuaSQL(SQL.FreeHandle, ConnectID, Query) LuaSQL(SQL.Close, ConnectID) end end end nice :) Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted March 6, 2019 (edited) --this table for illegal symbol local illegal = {"!","?",":","'","''","/","*","؟","@","#","$","+","-","--","%",".","..","(",")","^","=","==" ,"__","_","**" } --check if symbol exist in the name or not ---------- for i = 1, table.getn(illegal), 1 do if (string.find(name1, ""..illegal[i].."") ~= nil) then PopupNotice(role, "Please input legal alphabet or numbers!") return 0 end end for illegal symbols Edited March 6, 2019 by mkhzaleh Quote Share this post Link to post Share on other sites
jing 0 Report post Posted March 7, 2019 if I were you, I would definitely refactor the code and refrain from using a separate function to check whether the specified guild already exists. update table set column=... where not exists (select * from table where ...); Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted March 7, 2019 3 hours ago, jing said: if I were you, I would definitely refactor the code and refrain from using a separate function to check whether the specified guild already exists. update table set column=... where not exists (select * from table where ...); we solved the issue :)@V3ct0r can you close the topic :) thanks! Quote Share this post Link to post Share on other sites
Angelix 374 Report post Posted April 6, 2019 (edited) On 3/6/2019 at 12:36 PM, mkhzaleh said: --this table for illegal symbol local illegal = {"!","?",":","'","''","/","*","؟","@","#","$","+","-","--","%",".","..","(",")","^","=","==" ,"__","_","**" } --check if symbol exist in the name or not ---------- for i = 1, table.getn(illegal), 1 do if (string.find(name1, ""..illegal[i].."") ~= nil) then PopupNotice(role, "Please input legal alphabet or numbers!") return 0 end end for illegal symbols I don't know if you kept all of that, but maybe give this a try. Function: CheckString = function(Name) if string.len(Name) < 5 or string.len(Name) > 16 then return print("Name ["..Name.."] is too short or too long.") end if string.find(Name, "[^%w%s]") ~= nil then return print("Name ["..Name.."] must only contain alphanumeric values.") end return print("Name ["..Name.."] is correct.") end Input Values: CheckString("ABCD") -- 4 CheckString("ABCDE") -- 5 CheckString("ABCDEFGHIJKLMNOP") -- 16 CheckString("ABCDEFGHIJKLMNOPQ") -- 17 CheckString("ABCDEFG IJKLMNOP") -- 16 CheckString("ABCDEFG_IJKLMNOP") -- 16 CheckString("A!C E@G I#K M$OP") -- 16 Results: Name [ABCD] is too short or too long. Name [ABCDE] is correct. Name [ABCDEFGHIJKLMNOP] is correct. Name [ABCDEFGHIJKLMNOPQ] is too short or too long. Name [ABCDEFG IJKLMNOP] is correct. Name [ABCDEFG_IJKLMNOP] must only contain alphanumeric values. Name [A!C E@G I#K M$OP] must only contain alphanumeric values. You just need this simple code to check if it contains any weird symbol. if string.find(<STRING>, "[^%w%s]") ~= nil then ... end If you want to test Lua stuff without really opening a server, use the Lua manual and this site to run code: Repl.it Lua Manual - String Manipulation Edited April 6, 2019 by Angelix 1 Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted April 6, 2019 2 hours ago, Angelix said: I don't know if you kept all of that, but maybe give this a try. Function: CheckString = function(Name) if string.len(Name) < 5 or string.len(Name) > 16 then return print("Name ["..Name.."] is too short or too long.") end if string.find(Name, "[^%w%s]") ~= nil then return print("Name ["..Name.."] must only contain alphanumeric values.") end return print("Name ["..Name.."] is correct.") end Input Values: CheckString("ABCD") -- 4 CheckString("ABCDE") -- 5 CheckString("ABCDEFGHIJKLMNOP") -- 16 CheckString("ABCDEFGHIJKLMNOPQ") -- 17 CheckString("ABCDEFG IJKLMNOP") -- 16 CheckString("ABCDEFG_IJKLMNOP") -- 16 CheckString("A!C E@G I#K M$OP") -- 16 Results: Name [ABCD] is too short or too long. Name [ABCDE] is correct. Name [ABCDEFGHIJKLMNOP] is correct. Name [ABCDEFGHIJKLMNOPQ] is too short or too long. Name [ABCDEFG IJKLMNOP] is correct. Name [ABCDEFG_IJKLMNOP] must only contain alphanumeric values. Name [A!C E@G I#K M$OP] must only contain alphanumeric values. You just need this simple code to check if it contains any weird symbol. if string.find(<STRING>, "[^%w%s]") ~= nil then ... end If you want to test Lua stuff without really opening a server, use the Lua manual and this site to run code: Repl.it Lua Manual - String Manipulation Hey @Angelix , yea this sound better too :) and do the work thanks for sharing not sure if can detected if there is any spaces in the name for example "TEst tt" Quote Share this post Link to post Share on other sites
Angelix 374 Report post Posted April 6, 2019 If you don’t want the names to have spaces then remove the “%s” from the find function. By putting “%w%s” in the search, it will allow letters, numbers and spaces. I guess by removing “%s” will only allow letters and numbers. 1 Quote Share this post Link to post Share on other sites
mkhzaleh 131 Report post Posted April 6, 2019 (edited) fixed u can remove s and add this string.find(name1, "[^%w%g]") ~= nil then %g: represents all printable characters except space. and also work if u keep it %w as you said :) Edited April 6, 2019 by mkhzaleh Quote Share this post Link to post Share on other sites