Hell-Mate Posted March 14, 2014 Share Posted March 14, 2014 Hello community ,, today i decided to make a simple tutorial for MTA beginner scripters i hope that this tutorial help them to start their scripting life. Okay first of all i recommend all beginners to start learning the basic of LUA and try to understand every basic thing then start to learn much harder things. Basic tutorial to start with :- -------------------------------------- 1 ) What is Programming ? ( Not recommended but you have to know what is programming ) 2 ) The Editor. ( Tools you can use when scripting. ) 3 ) Variables in LUA. ( 100% Recommended ) 4 ) LUA – Mathematics ( Recommended but not now ! you will use it later when jumping from beginner level. ) 5 ) Comments - Keywords ( Just read. ) 6 ) Operations of Comparison / Logical Operations( 50% Recommended ) 7 ) Chunks / Blocks ( Must read !! 100% Recommended ) 8 ) Strings ( Read this later ) 9 ) Loops ( Must read !! 100% Recommended. ) 10 ) Conditional Structures ( Must read carefully !! ) 11 ) Tables ( Very useful in MTA LUA Scripting. Must read !! ) 12 ) Functions ( Totally recommended. i call this god of LUA. MUST READ !! ) ______________________________________________________________________________________________________________ MTA LUA Basic scripting _______________________ Questions and Answers :- --------------------------------- 1) Who is you fellow scripter that can help you with any function you forgot ? - MTA Wiki is ! 2 ) Program to use in writing MTA LUA in an easier way ? - MTA Script editor is. 3 ) Why i have to use MTA Script editor ? - It will help u to script in an easier way as it have auto complete function name feature. 4 ) Can i add more than one event for one function ? - Yes you can. 5 ) How to protect my scripts from hackers ? - you can use MTA compiler or use exports. 6 ) How to export ? - [TUT] How to export << This TUT will help ! 7 ) What is the difference between commands and events ? - Command will call the function when the player write the command but event will call the function when the player do something. ----------------------------------------------------------------------------------------------------------------------------------------------------------------- MTA Basic scripts ( Read Comments ) ---------------------------------------------------- 1 ) Creating a useful event. ourMarker = createMarker(x, y, z,"cylinder",2,0,150,255,255) -- Created a marker called ourMarker. dont forget to replace x, y, z with you co-ordinates function tutorial () -- creating a function called tutorial -- add function bodies here ( what the marker do when the player hits the marker ? ) end -- to end the function. addEventHandler ( "onMarkerHit", ourMarker, tutorial ) -- translate : when the player hit ourMarker call tutorial function. onMarkerHit is the Event. you know more about Events at MTA Wiki 2 ) Creating a useful command. function tutorial () --Created a function called tutorial -- add function bodies here ( what the function do when thePlayer write the Command ) end -- to end the function. addCommandHandler ( "CommandHere", tutorial ) -- translate : when the player write the command /CommandName it will call tutorial function. CommandHere is the Command. ----------------------------------------------------------------------------------------------------------------------------------------------------------------- Some useful scripts :- --------------------------- How to create a moving gate ? Tools we need : 1) x,y,z of the gate. 2) x,y,z of the gate after moving. 3) time in mili seconds in which the gate will open. 4) colshape to open the gate when the player hit the colshape. ( you can also use marker ) 5) onColShapeHit Event. ( you can also use onMarkerHit ) 6) onColShapeLeave Event. ourGate = createObject (objectIDOrTheGateID, x, y, z, rX, rY, rZ) -- change x,y,z to the gate co-ordinates, change rX,rY,rZ to the gate rotation co-ordinates. and for sure change objectIDOrTheGateID to the gate ID. ourColShape = createColCircle (x, y, z) -- change x,y,z to the x,y,z of the ColCirle function opendagate() moveObject (ourGate, timeInMiliSeconds, x, y, z) -- change x,y,z to co-ordinates of the gate after moving. and timeInMili seconds to time which the gate will open. for ex: 1000 : the gate will open after a second when the player hit the colShape. end addEventHandler("onColShapeHit", ourColShape, opendagate) function closedagate() moveObject (ourGate, timeInMiliSeconds, x, y, z) -- change x,y,z to co-ordinates of the gate normal position of the gate to close it. and timeInMili seconds to time which the gate will close. for ex: 1000 : the gate will close after a second when the player leave the colShape. end addEventHandler("onColShapeLeave", ourColShape, closedagate) Will add more useful scripts in the next topic update .. ______________________________________________________________________________________________________________ Thanks for reading and i hope all enjoyed. 1 Link to comment
Dude' Posted March 14, 2014 Share Posted March 14, 2014 Thanks FaDy-Jo for your time Great TUT Link to comment
Woovie Posted March 17, 2014 Share Posted March 17, 2014 Everyone stop being assholes. If you have feedback, at least be nice about it. No need for name-calling. This isn't pre-k. How to post: Use "Lua" instead of "LUA". It is a proper noun, not an acronym. How not to post: omfg u fuggin idiet use Lua becuz LUA is wrong Link to comment
IcyBar Posted July 22, 2015 Share Posted July 22, 2015 Could you update those links? They are not working anymore Link to comment
Skarbonke Posted June 18, 2017 Share Posted June 18, 2017 hmm, the gate is here, but it isn't moving, why? local tempCol = createColSphere ( -2696.5, -1.3999999761581, 3.2999999523163, 10.0 ) ourGate = createObject (980, -2696.6999511719, -1.7000000476837, 6.0999999046326, 0, 0, 90) -- change x,y,z to the gate co-ordinates, change rX,rY,rZ to the gate rotation co-ordinates. and for sure change objectIDOrTheGateID to the gate ID. ourColShape = createColCircle (-2696.5, -1.3999999761581, 3.2999999523163, 10.0) -- change x,y,z to the x,y,z of the ColCirle function opendagate() moveObject (ourGate, 2000, -2696.6999511719, -13.2, 6.0999999046326) -- change x,y,z to co-ordinates of the gate after moving. and timeInMili seconds to time which the gate will open. for ex: 1000 : the gate will open after a second when the player hit the colShape. end addEventHandler("onColShapeHit", ourColShape, opendagate) function closedagate() moveObject (ourGate, 2000, -2696.6999511719, -1.7000000476837, 6.0999999046326) -- change x,y,z to co-ordinates of the gate normal position of the gate to close it. and timeInMili seconds to time which the gate will close. for ex: 1000 : the gate will close after a second when the player leave the colShape. end addEventHandler("onColShapeLeave", ourColShape, closedagate) Link to comment
Skarbonke Posted June 19, 2017 Share Posted June 19, 2017 lol, i fixed it, but when the gate opens- my game crashes, why is it? Link to comment
pa3ck Posted June 19, 2017 Share Posted June 19, 2017 You shouldn't ask questions like this in the tutorial section... Please take your code and post it to this section: https://forum.multitheftauto.com/forum/71-scripting/ Before posting, make sure you also look at this post: Link to comment
Recommended Posts