Advertisement
Guest User

xox

a guest
Apr 12th, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.14 KB | None | 0 0
  1. ==Introduction==
  2. Resources Mta का एक महत्वपूर्ण हिस्सा हैं. एक Resources अनिवार्य रूप से फाइलों का एक संग्रह है जिसमें एक फोल्डर या ज़िप फाइल है, plus Resources लोड किया जाना चाहिए कि कैसे सर्वर से वर्णन किया गया है और इसे नियंत्रित करता है क्या फ़ाइलों कि एक मेटा फ़ाइल. इसे शुरू कर दिया जा सकता और बंद कर दिया जा सकता है, और कई Resources में एक बार चला सकते हैं.
  3.  
  4. पटकथा के साथ क्या करने के लिए सब कुछ है कि Resources में होता है. यह एक gamemode , एक नक्शा या कुछ और है कि अगर एक Resource परिभाषित करता है क्या. Mta इस तरह के एक खेल के मैदान के भीतर playings रखने के लिए maplimits या हथियार पिकप बनाने के लिए deathpickups के रूप में आप अपने gamemodes में उपयोग वैकल्पिक कर सकते हैं कि Resources के साथ आता है.
  5. {{tip|Lua scripting शुरू करने के लिए आपका पहला कदम एक Lua editor का उपयोग किया जाना चाहिए. यह Scripting बहुत आसान बना देता है. हम अनुशंसा करते हैं[http://www.sublimetext.com/ Sublime Text], [http://notepad-plus.sourceforge.net/uk/site.htm Notepad++] या [http://luaedit.sourceforge.net/ LuaEdit]. यह भी एक unoficial hai[[MTASE|MTA Script Editor]].}}
  6. आप बाहर का परीक्षण कर सकते हैं.
  7.  
  8. ==एक काम ki स्क्रिप्ट बनान==
  9. हम पहले कदम से शहर , चरण में चारों ओर खिलाड़ी की पैदल दूरी पर देता है कि एक बुनियादी स्क्रिप्ट कैसे बनाने के लिए सीखना होगा।
  10.  
  11. ===जहां सभी scripts क ha रहे हैं?===
  12. स्क्रिप्ट की फ़ाइल संरचना पर एक नज़र रखना। अपने एमटीए सर्वर फ़ोल्डर में जाओ , और नीचे पथ का पालन करें:
  13. सर्वर / Mods / Deathmatch / संसाधन /
  14. आप एमटीए के साथ भेज दिया पैकेज्ड नमूना स्क्रिप्ट हैं जो .zip फ़ाइलें, का एक बहुत देखेंगे। प्रत्येक फ़ाइल एक "संसाधन " है, और यह शुरू होता है जब वे सभी सर्वर द्वारा unzipped और लोड किया जाएगा। अपने खुद के संसाधन बनाने के लिए, बस अपने पसंदीदा नाम से एक फोल्डर बना । हम इस ट्यूटोरियल के लिए " myserver " का उपयोग करेंगे।
  15. अब आप इस निर्देशिका के तहत किया जाना चाहिए :
  16.  
  17. server/mods/deathmatch/resources/myserver/
  18.  
  19. ===अपने resource की पहचान===
  20. सर्वर संसाधन में क्या है यह बताने के लिए आदेश में , एक meta.xml फ़ाइल संसाधन की सामग्री की सूची के लिए बनाया जाना चाहिए। यह हमारे मामले में " myserver " फ़ोल्डर है जो संसाधन के रूट निर्देशिका में स्थित होना चाहिए । तो एक पाठ फ़ाइल बना सकते हैं और " meta.xml " यह नाम है, और नोटपैड के साथ खुला ।
  21. Meta.xml फ़ाइल में निम्नलिखित कोड दर्ज करें:
  22. <code>[xml]
  23. <meta>
  24. <info author="aapkanam" type="gamemode" name="My Server" description="My first MTA server" />
  25. <script src="script.lua" />
  26. </meta>
  27. </code>
  28. < info / > टैग में, संसाधन के बजाय एक नियमित रूप से एक gamemode शामिल है या बाद में समझाया जाएगा , जो एक नक्शा, इंगित करता है कि जो एक "प्रकार" क्षेत्र नहीं है। एक gamemode आप एक स्टैंड-अलोन सर्वर बनाने की जरूरत क्या है ।
  29. < script / > टैग हम अगले पैदा करेगा जो संसाधन , में निहित स्क्रिप्ट फ़ाइलें इंगित करता है।.
  30.  
  31. ===एक साधारण Script बनाना===
  32. इसके बाद के संस्करण < script /> टैग में , .lua फ़ाइल एक और निर्देशिका के अंतर्गत नहीं है कि ध्यान दें। इसलिए हम meta.xml के रूप में एक ही फ़ोल्डर में फाइल बना देंगे। अब आप को कॉपी और script.lua में निम्न कोड पेस्ट कर सकते हैं :
  33. <code>[lua]
  34. local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10
  35. function joinHandler()
  36. spawnPlayer(source, spawnX, spawnY, spawnZ)
  37. fadeCamera(source, true)
  38. setCameraTarget(source, source)
  39. outputChatBox("Welcome to My Server", source)
  40. end
  41. addEventHandler("onPlayerJoin", getRootElement(), joinHandler)
  42. </code>
  43. आप इस खेल में शामिल होने जब ​​स्क्रिप्ट, ऊपर निर्दिष्ट समन्वय (x, y, z ) में आप अंडे जाएगा। FadeCamera समारोह इस्तेमाल किया जाना चाहिए या स्क्रीन काला हो जाएगा कि ध्यान दें। इसके अलावा, DP2 के बाद रिलीज में , आप कैमरे के लक्ष्य निर्धारित करने की जरूरत है (अन्यथा देखेंगे सभी खिलाड़ी नीले आकाश है )।
  44. स्रोत चर घटना शुरू हो जो इंगित करता है। कोड शुरू हो रहा है जब एक खिलाड़ी शामिल हो गया है , इसलिए आप शामिल हो गया है जो देखने के लिए इस चर का उपयोग करें। तो यह बजाय हर किसी की है कि खिलाड़ी या एक यादृच्छिक व्यक्ति अंडे देंगे।
  45. यह आरंभ होता है जब जो इंगित करता है , ' onPlayerJoin ': हम [[addEventHandler]] पर एक करीब देखो है, तो आप तीन चीजें देख सकते हैं । यह चालू किया जा सकता है जो क्या / द्वारा जो दिखाता है getRootElement (), । और घटना शुरू हो जाने के बाद चालू किया जा करने के लिए है कि समारोह में इंगित करता है जो joinHandler , ( getRootElement () सब कुछ / हर कोई है )। अन्य विवरण बाद में एक अन्य उदाहरण में समझाया जाएगा , अब चलो बस सर्वर चलाने के लिए और इसे बाहर की कोशिश करते हैं!
  46.  
  47.  
  48. ===Running the script/स्क्रिप्ट रनिंग===
  49. सर्वर प्राप्त करने के लिए बस सर्वर / निर्देशिका के अंतर्गत निष्पादन योग्य चलाने के लिए, शुरू कर दिया। सर्वर आँकड़े की सूची के पहले दिखाया जाएगा; खेल में शामिल होने के लिए जब आप की आवश्यकता होगी जो पोर्ट संख्या, ध्यान दें। फिर सर्वर Mods / Deathmatch / संसाधन / निर्देशिका के अंतर्गत भार सभी संसाधनों, और फिर "कनेक्शन स्वीकार करने के लिए तैयार हो जाओ!"
  50.  
  51. आप सर्वर से कनेक्ट करने से पहले, आप gamemode चलाना चाहिए। टाइप करें "myserver शुरू" और प्रेस दर्ज करें। सर्वर आपने अभी बनाया gamemode शुरू होगा, और यह भी इस बात से किसी भी त्रुटि और चेतावनियों को दिखाएगा। अब आप एमटीए ग्राहक शुरू, और अपने सर्वर का आईपी पता है और आप पहले देखा था पोर्ट नंबर का उपयोग कर "त्वरित कनेक्ट कर सकते हैं"। सब कुछ ठीकठाक रहा, तो कुछ ही सेकंड बाद अपने चरित्र लॉस सैंटोस की सड़कों पर चलने दिया जाएगा।
  52.  
  53. अगले हम खिलाड़ियों को अपनी स्थिति के बगल में एक वाहन के अंडे के लिए उपयोग कर सकते हैं कि आपकी स्क्रिप्ट के लिए एक कमांड जोड़ देंगे। आप इसे छोड़ और के साथ और अधिक उन्नत पटकथा बाहर की जाँच कर सकते हैं [[Map manager|Map Manager]] इस ट्यूटोरियल जारी है, जो। इस ट्यूटोरियल से एक और शाखा, आप एमटीए में यूजर इंटरफेस खींचा और पटकथा है कि कैसे ग्राफिकल यह देखने के लिए अनुसरण कर सकते हैं [[Introduction to Scripting GUI]] है।
  54.  
  55. ===एक सरल कमांड बनाना===
  56. की ' ' script.lua '' फाइल की सामग्री को वापस करने के लिए चलते हैं। जैसा कि ऊपर कहा , हम इस खेल में अपनी वर्तमान स्थिति के बगल में एक वाहन बनाने के लिए एक आदेश प्रदान करना चाहते हैं । सबसे पहले हम हम कॉल करना चाहते हैं एक समारोह और खिलाड़ी कंसोल में प्रवेश करने में सक्षम हो जाएगा आदेश बनाता है एक आदेश हैंडलर बनाने की जरूरत है ।
  57.  
  58. <code>[lua]
  59. -- create the function the command handler calls, with the arguments: thePlayer, command, vehicleModel
  60. function createVehicleForPlayer(thePlayer, command, vehicleModel)
  61. -- create a vehicle and stuff
  62. end
  63.  
  64. -- create a command handler
  65. addCommandHandler("createvehicle", createVehicleForPlayer)
  66. </code>
  67.  
  68. '' नोट: समारोह के नाम विकी पर कोड के उदाहरण में क्लिक करने योग्य और कार्यों से जुड़े रहे हैं ' प्रलेखन ।''
  69.  
  70. ====About command handlers====
  71. The first argument of [[addCommandHandler]] is the name of the command the player will be able to enter, the second argument is the function this will call, in this case ''createVehicleForPlayer''.
  72.  
  73. If you have already experience in scripting, you will know that you call a function like this:
  74. <code>[lua]
  75. functionName(argument1, argument2, argument3, ..)
  76. </code>
  77. <code>[lua]
  78. functionName(thePlayer, commandName, argument3, ..)
  79. </code>
  80. If we have a closer look on the lower example above, we can see argument1 is thePlayer and argument2 the commandName. thePlayer is simply the one who typed the command, so whatever you call it, the variable will contain the player who activated the command. commandName is simply the command they typed. So if they typed "/greet", this argument will contain "greet". Argument 3 is something extra the player typed, you'll learn it a little bit further in the tutorial. Never forget that the first 2 arguments are standard arguments, but you can name them to anything you want.
  81.  
  82. We called the [[addCommandHandler]] function this way already and since ''createVehicleForPlayer'' is a function too, it can be called that way as well. But we are using a command handler for that, which calls it in a similiar manner, internally.
  83.  
  84. For example: Someone types "createvehicle 468" ingame in the console to spawn a Sanchez, the command handler calls the createVehicleForPlayer function, as '''if''' we would have this line of code in the script:
  85. <code>[lua]
  86. createVehicleForPlayer(thePlayer,"createvehicle","468") -- thePlayer is the player element of the player who entered the command
  87. </code>
  88. As we can see, it provides several parameters: the player who called the command, the command he entered and whatever text he had after that, in this case "468" as vehicle id for the Sanchez. The first two parameters are the same with all command handlers, which you can read on the [[addEventHandler]] page. For this fact, you always have to define at least those two parameters to use any after that (for example to process text that was entered after the command, like in our example the vehicle model id).
  89.  
  90. ''Note: You have to add the command handler AFTER you defined the handler function, else it can't find it. The order of execution matters.''
  91.  
  92. ====Writing the function====
  93. In order to fill the function we created, we need to think about what we have to do:
  94. * Get the players position, so we know where to spawn the vehicle (we want it to appear right beside the player)
  95. * Calculate the position we want to spawn the vehicle at (we don't want it to appear in the player)
  96. * Spawn the vehicle
  97. * Check if it has been spawned successfully, or output a message
  98.  
  99. In order to achieve our goals, we have to use several functions. To find function we need to use, we should visit the [[Scripting Functions|Server Functions List]]. First we need a function to get the players position. Since players are Elements, we first jump to the '''Element functions''' where we find the [[getElementPosition]] function. By clicking on the function name in the list, you get to the function description. There we can see the syntax, what it returns and usually an example. The syntax shows us what arguments we can or have to submit.
  100.  
  101. For [[getElementPosition]], the syntax is:
  102. <code>[lua]
  103. float, float, float getElementPosition ( element theElement )
  104. </code>
  105.  
  106. The three ''float'' in front of the function name are the return type. In this case it means the function returns three floating point numbers. (x, y and z) Within the parentheses, you can see what arguments you have to submit. In this case only the element whose position you want to get, which is the player in our example.
  107.  
  108. <code>[lua]
  109. function createVehicleForPlayer(thePlayer, command, vehicleModel)
  110. -- get the position and put it in the x,y,z variables
  111. -- (local means, the variables only exist in the current scope, in this case, the function)
  112. local x,y,z = getElementPosition(thePlayer)
  113. end
  114. </code>
  115.  
  116. Next we want to ensure that the vehicle won't spawn directly in the player, so we add a few units to the ''x'' variable, which will make it spawn east from the player.
  117.  
  118. <code>[lua]
  119. function createVehicleForPlayer(thePlayer, command, vehicleModel)
  120. local x,y,z = getElementPosition(thePlayer) -- get the position of the player
  121. x = x + 5 -- add 5 units to the x position
  122. end
  123. </code>
  124.  
  125. Now we need another function, one to spawn a vehicle. We once again search for it on the [[Scripting Functions|Server Functions List]], this time - since we are talking about vehicles - in the '''Vehicle functions''' section, where we will choose [[createVehicle]]. In this function's syntax, we only have one return type (which is more common), a vehicle element that points to the vehicle we just created. Also, we see that some arguments are enclosed within [ ] which means that those are optional.
  126.  
  127. We already have all arguments we need for [[createVehicle]] in our function: The position we just calculated in the ''x,y,z'' variables and the model id that we provided through the command ("createvehicle 468") and can access in the function as ''vehicleModel'' variable.
  128.  
  129. <code>[lua]
  130. function createVehicleForPlayer(thePlayer, command, vehicleModel)
  131. local x,y,z = getElementPosition(thePlayer) -- get the position of the player
  132. x = x + 5 -- add 5 units to the x position
  133. -- create the vehicle and store the returned vehicle element in the ''createdVehicle'' variable
  134. local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
  135. end
  136. </code>
  137.  
  138. Of course this code can be improved in many ways, but at least we want to add a check whether the vehicle was created successfully or not. As we can read on the [[createVehicle]] page under '''Returns''', the function returns ''false'' when it was unable to create the vehicle. Thus, we check the value of the ''createVehicle'' variable.
  139.  
  140. Now we have our complete script:
  141. <code>[lua]
  142. function createVehicleForPlayer(thePlayer, command, vehicleModel)
  143. local x,y,z = getElementPosition(thePlayer) -- get the position of the player
  144. x = x + 5 -- add 5 units to the x position
  145. local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
  146. -- check if the return value was ''false''
  147. if (createdVehicle == false) then
  148. -- if so, output a message to the chatbox, but only to this player.
  149. outputChatBox("Failed to create vehicle.",thePlayer)
  150. end
  151. end
  152. addCommandHandler("createvehicle", createVehicleForPlayer)
  153. </code>
  154.  
  155. As you can see, we introduced another function with [[outputChatBox]]. By now, you should be able to explore the function's documentation page yourself. For more advanced scripting, please check out the [[Map manager|Map Manager]].
  156.  
  157. ==What you need to know==
  158. You already read some things about resources, command handlers and finding functions in the documentation in the first paragraph, but there is much more to learn. This section will give you a rather short overview over some of these things, while linking to related pages if possible.
  159. ===Clientside and Serverside scripts===
  160. You may have already noticed these or similiar terms (Server/Client) somewhere on this wiki, mostly in conjunction with functions. MTA not only supports scripts that run on the server and provide commands (like the one we wrote above) or other features, but also scripts that run on the MTA client the players use to connect to the server. The reason for this is, that some features MTA provides have to be clientside (like a GUI - Graphical User Interface), others should be because they work better and still others are better off to be serverside or just don't work clientside.
  161.  
  162. Most scripts you will make (gamemodes, maps) will probably be serverside, like the one we wrote in the first section. If you run into something that can't be solved serverside, you will probably have to make it clientside. For a clientside script for example, you would create a ordinary script file (for example called ''client.lua'') and specify it in the meta.xml, like this:
  163. <code>[xml]
  164. <script src="client.lua" type="client" />
  165. </code>
  166. The ''type'' attribute defaults to 'server', so you only need to specify it for clientside scripts. When you do this, the clientside script will be downloaded to the player's computer once he connects to the server. Read more about [[Client side scripts]].
  167.  
  168. ===More complex resources===
  169. The previous section showed briefly how to add clientside scripts to the resource, but there is also much more possible. As mentioned at the very top of this page, resources can be pretty much everything. Their purpose is defined by what they do. Let's have some theoretical resources, by looking at the files it contains, the ''meta.xml'' and what they might do:
  170.  
  171. ====First example - A utility script====
  172. <code>[xml]
  173. /admin_commands
  174. /meta.xml
  175. /commands.lua
  176. /client.lua
  177. </code>
  178. <code>[xml]
  179. <meta>
  180. <info author="Someguy" description="admin commands" />
  181. <script src="commands.lua" />
  182. <script src="client.lua" type="client" />
  183. </meta>
  184. </code>
  185.  
  186. * The ''commands.lua'' provides some admin commands, like banning a player, muting or something else that can be used to admin the server
  187. * The ''client.lua'' provides a GUI to be able to perform the mentioned actions easily
  188.  
  189. This example might be running all the time (maybe even auto-started when the server starts) as it's useful during the whole gaming experience and also wont interfere with the gameplay, unless an admin decides to take some action of course.
  190.  
  191. ====Second example - A gamemode====
  192. <code>[xml]
  193. /counterstrike
  194. /meta.xml
  195. /counterstrike.lua
  196. /buymenu.lua
  197. </code>
  198. <code>[xml]
  199. <meta>
  200. <info author="Someguy" description="Counterstrike remake" type="gamemode" />
  201. <script src="counterstrike.lua" />
  202. <script src="buymenu.lua" type="client" />
  203. </meta>
  204. </code>
  205.  
  206. * The ''counterstrike.lua'' contains similiar to the following features:
  207. ** Let players choose their team and spawn them
  208. ** Provide them with weapons, targets and instructions (maybe read from a Map, see below)
  209. ** Define the game's rules, e.g. when does the round end, what happens when a player dies
  210. ** .. and maybe some more
  211. * The ''buymenu.lua'' is a clientside script and creates a menu to buy weapons
  212.  
  213. This example can be called a gamemode, since it not only intereferes with the gameplay, but actually defines the rules of it. The ''type'' attribute indicates that this example works with the [[Map manager]], yet another resource that was written by the QA Team to manage gamemodes and map loading. It is highly recommended that you base your gamemodes on the techniques it provides.
  214.  
  215. This also means that the gamemode probably won't run without a map. Gamemodes should always be as generic as possible. An example for a map is stated in the next example.
  216.  
  217. ====Third example - A Map====
  218. <code>[xml]
  219. /cs-airport
  220. /meta.xml
  221. /airport.map
  222. /airport.lua
  223. </code>
  224. <code>[xml]
  225. <meta>
  226. <info author="Someguy" description="Counterstrike airport map" type="map" gamemodes="counterstrike" />
  227. <map src="airport.map" />
  228. <script src="airport.lua" />
  229. </meta>
  230. </code>
  231.  
  232. * The ''airport.map'' in a XML file that provides information about the map to the gamemode, these may include:
  233. ** Where the players should spawn, with what weapons, what teams there are
  234. ** What the targets are
  235. ** Weather, World Time, Timelimit
  236. ** Provide vehicles
  237. * The ''airport.lua'' might contain map-specific features, that may include:
  238. ** Opening some door/make something explode when something specific happens
  239. ** Create or move some custom objects, or manipulate objects that are created through the .map file
  240. ** .. anything else map-specific you can think of
  241.  
  242. As you can see, the ''type'' attribute changed to 'map', telling the [[Map manager]] that this resource is a map, while the ''gamemodes'' attribute tells it for which gamemodes this map is valid, in this case the gamemode from the above example.
  243. What may come as a surprise is that there is also a script in the Map resource. Of course this is not necessarily needed in a map, but opens a wide range of possibilities for map makers to create their own world within the rules of the gamemode they create it for.
  244.  
  245. The ''airport.map'' file might look similiar to this:
  246. <code>[xml]
  247. <map mode="deathmatch" version="1.0">
  248. <terrorists>
  249. <spawnpoint posX="2332.23" posY="-12232.33" posZ="4.42223" skins="23-40" />
  250. </terrorists>
  251. <counterterrorists>
  252. <spawnpoint posX="2334.23443" posY="-12300.233" posZ="10.2344" skins="40-50" />
  253. </counterterrorists>
  254.  
  255. <bomb posX="23342.23" posY="" posZ="" />
  256.  
  257. <vehicle posX="" posY="" posZ="" model="602" />
  258. <vehicle posX="" posY="" posZ="" model="603" />
  259. </map>
  260. </code>
  261.  
  262. When a gamemode is started with a map, the map resources is automatically started by the mapmanager and the information it contains can be read by the gamemode resource. When the map changes, the current map resource is stopped and the next map resource is started. For a more in-depth explanation and examples of how map resources are utilized in the main script, please visit the [[Writing Gamemodes]] page.
  263.  
  264. ===Events===
  265. [[Event|Events]] are the way MTA tells scripts about things that happen. For example when a player dies, the [[onPlayerWasted]] event is triggered. In order to perform any actions when a player dies, you have to prepare yourself similiar to adding a command handler, as shown in [[#Writing_the_script|the first chapter]].
  266.  
  267. This example will output a message with the name of the player who died:
  268. <code>[lua]
  269. function playerDied(totalAmmo, killer, killerWeapon, bodypart)
  270. outputChatBox(getPlayerName(source).." died!")
  271. end
  272. addEventHandler("onPlayerWasted",getRootElement(),playerDied)
  273. </code>
  274.  
  275. Instead of showing what arguments are needed, the documentation page for Events shows what parameters are passed to the handler function, similiar to the way a [[#About_command_handlers|command handler]] does, just that it is different from event to event. Another important point is the ''source'' variable, that exists in handler functions. It doesn't have to be added to the parameter list of the function, but it still exists. It has a different value from event to event, for player events (as in the example above) it is the player element. As another example, you can take a look at the basic spawning player script in the first section to get an idea how ''source'' is used.
  276.  
  277. ==Where to go from here==
  278. You should now be familiar with the most basic aspects of MTA scripting and also a bit with the documentation. The [[Main Page]] provides you with links to more information, Tutorials and References that allow a deeper look into the topics you desire to learn about.
  279. {{note|From here we recommend reading the [[debugging]] tutorial. Good debugging skills are an absolute necessity when you are making scripts. We also recommend you to use the [[predefined variables list]] to help you with certain tasks and make scripting easier and faster.}}
  280. '''See also:'''
  281. * [[OOP_Introduction|OOP Scripting Introduction]]
  282. * [[Advanced Topics]]
  283. * [[Script_security|Script security]]
  284. * [[Scripting Introduction Urdu]]
  285. [[es:Introducción a la Programación]]
  286. [[it:Introduzione allo scripting]]
  287. [[nl:Scripting_introductie]]
  288. [[pt-br:Introdução ao Scripting]]
  289. [[ru:Scripting Introduction]]
  290. [[ar:مقدمه_في_البرمجه]]
  291. [[zh-cn:脚本编写介绍]]
  292. [[Category:Tutorials]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement