Including multiple client files


#1

The simple mod I was working on is growing out of hands on the client side and I feel the need to put the ‘class objects’ in their own file so that they may be accessed in the main file.

-- __resource.lua
server_script 'server.lua'
client_script 'example_class_file.lua'
client_script 'client.lua'

In client.lua I reference the object stored in example_class_file.lua which is not defined as local, so it should work, right? It does not, even though the code was literally moved from client.lua to example_class_file.lua.

When the object is accessed, it complains about the object index being nil. In the CitizenFX.log file it does complain about being unable to load example_class_file.lua, however, everything looks great when I open the RPF file in the cache directory, so that file and its contents definitely exist and in the right order (if that even matters).

I tried other variants for __resource.lua such as below, but it makes no difference.

server_script 'server.lua'
client_scripts 'example_class_file.lua'
client_scripts 'client.lua'

and

server_script 'server.lua'
client_scripts {
	'example_class_file.lua',
	'client.lua'
}

I have also tried to access the object with g[] to no avail.

So how am I supposed to accomplish this? I have looked at other mods but none of them really seem to do it with client files. Freeroam v2 has multiple client files, but I don’t think they use each other.

The file is getting confusingly big, so I would really like to solve this. Any ideas?


#2

Why would this be needed on the client? It’s better to store variables on the server to make sure they can’t be manipulated by the client


#3

Cheating is not really of any concern since it’s a small mod to enhance a fun little game of running and chasing we have been playing. Various variables get updated every tick to track vehicle speed and health and I don’t really want the latency to come into play. If it were server sided, one could just as easily modify the data sent to the server to achieve the same thing, so in the end it does not matter.

Judging by your reply, I take it that this is not possible for the client? I can work in one file if I have to, but I would be too embarrassed to share the code with anyone interested if it’s messy like that…


#4

####client_scripts

Lists one or multiple client scripts for the resource. Parsed by both client (to load scripts) and server (to offer scripts for download). Aliased as client_script.

client_script 'client.lua'

client_scripts {
	'client1.lua',
	'client2.lua'
}

####dependencies

Lists one or multiple required resources for this resource. Aliased as dependency.

dependency 'chat'

dependencies {
	'dot',
	'test'
}

####description

Sets the meta field ‘description’ in the resource’s metadata.

description 'My resource'

####exports

Lists one or multiple client-side script exports for other resources to call - these are taken from the resource’s global environment. Aliased as export.

export 'getStuff'

exports {
	'getStuff',
	'getOtherStuff'
}

####server_scripts

Lists one or multiple server scripts for the resource. Only parsed server-side. Aliased as server_script.

server_script 'server.lua'

server_scripts {
	'server1.lua'
	'server2.lua'
}