Jump to content

MTA SA Scripting Tutorial 1: The Basics


Recommended Posts

Heey guys, some people asked me how to script and i learned 2 people how to, but it was a pain in the ass... So i decided to make a little video how to make your first script. The video is horrible but the testing part at 00:30 is very useful. Just read this or the youtube description. :)


--Okay first of all, this is for all who wants to learn how to script.

--I was too lazy to teach everyone individually how to script, so here are some basics.

--First i want to make sure you understand the differences between client and server,

--I know there are some mistakes in what i script and say sometimes, but i just learn you what i know.

--First we are making a little script which gives the player 100 dollar as soon as he types a command

--This could be done server and client side.

--server sided lua

function theServerSidedGimmeCommand (source) --use names like theMovableObject or theWalkingPed to make and keep your script as easy readable as possible 
    givePlayerMoney ( source, 100 ) --give's the source player (the player who executes the function, can be done with various events, commands and binds) 100 dollar when he executes the function 
addCommandHandler ( "serversidegivecash", theServerSidedGimmeCommand  ) --adding the command which executes the function, everything in the function will run as soon as he types serversidegivecash 

--client sided lua

function theClientSidedGimmeCommand () --use different names for EVERY function, so you and the script won't get confused, also for every, example: myPed = createped use different names like myPed1 and myPed2 
    givePlayerMoney ( 100 ) --in client side scripts the player who executes the function is always the source player, so no need for the source argument here 
addCommandHandler ( "clientsidegivecash", theClientSidedGimmeCommand  ) 
fileDelete("script_name.lua") --use this to maximum protect your scripts, only add this at the very last line of your script. As soon as a player joins he downloads the scripts 
                              --but will be deleted right away. The only downside of this trick is that the player needs to download this client lua everytime he join the server. 

--This is what the meta.xml file looks like

    "Tinne_Spoel" name="Example script" version="1.0" type="script"/> --just the name, version, author and type of the script 

--Things to remember:

--Never use spaces or things like $*(%&@ in your script names, files or folders. Some of them will give errors.

--Server events or functions cant be used in client lua's and vice versa. You do have some events and functions which are both client and server sided.

--ALWAYS backup every 10 savings or test from your script, it happens you lose your script, delete, rewrite whatever. Just do :P

--Now put the server sided function in the server lua, the client sided function in the client lua and the meta stuff in the meta.xml


Notepad++: http://www.notepad-plus-plus.org/download/v5.9.8.html

The entire tutorial: http://pastebin.com/m1Bj5v3a

MTA SA: http://www.mtasa.com/

Good luck with your own scripts!

Edited by Guest
Link to comment
  • Recently Browsing   0 members

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