Jump to content
Sign in to follow this  
kyleflow

A working IMP Card System without LuaSQL.dll

Recommended Posts

Okay since I've struggle asking question in the forum without any answer relating to LuaSQL.dll, I somehow manage to do this and it works. Importance note for this to work.

 

1. Do not attach LuaSQL.dll of any version with CFF.

 

2. I'm using Lucky ServerFiles GS which is version 1.36 ( it might not work with your GS)

 

3. I'm not sure if the connector function for index.lua I give is the correct syntax that make it work or not but the connection syntax in the init.lua surely must be there for it to work. (I've run test and without it, the system not working.

 

4. Based on forum, I did not see any issues as mentioned where the system hang few secs to process this.

 

5. Okay lets see what I did.

 

dofile(GetResPath("script/extension/Lua-SQL/init.lua"))
dofile(GetResPath("script/extension/Lua-SQL/index.lua"))

Step 1 : Include this inside your Resource>script>MisScript>NPCScript (any of your choice, mine on 07)

 

Step 2: Create an extension folder based on the location on the above dofiles. It is case sensitive.

 

Disclaimer, the code here are compilation of code available in the forum, the way I use it only a bit different. Credit to owner.

 

Step 3: Inside init.lua, you need this code.

 

SQLConnector = {};
SQLConnector.sql = { host = "KHAIRUL\\CERMIN", user = "sa", pass = "Y87dc#$98", db = "TradeDB" }; --asal 127.0.0.1\\SQLEXPRESS

You need the double \\ in the host section to make it work.

 

Step 4: Put this inside index.lua. Remember, this part I'm not sure which connector work, so I just left the original connector there since it does not affect the success. The section for function  AddMallPoints(cha,points), I check it with my SQL database. If you used the same database as provided by Lucky, the syntax should be as I'm shown since my database, "Money" reflecting the amount of crystal in IGS.

-- ***********************************
-- Sample Lua-SQL System
-- Requires: SQL Server 2005
-- By Sultan | V3ct0r
-- ***********************************
local PLUGIN_NAME = '[[LUA-SQL System]]'
local PLUGIN_VERSION = '0.2'
local PLUGIN_AUTHOR = 'Sultan | V3ct0r'

--[[
	******************
	** Version: 0.2 **
	******************
	[*] Slightly faster and less lag on execution
	[*] Edited LuaSQL.LG function to generate new files instead of editing Query.txt
	[*] Added LuaSQL.LG for every sample function to trace players inside new file Logs.txt
	[*] Removed/Edited few unneccessary stuffs from V0.1
	
	
	******************
	** Version: 0.1 **
	******************
	[*] Use SQL Query directly using your scripts!
	[*] Built in the extension, there are few sample SQL Queries: AddMallPoints, AddCreditsPoints, ChangePlayerName, and more!
	[*] Requires GetPlayerByName if used by &lua command
	[*] Built in the extension the GetPlayerByName function, if it isn't exists in your files it will add it
	[*] You can freely add any SQL Query Execute function you wish for
	[*] This system will only generate UPDATES to SQL, you cannot "GET" any data from SQL
	[*] Requires SQL 2005 and above to use
	[*] For more information & details: http://forum.maindev.ru/threads/npc-dlja-nadoedalok-skajpa.19514/#post-159439
]]--

-- --------------------------
-- Display loading message on startup
-- --------------------------
print(">> Loading extension: "..PLUGIN_NAME)
print("	[Version: "..PLUGIN_VERSION.."] from "..PLUGIN_AUTHOR)

