Advertisement
Guest User

MTA SA Scripting Tutorial 1 The Basics

a guest
Jan 6th, 2012
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. --Okay first of all, this is for all who wants to learn how to script.
  2. --I was too lazy to teach everyone individually how to script, so here are some basics.
  3. --First i want to make sure you understand the differences between client and server,
  4. --I know there are some mistakes in what i script and say sometimes, but i just learn you what i know.
  5.  
  6. --First we are making a little script which gives the player 100 dollar as soon as he types /gimme
  7. --This could be done server and client side.
  8.  
  9.  
  10. --server sided lua
  11. function theServerSidedGimmeCommand (source) --use names like theMovableObject or theWalkingPed to make and keep your script as easy readable as possible
  12. 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
  13. end
  14. addCommandHandler ( "serversidegivecash", theServerSidedGimmeCommand ) --adding the command which executes the function, everything in the function will run as soon as he types /givecash
  15.  
  16.  
  17. --client sided lua
  18. 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
  19. 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
  20. end
  21. addCommandHandler ( "clientsidegivecash", theClientSidedGimmeCommand )
  22.  
  23.  
  24. 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
  25. --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.
  26.  
  27. --This is what the meta.xml file looks like
  28. <meta>
  29. <info author="Tinne_Spoel" name="Example script" version="1.0" type="script"/> --just the name, version, author and type of the script
  30. <script src="script_c.lua" type="client" /> --if you dont add the type=" then the meta will think its a server sided script. I prefer using the type=" always
  31. <script src="script_s.lua" type="server" />
  32. </meta> --don't forget the meta tags
  33.  
  34.  
  35. --Things to remember:
  36. --Never use spaces or things like $*(%&@ in your script names, files or folders. Some of them will give errors.
  37. --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.
  38. --ALWAYS backup every 10 savings or test from your script, it happens you lose your script, delete, rewrite whatever. Just do :P
  39.  
  40.  
  41. --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
  42.  
  43. youtube describtion
  44. --First we are making a little script which gives the player 100 dollar as soon as he types a command
  45. --This could be done server and client side. You have to type the the script over or try to make it yourself after watching the video.
  46.  
  47. --Things to remember:
  48. --Never use spaces or things like $*(%&@ in your script names, files or folders. Some of them will give errors.
  49. --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.
  50. --ALWAYS backup every 10 savings or test from your script, it happens you lose your script, delete, rewrite whatever. Just do :P
  51.  
  52. --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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement