Jump to content

let get started!


Recommended Posts

Ye bohat acha hai ke tum ne scripting shurou kar diya hai, ya phir at least koshis to kar rahe ho.

Meu aik choti se example deta hoon. Examples hi bande ko scripting sikhati hain. Is liye ham aik choti se script banate hain.

Sab se pehle notepad pe jain aur type ye kareu. (File ko meta.xml name deu)

<meta> 
<info author="someguy" type="script" version="1.0.0" name="Some name" /> 
<script src="script.lua" type="server" /> 
</meta> 

Ham aik script banain gay jis se jab player ko join kare ga. Usse aik message dikhai de ga: "Welcome To The Server", is ke liye aap ko ye karna pare ga.

Note: onPlayerJoin aik function nahi hai. Ye aik event hai.

function onJoin() 
         outputChatBox("Welcome To The Server", source, 255, 0, 0) 
end 
addEventHandler("onPlayerJoin", root, onJoin) 

end - function ko end karne ke liye use kiya gaya hai.

Agar aap chahtay hain ke jab aap join kareu to message bhi aai, aur saath saath aap ke wanted level bhi 6 ho jai.

function onJoin() 
         outputChatBox("Welcome To The Server", source, 255, 0, 0) 
         setPlayerWantedLevel(source, 6) 
end 
addEventHandler("onPlayerJoin", root, onJoin) 

Issi tarha aap functions ko add kar sakte hain. Lekin kabhi kabar hameu if ki zaroorat par jati hai. Jese ke, agar ham chaheu ke agar player apni skin 210 pe change kare to woh mar jai.

function onChangeSkin() 
         if getElementModel(source) == 210 then 
          killPed(source) 
else 
         return 
end 
end 
addEvent("onPlayerChangeSkin", true) 
addEventHandler("onPlayerChangeSkin", root, onChangeSkin) 

Aik end function ke liye aur aik end 'if' ke liye

source player element hota hai agar aap player element ko define na karna chaheu.

Jese ke ham kar sakte thay.

function(Player) 

is silsiley meu hamara player element Player hai. Lekin agar ham is ko asay likheu.

function() 

To is meu player element source hai.

Command banana bohat easy hai, jese ke agar aap chahtay hain ke aik command par aap ko aik message show ho aur ap ka wanted level 6 ho jai.

function setMyWantedLevel(Player) 
         setPlayerWantedLevel(Player, 6) 
         outputChatBox("Your Wanted Level Is Now 6!", Player, 255, 0, 0) 
end 
addCommandHandler("youcantgetme", root, setMyWantedLevel) 

Aik aur method bhi hai.

addCommandHandler("youcantgetme", 
     function(Player) 
       setPlayerWantedLevel(Player, 6) 
       outputChatBox("Your Wanted Level Is Now 6!", Player, 255, 0, 0) 
end 
) 

Useful functions ke liye wiki: https://wiki.multitheftauto.com/wiki/Useful_Functions

Kuch na kuch to samajh aai ho gi basic scripting ke baare meu ap ko ab.

Edited by Guest
Link to comment

Aik aur cheez jo meu batana bhool gaya hai woh hai 'math.random'. Agar aap chaheu ke koi cheez random ho is liye ye ap ko help kare ga. Jese ke agar aap chaheu ke jab aap server ko join kareu to ap ki skin 0 se 200 ids meu se aik ho.

function onJoin() 
         setPedSkin(source, math.random(0, 200), true) 
end 
addEventHandler("onPlayerJoin", root, onJoin) 

'true' ya 'false' function ke status ke liye hote hain.

Shukriya.

Link to comment

Yar ya manna script banaye ha dekho ya sai ha.

function onPlayerJoin() 
                      SpawnPlayer  (source, 1959.55, -1714.46, 1  ) 
                      OutputChatBox (“welcome to dash server", source, 0, 255, 0) 
                       giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammo    
                       giveMoney (source, 1000 ) 
AddEventHander (“onPlayerJoin, root, onPlayerJoin”) 
 

Link to comment

Is ko gor se dekho ab.

function onJoin() 
              spawnPlayer(source, 1959.55, -1714.46, 1) 
              giveWeapon(source, 31, 200) 
              givePlayerMoney(source, 1000) 
              outputChatBox("Welcome to dash server", source, 0, 255, 0) 
end 
addEventHandler("onPlayerJoin", root, onJoin) 
  
  

Link to comment

Sorry but I don't PREFER THAT. onPlayerJoinSkin is not even a event. There's onElementModelChange. Bilal stop giving wrong information, you must make that event. I'm sorry if this offended you but indentation is the most important thing. I'm ready to teach you how to indent code's @ moez. Contact me at skype anubhav.agarwal80 whenever you're free!

Now for that you must use this functions!

I'm making a small part for you, you must find out the other.

  
function getVehicleHP() 
     if getElementHealth(source) / 100 > 25 then -- Ye check karta hein vehicle ki health ( vo return hoti hein 1000 if full health ) tho ham usko 100 sa divide karke check karte hein os ki hp low hein ki nahi. 20 ke around vehicle blast ho ja ti. 
           -- ?? WHAT TO DO HERE? It's a mystery! 
     end -- Hamlog if ko end karte hein 
end -- Hamlog function ko end karte hein! 
addEventHandler("onVehicleDamage"", root, getVehicleHP) -- Ye event add kar tha hein getVehicleHP ko. Ye tab hota jab KOI BHI VEHICLE KI HEALTH LOW HOTHI HEIN! 
  
 

Link to comment
function getVehicleHP() 
         if getElementHealth(source) / 100 > 25 then 
         blowVehicle(source) 
         outputChatBox("Vehicle Health Was Very Low!", source, 255, 0, 0) 
else 
         return 
         end 
    end 
    addEventHandler("onVehicleDamage", root, getVehicleHP) 

Mystery filled.

Link to comment

If the upper code is not working, try this one.

function myVehHP() 
         if getElementHealth(source) / 100 > 25 then 
         local vehP = getPedOccupiedVehicle(source) 
         blowVehicle(source, vehP) 
         outputChatBox("Vehicle Health Was Very Low!", source, 255, 0, 0) 
else 
         return 
end 
end 
addEventHandler("onVehicleDamage", root, myVehHP) 

 

Functions ka name likna important ha?

Like function createLoginPanal()

 

Jese ke ooper bataya mene functions ko function ke saath nahi likhna balke next line meu likhna hai. Jese ke:

 

function myVehHP() 
  

myVehHP proper lua function nahi hai. Hameu sirf ye isi liye add karna hota hai taake ham is ko addEventHandler ya addCommandHandler ke saath likhte hain. Jese ke:

addEventHandler("onVehicleDamage", root, myVehHP) 

Link to comment

Aik aur cheez! Agar aap aik apna event banana chahtay hain. (Custom Event) us ke liye aap use kareu.

addEvent("Event Name", true/false) 

Jese ke:

addEvent("onPlayerEnterVehicle", true) 
addEventHandler("onPlayerEnterVehicle", root, functionName) 

Event name sensible hona chahiye.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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