Jump to content

Structure of a Resource || Hints and Helps


Robert333

Recommended Posts

I mostly no newbie today in scripting LUA, but in last time I always fail at the structure and management of my script/resource. In the last weeks I wrote and I will do in future a gamemode.

But now the script is long and unclearly. I tried to clean the code with the "--" Tag and wrote above all functions a header, but it was just unclearly too. Then I have split my "script_server.lua" and "script_client.lua" in many different LUA-Files, but that isn't a solution too. Maybe someone can help and write down his structure of resources.

Another problem is in the script. For example should I use "setElementData" or a "table" to set data that isn't given in a MTA-Function. Or should I use one "function" which is called by one "EventHandler" and in the "function" I call another "functions" or should I use for each "function" an "EventHandler"?

Hopefully you can help me because I wrote my script just more than ten times new. It's my most difficult problem in scripting.

PS: I'm German, and not good in English ;-).

Link to comment

I mostly no newbie today in scripting LUA, but in last time I always fail at the structure and management of my script/resource. In the last weeks I wrote and I will do in future a gamemode.

But now the script is long and unclearly. I tried to clean the code with the "--" Tag and wrote above all functions a header, but it was just unclearly too. Then I have split my "script_server.lua" and "script_client.lua" in many different LUA-Files, but that isn't a solution too. Maybe someone can help and write down his structure of resources.

Another problem is in the script. For example should I use "setElementData" or a "table" to set data that isn't given in a MTA-Function. Or should I use one "function" which is called by one "EventHandler" and in the "function" I call another "functions" or should I use for each "function" an "EventHandler"?

Hopefully you can help me because I wrote my script just more than ten times new. It's my most difficult problem in scripting.

PS: I'm German, and not good in English ;-).

Link to comment

i think its impossible to explain all those things in just one single post..

you have two ways:

first get the MTA Script Editor - it will help you a lot :)

then:

- download some resources (starting from really simple! you must know the basics) and read & analize them

- or getting through tutorials.

Wiki is very helpful too.

Good luck

Link to comment

i think its impossible to explain all those things in just one single post..

you have two ways:

first get the MTA Script Editor - it will help you a lot :)

then:

- download some resources (starting from really simple! you must know the basics) and read & analize them

- or getting through tutorials.

Wiki is very helpful too.

Good luck

Link to comment

I didn't want to know how I script, maybe I asked a little bit complicated.

I want help with the structure. Perhaps a example helps:

function ***()
blabla()
if blabla then
getblabla(bla,bla)
end
end
 
or
 
-- Function: *** --
function ***( )
   blabla( ) -- do blabla
 
if blabla then -- do something when blabla true
 
       getblabla ( bla, bla ) -- get blabla from blabla
 
end -- end if
 
end -- end function
 
or
 
function ***()
 
   blabla()
 
if blabla then getblabla(bla,bla) end
 
end

and the structure of a resource:

meta.xml

client/client.lua

server/server.lua

or

meta.xml

client/gui/menu/menu.lua

.../script/world/world.lua

.../.../player/player.lua

server/script/vehicle/vehicle.lua

...

Maybe now it's clear. I want to know some hints which make the script better looking and easier to wrote long scripts.

I have a script and it works fine but I still script a new script, because I don't like how my script look.

But thanks for answer varez, robhol

------------

There are no "right" answers to this question - how you organize your resources is up to you as long as it makes sense and is understandable.

[...]

Yeah, but you have for example a structure how your resource/script is looking, but I understand your point, maybe I find a solution.

Thanks for reply

Link to comment

I didn't want to know how I script, maybe I asked a little bit complicated.

I want help with the structure. Perhaps a example helps:

function ***()
blabla()
if blabla then
getblabla(bla,bla)
end
end
 
or
 
-- Function: *** --
function ***( )
   blabla( ) -- do blabla
 
if blabla then -- do something when blabla true
 
       getblabla ( bla, bla ) -- get blabla from blabla
 
end -- end if
 
end -- end function
 
or
 
function ***()
 
   blabla()
 
if blabla then getblabla(bla,bla) end
 
end

and the structure of a resource:

meta.xml

client/client.lua

server/server.lua

or

meta.xml

client/gui/menu/menu.lua

.../script/world/world.lua

.../.../player/player.lua

server/script/vehicle/vehicle.lua

...

Maybe now it's clear. I want to know some hints which make the script better looking and easier to wrote long scripts.

I have a script and it works fine but I still script a new script, because I don't like how my script look.

But thanks for answer varez, robhol

------------

There are no "right" answers to this question - how you organize your resources is up to you as long as it makes sense and is understandable.

[...]

Yeah, but you have for example a structure how your resource/script is looking, but I understand your point, maybe I find a solution.

Thanks for reply

Link to comment

As I said, that's up to you. If you look at large resources with a lot of files (that aren't necessarily script files), like admin, killmessages or mabako-services, the files are often bunched in folders based on server/client, what they are (script/data) or what they do. Ultimately, what's probably best for you is what you feel comfortable with.

Personally, I just name my script files something logical and have most of them on the "root" level of my resource, I don't bother with folder, I consider them something of a time waste and most of my script aren't really extensive enough for folders to be useful.

Link to comment

As I said, that's up to you. If you look at large resources with a lot of files (that aren't necessarily script files), like admin, killmessages or mabako-services, the files are often bunched in folders based on server/client, what they are (script/data) or what they do. Ultimately, what's probably best for you is what you feel comfortable with.

Personally, I just name my script files something logical and have most of them on the "root" level of my resource, I don't bother with folder, I consider them something of a time waste and most of my script aren't really extensive enough for folders to be useful.

Link to comment

One function should do only one specific thing. So, probably the more functions (and shorter) you have the better. Except, if there's a function that's called only by one function and you know there won't be any more places it'll be called, then it's usually better to put inside the parent function.

Link to comment

One function should do only one specific thing. So, probably the more functions (and shorter) you have the better. Except, if there's a function that's called only by one function and you know there won't be any more places it'll be called, then it's usually better to put inside the parent function.

Link to comment

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...