Jump to content

Very basic command


ThePhill97

Recommended Posts

Posted

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?

Posted

By spawn weapons you mean give to the command executer the weapons?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Posted
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. 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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?

Posted

A bit more? how?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I explained what it's doing, don't you see the comments?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...