Jump to content

Where shall I start with learning Lua?


Aveee

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.

Link to comment

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:

Link to comment
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: https://community.multitheftauto.com/index.php?p= ... 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) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), teams) 
function movePlayer () 
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin")) then 
  setPlayerTeam(source, team) 
  end 
end 
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) 
end 

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) 
end 
addCommandHandler("date", real ) 

Link to comment

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 ) 
end 
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 ) 
end 
addCommandHandler ( "participar", funcoesEvento ) 
  
function parandoEvento ( ) 
    outputChatBox ( "#00FFFFEvent Closed", getRootElement(), 255, 0, 0, true ) 
end 
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 ) 
end 

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