[FXServer] Server export

Hello,

I would like to know how the export_servers works?

Because I have a mistake that says “no such export AddCommand …”

server_exports {
  "AddCommand",
}
2 Likes

Frirst off, why did you add a coma ?
Then, you probably don’t have a AddCommand() function in your files

AddCommand exist, i use it already with the events

Server side right ?
And the file which contain the server function is well declared in the __resource.lua ?

Yes the event is working correctly :

AddEventHandler('ft_gamemode:SvAddSimpleCommand', function(prefix, permissionLevel, callback)

  AddCommand(prefix, permissionLevel, callback, "")

end)

Maybe it’s proper to load your file under FxServer.
Like, I’m on resource A I want to use a function which is in B.
On the A __resource.file, I just add :
server_script '@B/path/to/my/file'
And that’s it. Now the function in B is global to A and B

is correct ?

exports.ft_gamemode:AddCommand("car", 2, function(source, args)
  TriggerClientEvent('ft_admin:ClSpawnVehicle', source, args[1])
end)

I have to go through export

@izio’s comment “Maybe it’s proper…” and so on…

Unfortunately that’s incorrect. What you’re thinking of is a wrapper, because if you export functions they look like:

exports['pluginname']:FunctionName(params)

Alright, so I’m going to write a bit of a mini-tut on this since I’m not sure it’s documented well on the wiki and I’m already typing this and I’m too lazy to look. So, start off in your server.lua script by creating a function. I don’t believe this function can be defined inside of a loop and needs to be defined in the global scope of your script however I could be wrong. Haven’t tested. You should just make functions in the global scope anyways.

Step 1) Create a function in server.lua:

function Addition(a, b)
    return a + b
end

Step 2) Export the function in your __resource.lua file.

server_export 'Addition'

Step 3) To use that function in another resource we call it via the exports global. We’ll pretend the resource that contains Addition(a,b) is named “math”

return exports['math']:Addition(a, b)

Of course, if the command is triggering an event or something, you don’t need to use “return”, that’s just if you have a function that returns a value!

There you go, you’ve successfuly exported a function!

2 Likes

This is correct actually ^^
I’m using it

If you’re wondering how you would use a wrapper to make it look neater (This is irrelevant to functionality and is simply my preference)

Step 1) Make a lua script named wrapper.lua (Do not include this in the exported mod’s resources) It’s purpose is to be linked to.

Step 2) Create a function that wraps around the method you wish to make look nicer / readable.

function UpdateJob(player, job)
    exports['supertable']:UpdateJob(player, job)
end

Step 3) Include that resource script in another mod by linking to the folder/script.lua:

server_script '@supertable/wrapper.lua'

And now all the wrapped functions are included in whichever resource you are currently working on ^^

2 Likes

Oh yeah, that was what I was talking about ^^
Forgot the “wrapper” part

2 Likes

Izio, I was replying to what you said before he posted. I was typing that already before he posted :expressionless:

Frirst off, exports[‘math’]:Addition(a, b) == exports.math:Addition(a, b)

Add Command is already a global function : https://github.com/FivemTools/ft_gamemode/blob/master/server/sv_commands.lua

My resource.lua

And I still “no such export AddCommand …”

Yes AddCommand is a part of the new built in permissions system they’re working on. Why didn’t you follow my instructions?

The __resource.lua specifically requires:

server_export 'functionname'

That’s it. Nothing else.

Not “exports”
No curlyboyes {}{}{}{}{}{}

I tested with server_export is nothing either

Do we have to wait until the resource is loaded ?

I did tests, I found that it is like for the customer, it is necessary to wait that everything is well changed before to be able to use it. So you can not use it when you start the server. So how do we do that?

1 Like

Is there any update about this?