Jump to content

[QUESTION] How can I use scripts in different folders in my resource?


Kazafka

Recommended Posts

This is the dumbest question I've ever asked on this forum, but I have problem even not only with this. So, how can I add scripts from different folders in my meta.xml?

And in these scripts, how can I load xml files from different folders, too? Any idea? If yes, please, show me example :o

I know, that I would use 

xml = xmlLoadFile("filename.xml")

But how to load xml in different folders? Same

<script src="script.Lua" type="server"/>

But how to tell MTA to load script from different folder?

Edited by VaporZ
Link to comment
  • Moderators

I think you can't do that, but you can export functions.

Wiki: https://wiki.multitheftauto.com/wiki/Call

 

Example:

-- CLIENT
function print_msg(msg)
	outputChatBox(msg)
end
<meta>
	<script src="client.Lua" type="client"/>
	<export function="print_msg" type="client"/>
</meta>

 

After it you can call this 'print_msg' function from other resources:

-- CLIENT
exports.FIRST_RESOURCE_NAME:print_msg("called from other resource")

 

Link to comment
2 minutes ago, stPatrick said:

I think you can't do that, but you can export functions.

Wiki: https://wiki.multitheftauto.com/wiki/Call

 

Example:


-- CLIENT
function print_msg(msg)
	outputChatBox(msg)
end

<meta>
	<script src="client.Lua" type="client"/>
	<export function="print_msg" type="client"/>
</meta>

 

After it you can call this 'print_msg' function from other resources:


-- CLIENT
exports.FIRST_RESOURCE_NAME:print_msg("called from other resource")

 

But, how do I load a xml file, wich is in another folder, from a script, that is in default resource folder?

Link to comment
<meta>
	<!-- Blah blah blah (info) and this: -->
	
	<script src="cars.Lua" type="client"/>
	<script src="bank.Lua" type="client"/>
	<script src="fshop.Lua" type="server"/>
	<script src="gunshop.Lua" type="server"/>
	
	<file src="VaporCars/shops.xml"/>
	<file src="VaporCars/saved.xml"/>
	<file src="Bank/accounts.xml"/>
	<file src="Bank/atms.xml"/>
	<file src="Gunshop/prices.xml"/>
</meta>

This?

Is this possible?

Just now, Bilal135 said:

Lol I thought you were trying to load a file from a different folder within the same script.

Kinda.

Link to comment
  • Moderators

So, you want to load a xml file with xmlLoadFile from other resource?

Enter the full path, from the root resource folder. ( start path with )

 

xmlLoadFile(":OTHER_RESOURCE_NAME/SUBFOLDER/file.xml")

 

Edited by stPatrick
  • Like 1
Link to comment
8 minutes ago, stPatrick said:

So, you want to load a xml file with xmlLoadFile from other resource?

Enter the full path, from the root resource folder. ( start path with )

 


xmlLoadFile(":OTHER_RESOURCE_NAME/SUBFOLDER/file.xml")

 

NAAAH!

I want to load xml file in subfolder, but with script, that is in the same folder, as meta.xml!

Aaaaand this:

xml = xmlLoadFile("VaporCars/saved.xml")

Doesn't work!

"[...] Now you know!" ~ BELL BIV DEVOE - Poison

Edited by VaporZ
Link to comment

Is it server or client? If it's on the server, there is no need to declare the files in meta.xml for it to work. However, the resource that does the loading needs access to the general.ModifyOtherObjects permission to be able to read files located in other resources.

Link to comment
1 hour ago, MIKI785 said:

Is it server or client? If it's on the server, there is no need to declare the files in meta.xml for it to work. However, the resource that does the loading needs access to the general.ModifyOtherObjects permission to be able to read files located in other resources.

His problem was solved in this topic.

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