General > Developers Corner
Ulib/ULX function overriding (and now Hooks too) - MySQL
EraYaN:
HI,
I want to do the following thing:
Create full mySQL bindings for ULib/ULX, mySQL is not the problem. but how would I go and overriding ulib/ulx functions like ban/kick basicly only the file writing functions need overriding, right?
I would love to override in separate files so ULib updates wont ruin my functions. But I couldn't find anything helpful on the internet.
And if anyone wants to help, svn is up.
EraYaN
Megiddo:
The knee-jerk response would be that you should use a hook like this one, but I think you'd be better off simply redefining the kick and ban functions listed here.
EraYaN:
Thanks for the response!
Hooks seems fine to use, they tend to work like C#/Java/C++ events right?
Ok I still need your help, I just started Lua after a long time other languages like C++, C# and PHP
(I hate the not be able to test immediately, anything?)
I copied your way of getting the code run
so in autorun folder there is and file the includes init.lua and that one includes my file I put some examples in:
--- Code: ---function ULib.slap( ent, damage, power, nosound )
Msg('Slap override')
end
-- way of overriding?
-- ban hook function
function banHook(ply, commandName, translated_args)
end
hook.Add("ULibPostTranslatedCommand", "EraYaNBanHook", banHook) -- or is there a ulib/ulx alternative
-- player join (add to mysql database)
function playerJoinDB(ply)
-- check if player in db otherwise add him/her
end
hook.Add("UCLAuthed", "HookName", playerJoinDB) -- or is there a ulib/ulx alternative
--- End code ---
I tested it but not a very good result
--- Code: ---Registering gamemode 'sandbox' derived from 'base'
Sending 270 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Scanning for downloaded fonts..
Reloading Particles..
Client "[BB] EraYaN" spawned in server (192.168.1.54:27006)<STEAM_0:1:2700xxxx>.
Welcome to Garry's Mod dedicated server! We're playing gm_construct.
Redownloading all lightmaps
ULX version <SVN> unknown revision loaded.
Player [1][unconnected] authed <-- shouldn't my player auth hook thing show after this line
test true
///////////////////////////////////////
// ULX GUI -- Made by Stickly Man! //
///////////////////////////////////////
// Loading GUI Modules... //
-snip-
// Modules Loaded! //
///////////////////////////////////////
] ulx slap "[BB] EraYaN"
You slapped Yourself with 0 damage <-- and the other hook overhere
--- End code ---
I probably missed something but i just so new to gmod lua and the hook/ulx system
EraYaN
EDIT: I looked at the log files, it seems that by changing the function ulx.logWriteln( str ) (preferably not in the log.lua but in an external file) or maybe hooking on to it(best way i guess) that I can send all the logs to a MySQL database right? or anywhere else.
Megiddo:
My guess would be that you're not overriding ULib.slap (the function) because you're setting up the function before ULib does (and thus, ULib is actually overwriting yours).
As far as the hooks, there's no ULib alternative to hook.Add (except that we just make the hook system in general more awesome). You didn't show any print messages in those two hooks, so I don't see why you should expect them to print?
JamminR:
EraYan, you can (almost) always guarantee your code/functions run after ULib initializes if you put them in Gmod's addons and ULX/ULib's modules format.
gmod root/addons/Your_SQL_addon_name/lua/<ulib | ulx>/modules/<your lua files>
Make sure to use an info.txt within your addon_name folder. (See all other addons for an example, or the gmod wiki)
As ulib or ulx initialize (depending on which modules folder you used), the code you place there will load.
As for immediate testing, lua_run is your friend. as is lua_run_cl
My other team members will be able to help you more with that.
Navigation
[0] Message Index
[#] Next page
Go to full version