-- ------------------------
-- LUA-SQL ::DO NOT TOUCH::
-- ------------------------
do
	LuaSQL = {}
	LuaSQL.Directory = GetResPath('script\\extension\\Lua-SQL\\');
	LuaSQL.Host = "KHAIRUL\\CERMIN";
	LuaSQL.User = "sa";
	LuaSQL.Pass = "Y87dc#$98";

	LuaSQL.LG = function(file_name,text)
		local file = LuaSQL.Directory..file_name..'.txt'
		LogFile = io.open(file,'a')
		LogFile:write("["..os.date().."]\t"..text.."\n")
		LogFile:close()
	end

	LuaSQL.Execute = function(query)
		LuaSQL.LG('Query','Executed Query: ['..query..']');
		os.execute("sqlcmd -S "..LuaSQL.Host.." -U "..LuaSQL.User.." -P "..LuaSQL.Pass.." -Q \""..query.."\" 1>NUL 2>NUL");
	end
	
	-- if GetPlayerByName is nil, it will generate
	if(GetPlayerByName == nil)then
		Roles = {}
		
		Timer = cha_timer
		cha_timer = function(r,f,t)
			if(IsPlayer(r) == 1)then
				local characterName = GetChaDefaultName(r)
				if(Roles[characterName] == nil)then
					Roles[characterName] = r
				end
			end
			Timer(r,f,t)
		end
		
		GetPlayerByName = function(name)
			if(Roles[name] ~= nil)then
				return Roles[name]
			end
			return nil
		end
	end
end

-- ------------------------
-- LUA-SQL Functions
-- ------------------------

--[[
	*****************************
	** Sample Custom Functions **
	*****************************
	[*]: AddMallPoints(cha,points) => Requires Userdata to grant Mall Points
	[*]: AddCreditsPoints(cha,points) => Requires Userdata to grant Credits
	[*]: ChangePlayerName(cha,newName) => Requires Userdata to change players name
	[*]: ChangeGuildName(guildID,newName) => Requires Guild ID to change guild name
	[*]: Ban(cha) => Will ban character by Userdata
	[*]: UnBan(account Name) => Will unban character by account
	
	P/S: You can add yours, just use one of samples below and create your own.
	
	@FAQ [How To Use]:
	
	Example:
	&lua AddMallPoints("Player Name",1000)
	&lua ChangeGuildName(1,"New Guild Name")
	&lua Ban("Account Name")
]]--

function AddMallPoints(cha,points)
	if(type(cha) ~= 'userdata')then
		cha = GetPlayerByName(cha)
	end
	if(cha ~= nil)then
		local accountName = GetActName(cha)
		LuaSQL.Execute("UPDATE tradedb.dbo.AccountInfo SET Money = Money + "..points.." WHERE accName = '"..accountName.."'")
		LuaSQL.LG('Logs','[AddMallPoints] = Account name['..accountName..'] successfully added '..points..' mall points');
	end
end

Step 5: Create an item for it with the function below, put it inside iteminfo.txt and itemeffect.lua respectively.

 

7346	1 Crsytal	n0109	10130005	0	0	0	0	0	0	31	0	0	0	0	0	1	1	1	1	99	0	1000	-1,-2,-2,-2	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	-1,-2,-2,-2,-2,-2,-2,-2,-2,-2	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0,0	0	0,0	0,0	0	0	0	0	0	0	0	0	0	ImpsPoint_1	0	0	0	0,0	0	0	Obtain Crystal when used	0
function ImpsPoint_1 ( role , Item )
	local points = AddMallPoints(role,1)
	if points == 1 then
		SystemNotice(role ,"You just got 1 points !")
    end

end

That's all. Some unexplained part as per mentioned above, I really don't know why it works but hey, it did work. Enjoy.

Share this post


Link to post
Share on other sites

Whilst this works please keep in mind its very bad practise. The os.execute function call is blocking in nature, which means that it will halt the execution of game server until the command finishes. If a SQL query or command takes a long time to execute, it could cause noticeable delays.

 

not to mention it is prone to sql injections and other security vulnerabilities (there’s enough already, so why add more :))

  • Haha 1

Share this post


Link to post
Share on other sites
1 hour ago, champ said:

Whilst this works please keep in mind its very bad practise. The os.execute function call is blocking in nature, which means that it will halt the execution of game server until the command finishes. If a SQL query or command takes a long time to execute, it could cause noticeable delays.

 

not to mention it is prone to sql or injections and other security vulnerabilities (there’s enough already, so why add more :))

Luckily as I mentioned above. I play solo. Can't hack me if I'm not even connected to the internet 😈

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...