Sign in to follow this  

Where shall I start with learning Lua?

Recommended Posts

Hello I've decided to learn the Lua language, but I don't know where shall I start.

Can you guys tell me where do I start and what should I learn?

I don't know any other scripting or programming languages, I'm beginner at it, I just want to start right now with it.

Share this post

Link to post

Friend, I think you gotta start off with the LUA basics as Wiki doesnt have all of lua.....

Just google lua tutorial and then go to the first topic

after learning the blocks or chunks or functions and all then you gotta go to the mta wiki :)

Soon after that you gotta start making some simple scripts like outputChatBox and others :fadein:

Share this post

Link to post

I just youtubed some videos to get started, after that I started using the wiki and the IRC which helped me ALOT.

Share this post

Link to post

Play with run code and try things like outputChatBox.

For exmaple srun outputChatBox("Tuna")

Share this post

Link to post

The most easy way is looking to code in free scripts, it helped me a lot.

And also trying some things with outputChatBox as Atton said above me.

Then you can try some mathematical things, they are also easy.

Share this post

Link to post
I definitely agree with looking at free resources' code and looking up the functions on the wiki. I had written my first Lua script within hours of setting up my server. Y'all can check it out here and tell me how noobish it is: ... ls&id=8808

That's a good job for your first script!

There are two from my beginnings:

Random Clan Colors:

function teams () 
  team = createTeam("YourTeam") 
  setTimer(randomCOLOR, 5000, 0) 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), teams) 
function movePlayer () 
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin")) then 
  setPlayerTeam(source, team) 
addEventHandler("onPlayerLogin", root, movePlayer) 
function randomCOLOR () 
local R3 = math.random( 0, 255 ) 
local G3 = math.random( 0, 255 ) 
local B3 = math.random( 0, 255 ) 
  setTeamColor(team, R3, G3, B3) 

Date & Time:

function real () 
local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"} 
    local time = getRealTime() 
    local timeINFO = string.format("%02d:%02d:%02d", time.hour, time.minute, time.second) 
    local dateINFO = string.format("%02d/%02d/%04d", time.monthday, time.month+1, time.year+1900)    
    local wd = time.weekday+1 
outputChatBox("#ff8f00------------------------------------------------------------------", 255,255,255,true) 
outputChatBox("#ffffffTime: "..timeINFO, 255,255,255,true) 
outputChatBox("#ffffffDate: "..dateINFO, 255,255,255,true) 
outputChatBox("#ffffffDay: "..days[wd], 255,255,255,true) 
outputChatBox("#ff8f00------------------------------------------------------------------", 255,255,255,true) 
addCommandHandler("date", real ) 

Share this post

Link to post

My frist script was a Deagle Event :D

function mensagemEvento ( ) 
    outputChatBox ( "#00FFFF [sERVER]  To Enter the Event write /participar in chat", getRootElement(), 255, 0, 0, true ) 
addEventHandler ( "onResourceStart", getResourceRootElement ( ), mensagemEvento ) 
function funcoesEvento ( thePlayer ) 
    takeAllWeapons ( thePlayer ) 
    setElementDimension ( thePlayer, 300 ) 
    setPedArmor ( thePlayer, 100 ) 
    setElementHealth ( thePlayer, 569 ) 
    giveWeapon ( thePlayer, 24, 1000000000 ) 
    setElementPosition ( thePlayer, -260.60818481445, 2336.3356933594, 108.55751037598 ) 
    outputChatBox("[EVENTO] You got a Deagle !.",thePlayer,0,255,255) 
    outputChatBox("[EVENTO] You got health & armor.",thePlayer,0,255,255) 
    addEventHandler ( "onPlayerSpawn", thePlayer, onSpawn ) 
addCommandHandler ( "participar", funcoesEvento ) 
function parandoEvento ( ) 
    outputChatBox ( "#00FFFFEvent Closed", getRootElement(), 255, 0, 0, true ) 
addEventHandler ( "onResourceStop", getResourceRootElement ( ), parandoEvento ) 
function onSpawn ( ) 
    takeAllWeapons ( source ) 
    setElementDimension ( source, 300 ) 
    setPedArmor ( source, 100 ) 
    setElementHealth ( source, 569 ) 
    giveWeapon ( source, 24, 1000000000 ) 
    setElementPosition ( source, -260.60818481445, 2336.3356933594, 108.55751037598 ) 

Share this post

Link to post
Isn't the maximal dimension 255?

No, the interior count is 255, you mixed those two ;)

Share this post

Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.