ThePhill97 Posted January 6, 2013 Share Posted January 6, 2013 Hello, I'm attempting to learn MTAs 'lua' and I need an example command, I was following the WIKI, I made a spawn car command, however they didn't explain it very well and I couldn't analyse it. Can somebody please post a easy command. EG: Spawn weapons? and explain it in detail? Link to comment
Castillo Posted January 6, 2013 Share Posted January 6, 2013 By spawn weapons you mean give to the command executer the weapons? Link to comment
ThePhill97 Posted January 6, 2013 Author Share Posted January 6, 2013 By spawn weapons you mean give to the command executer the weapons? Yes eg: /w [weaponid] [ammoamount] givesthe weapon to the executer with specified ammo or something? or /w [weaponid] give default 500 bullets for each spawn i dunno Link to comment
Castillo Posted January 6, 2013 Share Posted January 6, 2013 addCommandHandler ( "w", function ( thePlayer, _, weaponID ) local weaponID = tonumber ( weaponID ) -- Convert the 'weaponID' argument value to a number. if ( weaponID ) then -- Check if the 'weaponID' is really a number. giveWeapon ( thePlayer, weaponID, 500, true ) -- Give the weapon and set it as current to the player who used the command. else -- If the 'weaponID' wasn't really a number... outputChatBox ( "Specify a weapon ID.", thePlayer, 255, 0, 0 ) -- Output it to the player's chat. end -- Close the 'if'. end -- Close the function. ) Link to comment
ThePhill97 Posted January 6, 2013 Author Share Posted January 6, 2013 addCommandHandler ( "w", function ( thePlayer, _, weaponID ) local weaponID = tonumber ( weaponID ) -- Convert the 'weaponID' argument value to a number. if ( weaponID ) then -- Check if the 'weaponID' is really a number. giveWeapon ( thePlayer, weaponID, 500, true ) -- Give the weapon and set it as current to the player who used the command. else -- If the 'weaponID' wasn't really a number... outputChatBox ( "Specify a weapon ID.", thePlayer, 255, 0, 0 ) -- Output it to the player's chat. end end ) Can you explain function ( thePlayer, _, weaponID ) local weaponID = tonumber ( weaponID ) -- Convert the 'weaponID' argument value to a number. abit more? Link to comment
ThePhill97 Posted January 6, 2013 Author Share Posted January 6, 2013 A bit more? how? Explain what its doing and stuff? Its just writing to me right now Link to comment
Castillo Posted January 6, 2013 Share Posted January 6, 2013 I explained what it's doing, don't you see the comments? Link to comment
ThePhill97 Posted January 6, 2013 Author Share Posted January 6, 2013 I explained what it's doing, don't you see the comments? Yes, but what is function ( thePlayer, _, weaponID ) Explain.. thePlayer? _? Link to comment
Castillo Posted January 6, 2013 Share Posted January 6, 2013 thePlayer = who used the command. _ = the command name, I named the argument like this because I was not using, I could have named it anything else anyway. Link to comment
ThePhill97 Posted January 6, 2013 Author Share Posted January 6, 2013 thePlayer = who used the command._ = the command name, I named the argument like this because I was not using, I could have named it anything else anyway. Thats cleared things up, thanks. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now