Scripting Introduction Urdu: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
Ye Scripting Introduction Urdu Meu Originally Translate Ki Gai Hai, Is Meu Kisi Bhi Tarah Ke Translator Ki Madad Nahi Li Gai, Ye Officially Created Ki Gai Hi By [[User:Bilal|Bilal]]. Ye tutorial ab complete hai.
==Lets Start==
Resources mta ka hissa hoti hain. Aik resource main collection of files hoti hain, plus aik meta file hoti hai jo describe karti hai ke kese resource ko load kiye jai aur ye resource kya contain karti hai. Resource ko start bhi kiya ja sakta hai aur stop bhi, aik waqt par aik se zyada bhi scripts chal sakti hain.
Resources mta ka hissa hoti hain. Aik resource main collection of files hoti hain, plus aik meta file hoti hai jo describe karti hai ke kese resource ko load kiye jai aur ye resource kya contain karti hai. Resource ko start bhi kiya ja sakta hai aur stop bhi, aik waqt par aik se zyada bhi scripts chal sakti hain.


Scripting ka sab kuch resource mein hi hota ha. MTA resources ke saath aata hai jo ap apne game mode meu chahain to use kar sakte hain, jese ke map limits jo players ko aik makhsoos area meu play karne ko force karte hain, ya phir deathpickups resource jo player ki death par us ke weapons ko show karti hai.
Scripting ka sab kuch resource mein hi hota ha. MTA resources ke saath aata hai jo ap apne game mode meu chahain to use kar sakte hain, jese ke map limits jo players ko aik makhsoos area meu play karne ko force karte hain, ya phir deathpickups resource jo player ki death par us ke weapons ko show karti hai.
{{tip|Lua scripting ke liye ap ka first step lua editor hona chahiye. Ye scripting ko bohat easy bana deta hai. Ham recommend in ko karte hain, [http://www.sublimetext.com/ Sublime Text], [http://notepad-plus.sourceforge.net/uk/site.htm Notepad++] or [http://luaedit.sourceforge.net/ LuaEdit]. Aik aur unofficial mta sa script editor bhi hai [[MTASE|MTA Script Editor]].}}


{{tip|Lua scripting ke liye ap ka first step lua editor hona chahiye. Ye scripting ko bohat easy bana deta hai. Ham recommend in ko karte hain, [http://www.sublimetext.com/ Sublime Text], [http://notepad-plus.sourceforge.net/uk/site.htm Notepad++] or [http://luaedit.sourceforge.net/ LuaEdit]. Aik aur unofficial mta sa script editor bhi hai [[MTASE|MTA Script Editor]] (In Progress) Ap is ko test kar sakte hain..}}
==Aik Working Script Ko Banana==
 
==Creating a working script==
Sab se pehle ham sekheu ge ke kese aik basic script ko banaya jaata hai jo players ko city ke around walk karne dete hain, Baari baari.
Sab se pehle ham sekheu ge ke kese aik basic script ko banaya jaata hai jo players ko city ke around walk karne dete hain, Baari baari.
===Saari Scripts Kahan Par Hoti Hain?===
===Saari Scripts Kahan Par Hoti Hain?===
Line 12: Line 14:
server/mods/deathmatch/resources/
server/mods/deathmatch/resources/


Aap bohat sey zip files ko dekheu gay jo ke packaged simple scripts hain. Har file aik resource hai. Ye sab khud ba khud unzip ho kar load ho jain gi jese hi mta local servr start ho ga. Aik script banane ke liye simply aik folder create kareu aur is meu jain. Ham "myserver" is tutorial ke liye use kareu gay.
Aap bohat sey zip files ko dekheu gay jo ke packaged simple scripts hain. Har file aik resource hai. Ye sab khud ba khud unzip ho kar load ho jain gi jese hi mta local server start ho ga. Aik script banane ke liye simply aik folder create kareu aur is meu jain. Ham "myserver" is tutorial ke liye use kareu gay.
Ab ap ko is directory mein hona chahiye:  
Ab ap ko is directory mein hona chahiye:  


Line 49: Line 51:
===Script Ko Chalana===
===Script Ko Chalana===
Server ko start karne ke liye, ap ko simply chalana hai excutable jo ke server directory main hai. Stats ki list sab se pehle show ho gi, is baat ka khyaal rakheu ke port number, ap ko game join karne ke liye chahiye ho ga. Phir server saari resources ko load kar leta hai aur phir "Ready to accept connections!"
Server ko start karne ke liye, ap ko simply chalana hai excutable jo ke server directory main hai. Stats ki list sab se pehle show ho gi, is baat ka khyaal rakheu ke port number, ap ko game join karne ke liye chahiye ho ga. Phir server saari resources ko load kar leta hai aur phir "Ready to accept connections!"
Before you connect to the server, you must run the gamemode. Type "start myserver" and press Enter. The server will start the gamemode you just created, and will also show any errors and warnings from this point on. Now you can start the MTA client, and "Quick Connect" using the IP address of your server and the port number you saw earlier. If all goes well, after a few seconds your character will be walking on the streets of Los Santos.
Connect karne se pehle, ap ko gamemode run karna bohat zaroori hai. Type kareu "start myserver" aur enter press kareu. Server gamemode ko start kar de ga jo ap ne abhi banaya, aur ab se koi errors aur warnings bhi show kare ga. Ab ap MTA ko start kareu, aur "Quick Connect" main apnay IP adress se connect kareu. Agar sab kuch theek hota hai, kuch der baad ap ka character streets pe walk kar raha ho ga Los Santos ki.


Next we'll add a command to your script that players can use to spawn a vehicle beside their position. You may skip it and check out more advanced scripting with the [[Map manager|Map Manager]], which continues this tutorial. Another branch from this tutorial is [[Introduction to Scripting GUI]], you may follow it to see how Graphical User Interface in MTA is drawn and scripted.
Ab aage ham command daleu gay jo players vehicle ko spawn karne ke liye use kar sakte hain apne position pe. Ap shaid is ko skip kar deu aur check kareu [[Map manager|Map Manager]], jo is tutorial ko continue karta hai. Is tutorial ki aik aur branch bhi hai, [[Introduction to Scripting GUI]], ap is ko follow kar sakte hain aur pata chala sakte hain ke kese MTA Graphical User Interface MTA meu draw ki jaati hai aur kese script ki jaati hai.


==Creating a simple command==
==Aik Simple Command Ko Banana==
Let's go back to the content of the ''script.lua'' file. As mentioned above, we want to provide a command to create a vehicle beside your current position in the game. Firstly we need to create a function we want to call and a command handler that creates the command the player will be able to enter in the console.
Chaleu ham dobarah ''script.lua'' content meu jaate hain. Jese ke ooper mention kiya, ham chahtay hain ke command par hamaray saath aik vehicle spawn go, sab se pehle hameu aik function banana ho ga, jis ko ham call kareu ge aur aik command handler jo command ko create karta hai.


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create the function the command handler calls, with the arguments: thePlayer, command, vehicleModel
-- Function ko banain, jo command handler ko call karta hai in arguments sey: thePlayer, command, vehicleModel
function createVehicleForPlayer(thePlayer, command, vehicleModel)
function createVehicleForPlayer(thePlayer, command, vehicleModel)
   -- create a vehicle and stuff
   -- Vehicle ko banana aur doosri cheezeu.
end
end


-- create a command handler
-- Command handler ko banana.
addCommandHandler("createvehicle", createVehicleForPlayer)
addCommandHandler("createvehicle", createVehicleForPlayer)
</syntaxhighlight>
</syntaxhighlight>
''Note: Function names are clickable in code examples on the wiki and linked to the functions' documentation.''
''Note: Function names click able hote hain wiki par, in ko click kareu in ke baare meu information haasil karne ke liye''
 
====About command handlers====
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''.


If you have already experience in scripting, you will know that you call a function like this:
====Command Handlers Ke Baare Meu====
Pehla argument command handler ke baare meu command ka name hai jo ke player ko enter karne ke liye allow kare gi. Doosra argument function hai jo ye call kare ga, is case meu ''createVehicleForPlayer''
Agar ap ka already scripting meu experience hai, ap ko is tarah ke function ke baare meu pata ho ga:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
functionName(argument1, argument2, argument3, ..)
functionName(argument1, argument2, argument3, ..)
Line 77: Line 78:
functionName(thePlayer, commandName, argument3, ..)
functionName(thePlayer, commandName, argument3, ..)
</syntaxhighlight>
</syntaxhighlight>
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.
Agar ham gor se dekheu above example ko, ham dekh sakhte hain argument1 jo ke thePlayer hai aur argument2 commandName hai. thePlayer woh hai jis ne command ko type kiya ho ga. Isi liye ap jo bhi isay kaheu, variable contain kare ga player jis ne is command ko activate kiya ho ga. commandName woh hai jo player ne type ki ho gi. Agar woh type kareu "/greet", ye argument contain kare ga "greet". Argument 3 aik extra line hai jo ham ne type ki hai. Ham is ke baare meu seekheu ge thora sa aage. Is ko naa bhooleu ke first 2 arguments, standard arguments hain, lekin ap is ko koi bhi name de sakte hain.


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.
Ham ne call kiya [[addCommandHandler]] ko is way mein aur jab se ''createVeicleForPlayer'' aik function hai, ye bhi us tareeqay se call kiya jaa sakta hai. Lekin ham us ke liye command handler use kar rahe hain, jo ke aik similar manner meu isse call karta hai.
 
Aik example: Koi type karta hai "createvehicle 468" game meu, console meu Sanchez ko spawn karne ke liye, Command handler call karta hai createVehicleForPlayer function ko, jese ''''if'''' ham code ke is line ko script meu leu gay:
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:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
createVehicleForPlayer(thePlayer,"createvehicle","468") -- thePlayer is the player element of the player who entered the command
createVehicleForPlayer(thePlayer,"createvehicle","468") -- thePlayer player element hai, woh jis ne ye command type ki.
</syntaxhighlight>
</syntaxhighlight>
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).
Jese ke ham dekh sakte hain, ye bohat se parameters provide karta hai: woh player jis ne is command ko call ki, woh command jo us ne enter ki aur text us ke baad jo us ko dikha, is case meu "468" vehicle id hai Sanchez ki. Pehle 2 parameters sae hain all command handlers ke saath, jo ke aap read kar sakte hain [[addEventHandler]] page par. Is fact ke liye, aap ko at least 2 parameters ko define karna hota hai jo ap us ke baad use karte hain.


''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.''
''Note: Aap ko command handler ko add karna hota hai, handler function ko define karne ke baad, warne ye isse find nahi kar paai ga.''


====Writing the function====
====Function Ko Write Karna====
In order to fill the function we created, we need to think about what we have to do:
Function ko fill karne ke liye, jo ham ne banaya, hameu sochna pare ga ke hameu kya karna hai:
* Get the players position, so we know where to spawn the vehicle (we want it to appear right beside the player)
* Player ki position ka pata chalana hai, taake hameu pata ho ke ham ne vehicle ko kahan spawn karna hai (Ham chahtay hain ke vehicle player ke saath spawn ho)
* Calculate the position we want to spawn the vehicle at (we don't want it to appear in the player)
* Calucate position ko karna zaroori hai jahan par ham ne vehicle ko spawn karna hai. (Ham nahi chahtay ke vehicle player ke ooper spawn ho)
* Spawn the vehicle
* Vehicle ko spawn karna hai.
* Check if it has been spawned successfully, or output a message
* Check karna hai ke vehicle spawn hua hai ke nahi, aur aik message ko output karna hai.


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.
Apne goals ko achieve karne ke liye, hameu bohat se functions use karne pareu gay. Functions ko find karne ke liye, hameu visit karna chahiye [[Scripting Functions|Sserver Functions List]] Sab se pehle hameu aik function chahiye player ki position ka pata lagaane ke liye. Jab se players elements hain, ham sab se pehle jump karte hain '''Element functions''' jahan par hameu pata chalta hai [[getElementPosition]] function ke baate meu. Function name ko click karne ke baad, hameu function ki description pata chal jai gi. Wahan par ham syntax dekh sakte hain, ye kya return karti hai aur usually aik example. Syntax hameu batata hai ke kon se arguments ham kar sakte hain aur karne hain submit.
 
[[getElementPosition]] ke liye syntax ye hai:
For [[getElementPosition]], the syntax is:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float, float, float getElementPosition ( element theElement )
float, float, float getElementPosition ( element theElement )
</syntaxhighlight>
</syntaxhighlight>


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.
Ye 3 ''float'' function name ke front meu jo hain, ye return type hain. Is case meu, is ka matlab ye hai ke ye function 3 floating point numbers ko return karta hai. (x, y aur z), ap un arguments ko dekh sakte hain jo ap ne submit karne hain. Is case meu sirf element jis ki position ap janana chahtay hain, woh hamari example meu player hai.
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createVehicleForPlayer(thePlayer, command, vehicleModel)
function createVehicleForPlayer(thePlayer, command, vehicleModel)
-- get the position and put it in the x,y,z variables
-- get the position and put x, y, z variables.
-- (local means, the variables only exist in the current scope, in this case, the function)
-- (local ka matlab hai, variables jo only hote hain current scope main, is case meu, the function)
local x,y,z = getElementPosition(thePlayer)
local x,y,z = getElementPosition(thePlayer)
end
end
</syntaxhighlight>
</syntaxhighlight>


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.
Aage ham ye pakka karna chahtay hain ke ye vehicle player ke ooper spawn na ho, is liye ham 5 units add kareu gay ''x'' variable meu, jo vehicle ko player kay east main spawn kare ga.


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createVehicleForPlayer(thePlayer, command, vehicleModel)
function createVehicleForPlayer(thePlayer, command, vehicleModel)
local x,y,z = getElementPosition(thePlayer) -- get the position of the player
local x,y,z = getElementPosition(thePlayer) -- Player ki position ko pata chalanay key liye ye use hota hai.
x = x + 5 -- add 5 units to the x position
x = x + 5 -- 5 units ko add karna hai x meu.
end
end
</syntaxhighlight>
</syntaxhighlight>


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.
Ab hameu aik aur function chahiye jis se aik vehicle spawn ho. Isi liye, aik baar phir ham search kareu gay [[Scripting Functions|Server Functions List]] Jab se ham vehicles kay baare meu baat kar rahe hain, '''Vehicle functions''' section meu, ham choose kareu gay [[createVehicle]] ko. Is function kay syntax meu, hamaray paas sirf aik return type hai, jo ke zyada common hai. Hum ne ye bhi dekha ke kuch arguments [ ] se close huay hain, matlab ye optional hain.
 
Hamaray paas already woh saare arguments hain jo hameu [[createVehicle]] ke liye chahiyain, hamaray function meu. Woh position jo ham ne abhi calculate ki ''x, y, z'' variables main, aur model id jo ham ne provice ki thi command ke through ("createvehicle 468") aur ham function ko access kar sakte hain as ''vehicleModel'' variable.
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.
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createVehicleForPlayer(thePlayer, command, vehicleModel)
function createVehicleForPlayer(thePlayer, command, vehicleModel)
Line 135: Line 131:
</syntaxhighlight>
</syntaxhighlight>


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.
Of course ye code ko improve kiya jaa sakta hai bohat say ways mein, lekin ham aik check banana chahtay hain ke ye vehicle create hui thi ya nahi. Jese ke ham read kar sakte hain [[createVehicle]] page par, '''Returns''' ke neeche, function return hota hai, ''false'', jab ye vehicle ko create nahi kar paya tha. Hum ''createVehicle'' variable ki value ko check karte hain.


Now we have our complete script:
Ab hamare paas poori complete script hai:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function createVehicleForPlayer(thePlayer, command, vehicleModel)
function createVehicleForPlayer(thePlayer, command, vehicleModel)
Line 152: Line 148:
</syntaxhighlight>
</syntaxhighlight>


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]].
Jese ke ap ko pata hai, ham ne aik naya function introduce kiya hai [[outputChatBox]].Ap ab functions ke documentation pages ko khud dekh sakte hain.Zyada advanced scripting kay liye, check kareu [[Map manager|Map Manager]].
==Ap Ko Kya Pata Hona Chahiye==
Ap ne pehle hi resources, command handlers aur functions ko find karne ke baare meu parha hai documentation kay first paragraph mein. Lekin abhi bohat kuch learn karna rahta hai. Ye section ap ko short overview de ga in cheezou kay baate meu, aur related links ko bhi add kiya jai ga.
===Clientside Aur Serverside Scripts===
Shaid ap ne kabhi (server/cilent) kay baare meu suna ho mta sa wiki par. MTA ki kuch coding server sided karni parti hai aur kuch cilent sided. Jese ke aik GUI - Graphical User Interface, kuch cilent sided is liye hoti hain kyun ke woh cilent sided zyada behtar cilentsided kaam karti hain, ya phir server sided sahi tarha kaam nahi karti hain. Lekin zyada tar functions mta ke server sided hi kaam karte hain.


==What you need to know==
Zyada tar scripts jo ap banin gay jese ke gamemodes, maps, server sided hi hon gi, jese ke ham ne likhi thi first section mein. Agar kuch server side kaam nahi karta, to ap ko us ko cilent sided banana ho ga. Cilent Sided script kay liye aap ko ordinary script file create karni ho gi, jis ko ap name deu gay ''cilent.lua'' aur is ko meta meu bhi add kareu gey, is tarah:
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.
===Clientside and Serverside scripts===
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.
 
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:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<script src="client.lua" type="client" />
<script src="client.lua" type="client" />
</syntaxhighlight>
</syntaxhighlight>
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]].
''type'' ko agar aap add nahi kareu gey to woh automatically server side ban jai ga, is liye a ko batana parhey ga ke ye cilent sided script hai meta.xml meu. Cilent sided script download ho jai gi player ke computer meu jab woh join kare ga server ko. Is ke baare meu parhein zyada idhar [[Client side scripts]].


===More complex resources===
===Mushkil Resources Ke Baare Meu===
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:
Pechla section meu briefly explain kar diya hai ke cilent sided scripts ko kese add karte hain resource mein, lekin abhi bohat kuch possible hai. Jese ke ooper bataya, ham kisi bhi tarha ki resource bana sakte hain. Chaleu kuch theortical resources ko dekhte hain. ''meta.xml'' ko dekh kar hameu pata chalta hai ke ye resource kya kar sakti hai.


====First example - A utility script====
====Pehle Example - Utility Script====
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
/admin_commands
/admin_commands
Line 183: Line 178:
</syntaxhighlight>
</syntaxhighlight>


* The ''commands.lua'' provides some admin commands, like banning a player, muting or something else that can be used to admin the server
* ''commands.lua'' admin commands provide karti hai, jese ban karna player ko, mute karna ya kuch aur jo admins kar sakte hain.
* The ''client.lua'' provides a GUI to be able to perform the mentioned actions easily
* ''client.lua'' aik gui provide karti hai jahan se ham actions ko perfom zyada asaani se kar paate hain.


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.
Ye aik example hai jo har waqt run ho rahi hoti hai, aur ye bohat useful hai poorey game mode experience mein aur ye gameplay ke doraan interfere bhi nahi karti, jab tak koi admin action ko perform nahi karta.


====Second example - A gamemode====
====Doosri Example - Aik Gamemode====
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
/counterstrike
/counterstrike
Line 203: Line 198:
</syntaxhighlight>
</syntaxhighlight>


* The ''counterstrike.lua'' contains similiar to the following features:
* ''counterstrike.lua'' contain karta hai neeche diye gayi huay features:
** Let players choose their team and spawn them
** Players ko allow karti hai ke woh apni team ko choose kar paiin.
** Provide them with weapons, targets and instructions (maybe read from a Map, see below)
** Players ko weapons deti hai, targets aur instructions bhi deti hai.
** Define the game's rules, e.g. when does the round end, what happens when a player dies
** Game rules ko define karti hai, example ke tor par kab round end hota hai aur kya hota hai jab player mar jata hai.
** .. and maybe some more
** .. aur shaid more features.
* The ''buymenu.lua'' is a clientside script and creates a menu to buy weapons
* ''buymenu.lua'' aik cilentside script hai jo aik menu ko create karti hai weapons ko buy karne ke liye.


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.
Is example ko game mode kehte hain, jab se ye sirf gameplay se interfere nahi karti, balke rules ko define bhi karti hai. ''type'' batata hai ke ye example work kari hai [[Map manager]] kay saath.
Is ka ye bhi matlab hai ke ye game mode map kay bagair nahi work karta. Gamemode ko hamesha generic hona chahiye. Next example meu aik map start hota hai.


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.
====Teesri Example - Aik Map====
 
====Third example - A Map====
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
/cs-airport
/cs-airport
Line 229: Line 223:
</syntaxhighlight>
</syntaxhighlight>


* The ''airport.map'' in a XML file that provides information about the map to the gamemode, these may include:
* ''airport.map'' XML file information provide karti hai map ke baare meu.
** Where the players should spawn, with what weapons, what teams there are
** Players ko kahan spawn hona chahiye, konse weapons meu hona chahiye.
** What the targets are
** Targets konse hain.
** Weather, World Time, Timelimit
** Weather, World Time, Timelimit
** Provide vehicles
** Vehicles ko provide karna.
* The ''airport.lua'' might contain map-specific features, that may include:
* ''airport.lua'' shaid contain kareu map-specific cheezeu, jin meu shaid hon:
** Opening some door/make something explode when something specific happens
** Kuch cheez ka explode hona agar kuch specific hota hai.
** Create or move some custom objects, or manipulate objects that are created through the .map file
** Custom objects ko banana ya move karna.
** .. anything else map-specific you can think of
** Aur kuch jo ap soch sakte hain..
 
Jese ke ap dekh sakte hain ke ''type'' badal gaya hai 'map' meu, jo hameu bata raha hai ke [[Map manager]] resource aik map hai, jab ke ''gamemodes'' bata raha hai ke ye map valid hai, game mode is example ke ooper hai.
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.
Shaid ap ko ye kuch surprise lage kyun ke aik aur script bhi hai mao resource main. Ofcourse ye necessarily map meu nahi chahiye, lekin ye bohat se possibilities ko open kar deti hai map makers kay liye, ke woh apna world bana paiin.
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.
 
The ''airport.map'' file might look similiar to this:
The ''airport.map'' file might look similiar to this:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Line 259: Line 251:
</syntaxhighlight>
</syntaxhighlight>


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.
Jab koi game mode start hota hai aik map ke saath, map resource khud ba khud start ho jati hai map manager ki waja se aur ye jo information contain karti hai, woh game mode read kar sakta hai. Jab koi map badalta hai, pehle wala map stop ho jata hai aur naya start ho jata hai, zyada explanation ke liye visit kareu [[Writing Gamemodes]] page ko.


===Events===
===Events===
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]].
Events kuch aise cheezeu hain jo mta ko batati hain un cheezou ke baare meu jo hoti hain. Jese ke jab koi player mar jata hai, [[onPlayerWasted]] event ko trigger kiya jaata hai. Agar hameu koi action ko perforum karna hai jab koi player mar jaata hai, ap ko apne aap ko tyaar rakhna hai aik command handler ko dalne ke liye, jese ke is meu hai [[#Aik_Working_Script_Ko_Banana|Sab Se Pehla Chapter]].


This example will output a message with the name of the player who died:
Ye example aik message output kare gi us player ke naam se jo marra ho ga:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function playerDied(totalAmmo, killer, killerWeapon, bodypart)
function playerDied(totalAmmo, killer, killerWeapon, bodypart)
Line 272: Line 264:
</syntaxhighlight>
</syntaxhighlight>


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.
Documentation page Events ka batata hai ke parameters pass kiye jaate hain handler function pe, Is se milta julta aik [[#Command_Handlers_Ke_Baare_Meu|Command Handlers]] har event aik doosre se different hota hai. Aik aur important point hai ''source'' variable, jo ke handler functions meu exist karta hai. Is ko parameter list meu add karne ki koi zaroorat nahi, lekin fir bhi ye exist karta hai. Player events ke liye, (Ooper Example), ye player element hai. Aik aur example ke liye, ap dekh sakte hain pehla section aik idea ke liye ke ''source'' kis tarha use hota hai.


==Where to go from here==
==Yahan Se Ab Kahan Jain?==
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.
Ab ap ko mta ki basic scripting ka pata chal chuka ho gaya ho ga aur thora sa documentation ke baare meu bhi. [[Main Page]] zyada information ke baare meu links deta hai, tutorials jo ap ko allow karte hain ke ap zyada acha learn kar sakeu.
{{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.}}
{{note|Yahan se, ham recommend karte hain ke ap [[debugging]] tutorial parheu. Ache debugging skills necessity hote hain jab ap scripts ko bana rahe hote hain. Ham ap ko [[predefined variables list]] ko parhne ki advice bhi dete hain, ye ap ko certain tasks meu help kare ga.
'''See also:'''
'''See also:'''
* [[Advanced Topics]]
* [[Advanced Topics]]
* [[OOP_Introduction|OOP Scripting Introduction]]
* [[OOP_Introduction|OOP English Scripting Introduction]]
[[es:Introducción a la Programación]]
[[es:Introducción a la Programación]]
[[it:Introduzione allo scripting]]
[[it:Introduzione allo scripting]]

Latest revision as of 06:13, 25 October 2014

Ye Scripting Introduction Urdu Meu Originally Translate Ki Gai Hai, Is Meu Kisi Bhi Tarah Ke Translator Ki Madad Nahi Li Gai, Ye Officially Created Ki Gai Hi By Bilal. Ye tutorial ab complete hai.

Lets Start

Resources mta ka hissa hoti hain. Aik resource main collection of files hoti hain, plus aik meta file hoti hai jo describe karti hai ke kese resource ko load kiye jai aur ye resource kya contain karti hai. Resource ko start bhi kiya ja sakta hai aur stop bhi, aik waqt par aik se zyada bhi scripts chal sakti hain.

Scripting ka sab kuch resource mein hi hota ha. MTA resources ke saath aata hai jo ap apne game mode meu chahain to use kar sakte hain, jese ke map limits jo players ko aik makhsoos area meu play karne ko force karte hain, ya phir deathpickups resource jo player ki death par us ke weapons ko show karti hai.

[[{{{image}}}|link=|]] Tip: Lua scripting ke liye ap ka first step lua editor hona chahiye. Ye scripting ko bohat easy bana deta hai. Ham recommend in ko karte hain, Sublime Text, Notepad++ or LuaEdit. Aik aur unofficial mta sa script editor bhi hai MTA Script Editor.

Aik Working Script Ko Banana

Sab se pehle ham sekheu ge ke kese aik basic script ko banaya jaata hai jo players ko city ke around walk karne dete hain, Baari baari.

Saari Scripts Kahan Par Hoti Hain?

Chaleu, ham script ke file structure ko dekhte hain. Apne MTA Server folder meu jain aur neeche path ko follow kareu:

server/mods/deathmatch/resources/

Aap bohat sey zip files ko dekheu gay jo ke packaged simple scripts hain. Har file aik resource hai. Ye sab khud ba khud unzip ho kar load ho jain gi jese hi mta local server start ho ga. Aik script banane ke liye simply aik folder create kareu aur is meu jain. Ham "myserver" is tutorial ke liye use kareu gay. Ab ap ko is directory mein hona chahiye:

server/mods/deathmatch/resources/myserver/

Identify Resource Ko Karna

Taake server ko pata chale ke ye resource mein kya hai, aik meta.xml file ko create karna bohat zaroori hai. Ye file ko root directory mein hona chahiye, jo ke "myserver" hai hamare case meu. To ab aik text file create kareu aur isay name deu "meta.xml", aur ise open kareu notepad se.

Phir ye walay codes meta.xml file meu enter kar deu:

<meta>
     <info author="YourName" type="gamemode" name="My Server" description="My first MTA server" />
     <script src="script.lua" />
</meta>

Is <info /> tag meu, aik field "type" bhi hai jo batata hai ke ye resource gamemode hai jab ke map' ya phir script nahi hai jo ke later explained kar diya jai ga. Gamemode aik cheez hai jis meu bohat saari scripts hoti hain. <script /> tag batata hai ke is script meu konsi files hain, jo ke ham agge banaain gay.

Aik Simple Script Ko Banana

Is baat ka khyaal rakheu ke <script /> tag aik aur .lua file ke andar nahi hota, ye ussi directory mein hota hai jahan par meta.xml hota hai. Ab ap ye code ko copy aur paste kar sakte hain script.lua mein.

local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
	outputChatBox("Welcome to My Server", source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

Ye script ap ko coordinate (x, y, z) pe saw kare gi, jab ap game ko join kareu gay. Is baat ka khyaal rahe ke fadecamera function zaroor hona chahiye warna ap ko sirf black screen hi dikhai de gi. Is ke saath saath ap camera target bhi set karna ho ga, warna saare players sirf sky ko hi dekh paain ge.

source variable batata hai ke kis ne event ko trigger kiya hai. Jab koi player join karta hai, ap is code ko ye pata lagane ke liye use kar sakte hain ke kis ne join kiya hai. So ye spawn hameu kisi random player pe nahi kare gi.

Agar ham gor se dekhey addEventHandler ko, to ap ko 3 cheezeu nazar aain gi, 'onPlayerJoin', jo batata hai jab event ko trigger kiya jaata hai. 'getRootElement()', jo batata hai ke kya/kis par ye trigger kiya jaa sakta hai. Aur 'joinHandler' jo batata hai ke konsa function trigger ho ga jab ham event ko trigger kareu gay. Aur details agge explain ki jain gi aik aur example main, ab ham server ko start karte hain aur script ko try karte hain!

Script Ko Chalana

Server ko start karne ke liye, ap ko simply chalana hai excutable jo ke server directory main hai. Stats ki list sab se pehle show ho gi, is baat ka khyaal rakheu ke port number, ap ko game join karne ke liye chahiye ho ga. Phir server saari resources ko load kar leta hai aur phir "Ready to accept connections!" Connect karne se pehle, ap ko gamemode run karna bohat zaroori hai. Type kareu "start myserver" aur enter press kareu. Server gamemode ko start kar de ga jo ap ne abhi banaya, aur ab se koi errors aur warnings bhi show kare ga. Ab ap MTA ko start kareu, aur "Quick Connect" main apnay IP adress se connect kareu. Agar sab kuch theek hota hai, kuch der baad ap ka character streets pe walk kar raha ho ga Los Santos ki.

Ab aage ham command daleu gay jo players vehicle ko spawn karne ke liye use kar sakte hain apne position pe. Ap shaid is ko skip kar deu aur check kareu Map Manager, jo is tutorial ko continue karta hai. Is tutorial ki aik aur branch bhi hai, Introduction to Scripting GUI, ap is ko follow kar sakte hain aur pata chala sakte hain ke kese MTA Graphical User Interface MTA meu draw ki jaati hai aur kese script ki jaati hai.

Aik Simple Command Ko Banana

Chaleu ham dobarah script.lua content meu jaate hain. Jese ke ooper mention kiya, ham chahtay hain ke command par hamaray saath aik vehicle spawn go, sab se pehle hameu aik function banana ho ga, jis ko ham call kareu ge aur aik command handler jo command ko create karta hai.

-- Function ko banain, jo command handler ko call karta hai in arguments sey: thePlayer, command, vehicleModel
function createVehicleForPlayer(thePlayer, command, vehicleModel)
   -- Vehicle ko banana aur doosri cheezeu.
end

-- Command handler ko banana.
addCommandHandler("createvehicle", createVehicleForPlayer)

Note: Function names click able hote hain wiki par, in ko click kareu in ke baare meu information haasil karne ke liye

Command Handlers Ke Baare Meu

Pehla argument command handler ke baare meu command ka name hai jo ke player ko enter karne ke liye allow kare gi. Doosra argument function hai jo ye call kare ga, is case meu createVehicleForPlayer Agar ap ka already scripting meu experience hai, ap ko is tarah ke function ke baare meu pata ho ga:

functionName(argument1, argument2, argument3, ..)
functionName(thePlayer, commandName, argument3, ..)

Agar ham gor se dekheu above example ko, ham dekh sakhte hain argument1 jo ke thePlayer hai aur argument2 commandName hai. thePlayer woh hai jis ne command ko type kiya ho ga. Isi liye ap jo bhi isay kaheu, variable contain kare ga player jis ne is command ko activate kiya ho ga. commandName woh hai jo player ne type ki ho gi. Agar woh type kareu "/greet", ye argument contain kare ga "greet". Argument 3 aik extra line hai jo ham ne type ki hai. Ham is ke baare meu seekheu ge thora sa aage. Is ko naa bhooleu ke first 2 arguments, standard arguments hain, lekin ap is ko koi bhi name de sakte hain.

Ham ne call kiya addCommandHandler ko is way mein aur jab se createVeicleForPlayer aik function hai, ye bhi us tareeqay se call kiya jaa sakta hai. Lekin ham us ke liye command handler use kar rahe hain, jo ke aik similar manner meu isse call karta hai. Aik example: Koi type karta hai "createvehicle 468" game meu, console meu Sanchez ko spawn karne ke liye, Command handler call karta hai createVehicleForPlayer function ko, jese 'if' ham code ke is line ko script meu leu gay:

createVehicleForPlayer(thePlayer,"createvehicle","468") -- thePlayer player element hai, woh jis ne ye command type ki.

Jese ke ham dekh sakte hain, ye bohat se parameters provide karta hai: woh player jis ne is command ko call ki, woh command jo us ne enter ki aur text us ke baad jo us ko dikha, is case meu "468" vehicle id hai Sanchez ki. Pehle 2 parameters sae hain all command handlers ke saath, jo ke aap read kar sakte hain addEventHandler page par. Is fact ke liye, aap ko at least 2 parameters ko define karna hota hai jo ap us ke baad use karte hain.

Note: Aap ko command handler ko add karna hota hai, handler function ko define karne ke baad, warne ye isse find nahi kar paai ga.

Function Ko Write Karna

Function ko fill karne ke liye, jo ham ne banaya, hameu sochna pare ga ke hameu kya karna hai:

  • Player ki position ka pata chalana hai, taake hameu pata ho ke ham ne vehicle ko kahan spawn karna hai (Ham chahtay hain ke vehicle player ke saath spawn ho)
  • Calucate position ko karna zaroori hai jahan par ham ne vehicle ko spawn karna hai. (Ham nahi chahtay ke vehicle player ke ooper spawn ho)
  • Vehicle ko spawn karna hai.
  • Check karna hai ke vehicle spawn hua hai ke nahi, aur aik message ko output karna hai.

Apne goals ko achieve karne ke liye, hameu bohat se functions use karne pareu gay. Functions ko find karne ke liye, hameu visit karna chahiye Sserver Functions List Sab se pehle hameu aik function chahiye player ki position ka pata lagaane ke liye. Jab se players elements hain, ham sab se pehle jump karte hain Element functions jahan par hameu pata chalta hai getElementPosition function ke baate meu. Function name ko click karne ke baad, hameu function ki description pata chal jai gi. Wahan par ham syntax dekh sakte hain, ye kya return karti hai aur usually aik example. Syntax hameu batata hai ke kon se arguments ham kar sakte hain aur karne hain submit. getElementPosition ke liye syntax ye hai:

float, float, float getElementPosition ( element theElement )

Ye 3 float function name ke front meu jo hain, ye return type hain. Is case meu, is ka matlab ye hai ke ye function 3 floating point numbers ko return karta hai. (x, y aur z), ap un arguments ko dekh sakte hain jo ap ne submit karne hain. Is case meu sirf element jis ki position ap janana chahtay hain, woh hamari example meu player hai.

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	-- get the position and put x, y, z variables.
	-- (local ka matlab hai, variables jo only hote hain current scope main, is case meu, the function)
	local x,y,z = getElementPosition(thePlayer)
end

Aage ham ye pakka karna chahtay hain ke ye vehicle player ke ooper spawn na ho, is liye ham 5 units add kareu gay x variable meu, jo vehicle ko player kay east main spawn kare ga.

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer) -- Player ki position ko pata chalanay key liye ye use hota hai.
	x = x + 5 -- 5 units ko add karna hai x meu.
end

Ab hameu aik aur function chahiye jis se aik vehicle spawn ho. Isi liye, aik baar phir ham search kareu gay Server Functions List Jab se ham vehicles kay baare meu baat kar rahe hain, Vehicle functions section meu, ham choose kareu gay createVehicle ko. Is function kay syntax meu, hamaray paas sirf aik return type hai, jo ke zyada common hai. Hum ne ye bhi dekha ke kuch arguments [ ] se close huay hain, matlab ye optional hain. Hamaray paas already woh saare arguments hain jo hameu createVehicle ke liye chahiyain, hamaray function meu. Woh position jo ham ne abhi calculate ki x, y, z variables main, aur model id jo ham ne provice ki thi command ke through ("createvehicle 468") aur ham function ko access kar sakte hain as vehicleModel variable.

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer) -- get the position of the player
	x = x + 5 -- add 5 units to the x position
	-- create the vehicle and store the returned vehicle element in the ''createdVehicle'' variable
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
end

Of course ye code ko improve kiya jaa sakta hai bohat say ways mein, lekin ham aik check banana chahtay hain ke ye vehicle create hui thi ya nahi. Jese ke ham read kar sakte hain createVehicle page par, Returns ke neeche, function return hota hai, false, jab ye vehicle ko create nahi kar paya tha. Hum createVehicle variable ki value ko check karte hain.

Ab hamare paas poori complete script hai:

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer) -- get the position of the player
	x = x + 5 -- add 5 units to the x position
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
	-- check if the return value was ''false''
	if (createdVehicle == false) then
		-- if so, output a message to the chatbox, but only to this player.
		outputChatBox("Failed to create vehicle.",thePlayer)
	end
end
addCommandHandler("createvehicle", createVehicleForPlayer)

Jese ke ap ko pata hai, ham ne aik naya function introduce kiya hai outputChatBox.Ap ab functions ke documentation pages ko khud dekh sakte hain.Zyada advanced scripting kay liye, check kareu Map Manager.

Ap Ko Kya Pata Hona Chahiye

Ap ne pehle hi resources, command handlers aur functions ko find karne ke baare meu parha hai documentation kay first paragraph mein. Lekin abhi bohat kuch learn karna rahta hai. Ye section ap ko short overview de ga in cheezou kay baate meu, aur related links ko bhi add kiya jai ga.

Clientside Aur Serverside Scripts

Shaid ap ne kabhi (server/cilent) kay baare meu suna ho mta sa wiki par. MTA ki kuch coding server sided karni parti hai aur kuch cilent sided. Jese ke aik GUI - Graphical User Interface, kuch cilent sided is liye hoti hain kyun ke woh cilent sided zyada behtar cilentsided kaam karti hain, ya phir server sided sahi tarha kaam nahi karti hain. Lekin zyada tar functions mta ke server sided hi kaam karte hain.

Zyada tar scripts jo ap banin gay jese ke gamemodes, maps, server sided hi hon gi, jese ke ham ne likhi thi first section mein. Agar kuch server side kaam nahi karta, to ap ko us ko cilent sided banana ho ga. Cilent Sided script kay liye aap ko ordinary script file create karni ho gi, jis ko ap name deu gay cilent.lua aur is ko meta meu bhi add kareu gey, is tarah:

<script src="client.lua" type="client" />

type ko agar aap add nahi kareu gey to woh automatically server side ban jai ga, is liye a ko batana parhey ga ke ye cilent sided script hai meta.xml meu. Cilent sided script download ho jai gi player ke computer meu jab woh join kare ga server ko. Is ke baare meu parhein zyada idhar Client side scripts.

Mushkil Resources Ke Baare Meu

Pechla section meu briefly explain kar diya hai ke cilent sided scripts ko kese add karte hain resource mein, lekin abhi bohat kuch possible hai. Jese ke ooper bataya, ham kisi bhi tarha ki resource bana sakte hain. Chaleu kuch theortical resources ko dekhte hain. meta.xml ko dekh kar hameu pata chalta hai ke ye resource kya kar sakti hai.

Pehle Example - Utility Script

/admin_commands
	/meta.xml
	/commands.lua
	/client.lua
<meta>
	<info author="Someguy" description="admin commands" />
	<script src="commands.lua" />
	<script src="client.lua" type="client" />
</meta>
  • commands.lua admin commands provide karti hai, jese ban karna player ko, mute karna ya kuch aur jo admins kar sakte hain.
  • client.lua aik gui provide karti hai jahan se ham actions ko perfom zyada asaani se kar paate hain.

Ye aik example hai jo har waqt run ho rahi hoti hai, aur ye bohat useful hai poorey game mode experience mein aur ye gameplay ke doraan interfere bhi nahi karti, jab tak koi admin action ko perform nahi karta.

Doosri Example - Aik Gamemode

/counterstrike
	/meta.xml
	/counterstrike.lua
	/buymenu.lua
<meta>
	<info author="Someguy" description="Counterstrike remake" type="gamemode" />
	<script src="counterstrike.lua" />
	<script src="buymenu.lua" type="client" />
</meta>
  • counterstrike.lua contain karta hai neeche diye gayi huay features:
    • Players ko allow karti hai ke woh apni team ko choose kar paiin.
    • Players ko weapons deti hai, targets aur instructions bhi deti hai.
    • Game rules ko define karti hai, example ke tor par kab round end hota hai aur kya hota hai jab player mar jata hai.
    • .. aur shaid more features.
  • buymenu.lua aik cilentside script hai jo aik menu ko create karti hai weapons ko buy karne ke liye.

Is example ko game mode kehte hain, jab se ye sirf gameplay se interfere nahi karti, balke rules ko define bhi karti hai. type batata hai ke ye example work kari hai Map manager kay saath. Is ka ye bhi matlab hai ke ye game mode map kay bagair nahi work karta. Gamemode ko hamesha generic hona chahiye. Next example meu aik map start hota hai.

Teesri Example - Aik Map

/cs-airport
	/meta.xml
	/airport.map
	/airport.lua
<meta>
	<info author="Someguy" description="Counterstrike airport map" type="map" gamemodes="counterstrike" />
	<map src="airport.map" />
	<script src="airport.lua" />
</meta>
  • airport.map XML file information provide karti hai map ke baare meu.
    • Players ko kahan spawn hona chahiye, konse weapons meu hona chahiye.
    • Targets konse hain.
    • Weather, World Time, Timelimit
    • Vehicles ko provide karna.
  • airport.lua shaid contain kareu map-specific cheezeu, jin meu shaid hon:
    • Kuch cheez ka explode hona agar kuch specific hota hai.
    • Custom objects ko banana ya move karna.
    • Aur kuch jo ap soch sakte hain..

Jese ke ap dekh sakte hain ke type badal gaya hai 'map' meu, jo hameu bata raha hai ke Map manager resource aik map hai, jab ke gamemodes bata raha hai ke ye map valid hai, game mode is example ke ooper hai. Shaid ap ko ye kuch surprise lage kyun ke aik aur script bhi hai mao resource main. Ofcourse ye necessarily map meu nahi chahiye, lekin ye bohat se possibilities ko open kar deti hai map makers kay liye, ke woh apna world bana paiin. The airport.map file might look similiar to this:

<map mode="deathmatch" version="1.0">
	<terrorists>
		<spawnpoint posX="2332.23" posY="-12232.33" posZ="4.42223" skins="23-40" />
	</terrorists>
	<counterterrorists>
		<spawnpoint posX="2334.23443" posY="-12300.233" posZ="10.2344" skins="40-50" />
	</counterterrorists>

	<bomb posX="23342.23" posY="" posZ="" />
	
	<vehicle posX="" posY="" posZ="" model="602" />	
	<vehicle posX="" posY="" posZ="" model="603" />	
</map>

Jab koi game mode start hota hai aik map ke saath, map resource khud ba khud start ho jati hai map manager ki waja se aur ye jo information contain karti hai, woh game mode read kar sakta hai. Jab koi map badalta hai, pehle wala map stop ho jata hai aur naya start ho jata hai, zyada explanation ke liye visit kareu Writing Gamemodes page ko.

Events

Events kuch aise cheezeu hain jo mta ko batati hain un cheezou ke baare meu jo hoti hain. Jese ke jab koi player mar jata hai, onPlayerWasted event ko trigger kiya jaata hai. Agar hameu koi action ko perforum karna hai jab koi player mar jaata hai, ap ko apne aap ko tyaar rakhna hai aik command handler ko dalne ke liye, jese ke is meu hai Sab Se Pehla Chapter.

Ye example aik message output kare gi us player ke naam se jo marra ho ga:

function playerDied(totalAmmo, killer, killerWeapon, bodypart)
	outputChatBox(getPlayerName(source).." died!")
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)

Documentation page Events ka batata hai ke parameters pass kiye jaate hain handler function pe, Is se milta julta aik Command Handlers har event aik doosre se different hota hai. Aik aur important point hai source variable, jo ke handler functions meu exist karta hai. Is ko parameter list meu add karne ki koi zaroorat nahi, lekin fir bhi ye exist karta hai. Player events ke liye, (Ooper Example), ye player element hai. Aik aur example ke liye, ap dekh sakte hain pehla section aik idea ke liye ke source kis tarha use hota hai.

Yahan Se Ab Kahan Jain?

Ab ap ko mta ki basic scripting ka pata chal chuka ho gaya ho ga aur thora sa documentation ke baare meu bhi. Main Page zyada information ke baare meu links deta hai, tutorials jo ap ko allow karte hain ke ap zyada acha learn kar sakeu. {{note|Yahan se, ham recommend karte hain ke ap debugging tutorial parheu. Ache debugging skills necessity hote hain jab ap scripts ko bana rahe hote hain. Ham ap ko predefined variables list ko parhne ki advice bhi dete hain, ye ap ko certain tasks meu help kare ga. See also: