Jump to content

Help on debug messages needed


Ch3ck3r

Recommended Posts

Posted (edited)

Hi guys,

i'm relatively new to lua and mta but not so new at scripting in general.

I want to create a new gamemode, starting from scratch and ran into my first problem already.

I want to use a mysql database and therefor i am checking the database connection on resource start up.

This is the relevant piece of code

function onGamemodeStart(resource)
g_gameMode = resource
g_mysqlHandler = mysql_connect("localhost", "mtasa", "------", "mtasa")
if(not g_mysqlHandler) then
	outputDebugString("Could not establish connection to database server", 1)
	outputConsole("Could not establish connection to database server")
	outputServerLog("Could not establish connection to database server")
	shutdown("Could not establish connection to database server")
end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onGamemodeStart)

This piece of code does work, indeed. It shuts down my server when the connection can't be established.

But i'm missing the debug output. None of the Lines above create a readable Message. Ther is no message

in the console nor in the log file neither a debugmessage in the server.

I set debugscript to 3 (ingame) and scriptdebugloglevel (in mtaserver.conf) to 3 as well.

Any help appreciated

Thanks :)

Edited by Guest
Posted

This is MySQL module's bug on Windows. It will crash if it'll fail to connect. It should work fine on *UNIX operating systems. So, be aware of this.

Posted

Thanks for this information, though i'd have to know this. Now you are mentioning it it came to my mind, that i've stumbled about this damn error in other languages and modules already.

Nevertheless i've one question left. It's not really a problem but maybe you got some advice for me.

I need to use the same mysql connection in serveral resources.

How do i do that in the best way?

I tried to pass the mysq_handle with an exported function which didn't worked.

By passing the handle between resources it always became a string and was useless.

Atm. i solved it by saving the mysql data in settings.xml and create one connection per resource.

Isn't there a better way?

Posted

You could have a centralized system with one resource interacting with the database and where the resources that needed DB data would interact with that resource via either exported functions or events.

Posted

Like robhol suggested, i summed up everything in a central resource called 'database'

Actually the whole file just overwrites the mysql functions providing the resource parameter automatically.

It was quite a boring task to rewrite all mysql function, so if anybody is in need of it, i will post it up on here.

Currently it does only work from server-side. Maybe i will do some event based system for handling action with client scripts later.

Posted

You should clearly be very careful providing access to client-side scripts. You certainly shouldn't allow them to execute arbitrary SQL, or you'll have someone doing a DELETE or DROP on you...

Posted

Yep. I came accross i don't need client side mysql anyway.

But is there a way to make a function global? So every resource can call it without exports.resource:function ?

Posted

No, it'd get pretty messy if there was I think, though it could be useful sometimes...

Something that could be added in the future would be an tag in the meta.xml that would import one resource into another - either by just mapping functions directly to exported ones or by running the resource again in the instance of the resource that was imported...

Posted

Yeah that'd be quite useful sometimes.

At the moment i use something like this, because i am to lazy to write this exports... stuff

mysql = exports.database
 
-- and then in function i use
mysql:mysql_query("...")

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...