Jump to content

[LUA] LESSON #1 Creating a resource


Saml1er

Recommended Posts

Hello everybody, this is a tutorial by my friend ( Dreddy from DDC ) :

It's my first lesson to you, as Subject says, today I will teach you how to create resources.

Well, If you wanna create a simple resource, like with fun commands. You have to make only 2 files in folder (.xml one and .lua)

Well, Let's get started from beginning.

1. Open MTA Folder/server/mods/deathmatch/resources.

2. Create a new folder, called "Script01" http://i.imgur.com/ZU72Kor.jpg

As you see now, It's empty, Let's make something there.

3. Create a new Text File and call it "meta.xml" and Let's start with meta settings.

    "Author" version="1.0" name="Script01" type="script"/> 

Congratulations my boy, we created a simple meta code.

4. Create a new Text File an call it "script.lua"

DANGEROUS: If you're going to do some script, look carefully to which side that function belongs.

Here's not all functions belong to Client/Server side. If you will put Client-side event into the Server-side .lua file, It will not work at all.

5. Well, Let's make a simple script: When new map starts, It says us "Hello World"

addEvent('onRaceStateChanging', true) 
addEventHandler('onRaceStateChanging', root, 
    function(new) 
        if new=='LoadingMap' then 
            outputChatBox ('Hello World', root, 255, 255, 255, true) 
        end 
    end 
) 

6. Paste that code into our created .lua file and save it.

7. Adding Lua file in meta.

Here's nothing hard at all, just place that line into your .xml file AFTER or BEFORE


Now your meta.xml should look like

    "Author" version="1.0" name="Script01" type="script"/> 
    

8. Come to server, and use "/start Script01" and try to start some map on gamemode.


NOTE: If you don't understand anything here then please post it right here so I can help you.

Link to comment
  • 2 weeks later...
Hello.

Can I know what does the "onRaceStateChanging" event is? If possible, please explain in the simpliest form, as much as you can.

Thank you. :)

Its an Event ( race event ). You can also change the 'LoadingMap' with following states and the 2 parameters.

Parameters

string newState, string oldState

newState: the new state

oldState: the old state

Possible states:

undefined

NoMap

LoadingMap

PreGridCountdown

GridCountdown

Running

MidMapVote

SomeoneWon

TimesUp

EveryoneFinished

PostFinish

NextMapSelect

NextMapVote

ResourceStopping

More info can be found here: https://wiki.multitheftauto.com/wiki/Resource:Race

Link to comment
Apparently my resource "could not be found" and I've no idea why.

http://pasteboard.co/VWzb0WD.png

Type refresh or go to your server and type "/refresh". This will load the resource(You must have admin rights). Also At the top there's an option "Organize">Folder and search options>view> scroll down> and untick "hide extensions for known file types.

Then rename the script and meta text documents (change the suffixes to .xml and .lua) There should come up and label, you should click yes and the file type is now changed to .xml and .lua. Its important to do this because this will make it lua file from .txt.

Link to comment
Did see my post? And his picture shows that script.lua wasn't found. That's why it was failed to start it.

Allow me to educate you. "Resource not found" has nothing to do with script.lua. "Resource not found" means the Resource Is not loaded or it does not exist. If script.lua was missing then it would have output error in debug something like "script.lua file missing". Common sensé.

Link to comment
They were already in .lua and .xml, I have disabled the hiding of file formats in the name.

http://pbrd.co/1cNcMsT This is the error I get when I type 'refresh'.

Open your méta.xml and paste This:

  
<meta> 
<info author="Author" version="1.0" name="Script01" type="script"/> 
<script src="script.lua" type="server"></script> 
</meta> 
  

This will fix it and if still no Luck then I'll help you in teamviewer.

Link to comment
Still having trouble, I'll pm you.

When you go to">Folder and search options>view> scroll down> Now take a screen with snipping tool and post it here also right click on script.lua and click properties and take a screen shot with snipping tool and post it here as well. I got the problem thats why I'm saying this. Anyways also right click on script.lua and rename it script.lua > Now right click on méta.xml and rename it meta.xml

Link to comment
Still having trouble, I'll pm you.

When you go to">Folder and search options>view> scroll down> Now take a screen with snipping tool and post it here also right click on script.lua and click properties and take a screen shot with snipping tool and post it here as well. I got the problem thats why I'm saying this. Anyways also right click on script.lua and rename it script.lua > Now right click on méta.xml and rename it meta.xml

http://pbrd.co/1fGGYr0 I didn't scroll the whole way down I assumed you just wanted to see the "Hide extensions for known file types"

Link to comment
[LUA] LESSON #1 Creating a resource

The wiki tutorial wasn't good enough ?!

https://wiki.multitheftauto.com/wiki/Sc ... ing_script

Do you really think everyone finds this easy? I posted a tut so people can easily understand how to make a Resource. Can't help people who don't even put an effort to create a Resource. Nevermind.

His file is called scipt.lua, when the meta asks for script.lua...

Amateurs.

You beat me. :?

Link to comment
  • Recently Browsing   0 members

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