Include file from different directory

Hi all,

I need to use some functions from another file in my gmod server directory. The problem is I don’t know how to navigate to it from that file.

This is where my functions are ( which I want to include ):

garrysmod/lua/autorun/ranks.lua

This is where I want to include it in:

garrysmod/addons/ulx/lua/ulx/modules/sh/user.lua

I have tried many paths using the include function but none of them work.

Thanks,
Computer

PS: I basically want to use functions from the first file I mentioned in the second file I mentioned. If there is a better/easier way please tell me. Thanks once again

Take a look at http://wiki.garrysmod.com/page/file/Find, I think this should help

There is no reason why you should need to include a ULX function within the directory. Placing them in autorun should work perfectly fine if you’ve done everything correctly. Can’t you call the ulx functions? The ULX table should be global, you should be able to use it wherever.

Hmm,

Here’s the function I’m editing in ULX:



function ulx.adduser( calling_ply, target_ply, group_name )
	local userInfo = ULib.ucl.authed[ target_ply:UniqueID() ]

	local id = ULib.ucl.getUserRegisteredID( target_ply )
	if not id then id = target_ply:SteamID() end

	ULib.ucl.addUser( id, userInfo.allow, userInfo.deny, group_name )

	SaveULXRank( target_ply )

	ulx.fancyLogAdmin( calling_ply, "#A added #T to group #s", target_ply, group_name )
end
local adduser = ulx.command( CATEGORY_NAME, "ulx adduser", ulx.adduser )
adduser:addParam{ type=ULib.cmds.PlayerArg }
adduser:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
adduser:defaultAccess( ULib.ACCESS_SUPERADMIN )
adduser:help( "Add a user to specified group." )


SaveULXRank is the function I’m trying to get working

and heres that function in the autorun folder:



function SaveULXRank(ply)
	
	local usergroup = "user"
	
	if ply:IsUserGroup( "superadmin" ) then
		usergroup = "superadmin"
	elseif ply:IsUserGroup( "admin" ) then
		usergroup = "admin"
	elseif ply:IsUserGroup( "moderator" ) then
		usergroup = "moderator"
	elseif ply:IsUserGroup( "vip" ) then
		usergroup = "vip"
	elseif ply:IsUserGroup( "vip+" ) then
		usergroup = "vip+"
	elseif ply:IsUserGroup( "community" ) then
		usergroup = "community"
	else
		usergroup = "user"
	end
	
	local steamid = ply:SteamID()
	local InsertQ = DB:query("INSERT INTO `rankinfo` (`steam`, `groups`) VALUES ('" .. usergroup .."', '" .. ply:SteamID() .. "')")
	InsertQ.onError = DBError
		InsertQ.onSuccess = function(q)
		if checkQuery(q) then
			print ("That Database Stuff Happened Yay")
		end
	end
		InsertQ:start()
end


Have I missed something?

I wouldn’t recommend this method. ULX calls a hook after every command has been translated: http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibPostTranslatedCommand
This is how I hooked in “synchronization”
[lua]
function db:onConnected()

MsgN( "[Sync] Connected successfully to "..ip..":"..port.." with the username "..user.."

" )

hook.Add( "ULibPostTranslatedCommand", "UpdateOnPromotion", function( ply, command, args ) 

	if ( command ~= "ulx adduserid" and command ~= "ulx adduser" ) then return end

	local id = command == "ulx adduser" and args[2]:SteamID() or command == "ulx adduserid" and args[2] or nil // grabs the steamid from the arguments
	local group = args[3] // grabs the ULX group from the arguments

	MsgN( "[Sync] Traced a promotion successfully - attempting update query...

" )

	if db:status() ~= mysqloo.DATABASE_CONNECTED then

		MsgN( "[Sync] Server has lost connection to database - will reconnect and try again in 5 seconds...")

		db:connect()

		timer.Simple( 5, function() updateUser( id, group ) end ) // wait for the database to connect

		return 
	end

	updateUser( id, group ) // I'd make this your function with the update query

end )

end[/lua]
Maybe you can learn from it. Remember to check the database status before querying to reconnect if necessary, otherwise the query will be lost.