Jump to content

Noob in a need of help.


Heisenberg

Recommended Posts

Hello!

I started learning lua scripting just a couple of days ago and it seems hard for me to get started since I don't know how different functions and stuff work.

I was just wondering if anyone could give me some advices to get started. I know something about spawning weapons but I'd like to know how to make a simple weapon buying system. Nothing special just that I'm able to decide wich weapon I want and that when I type in the command, it takes some amount of my money.

I would also like to know how to create some kinds of goods in the game, for example materials or drugs. And to be able to build some kind of a buying/selling system for them.

If someone could hit me up with a script or something to get me started, I'd preciate it.

Link to comment

Hang on, before everyone is turning crazy and talk shit on your head. I'll make a small example of that weapon stuff. :)

Try this, commented and ready. You might find this usefull!

addCommandHandler("bWeapon", 
    function ( source, command, weapon ) -- the function will get 1 parameter, the source is the player that uses the command, the command is which command has been used. 
        -- before you do anything with the code itself, make sure all the parameter are filled!! 
        if ( ( weapon ) and ( tonumber ( weapon ) ) ) then 
            -- if the paramater is filled, we continue. 
             
            -- first we will create some local variables that will clean up the code abit 
            local money = getPlayerMoney ( source ); 
             
            -- secondly we create an "array" holding the ID and the price of 1 clip. 
            local weapons = { 
                            { "1", "50" }, -- Brass Knuckles 
                            { "22", "150" }, -- Pistol 
                            { "23", "175" }, -- Silencer 
                            { "24", "250" }} -- Desert Eagle 
                             
            -- after that, we create a for-loop to see if the chosen weapon is in the list 
            for index, item in ipairs ( weapons ) do 
                if ( item[0] == tonumber( weapon ) ) then -- make sure you use tonumber, else it will crash the script here. 
                    if ( money >= item[2] ) then -- if the player has the required ammount of money 
                        takePlayerMoney ( item[2] ); -- take the players money 
                        giveWeapon ( source, item[1], 50 ); -- give the weapon + 50 ammo 
                    end 
                else 
                    outputChatBox( "You dont got enough money!", source ); -- tell them they dont have enough money 
                end 
            end 
        else  
            outputChatBox( "Wrong usage, example: /bWeapon ", source ); -- tell them they used the command wrong. 
            return; -- quit the entire operation! 
        end 
    end 
); 

Link to comment

A parameter is nothing but a pre-defined variable thats being filled in while using a function. If you're working with a function that needs a true/false back to check something, like isPedInVehicle (its a function). To tell the system that its a function, you have to add " ( ) " after the name of the function. Inside these 2 brackets, you place paramaters. For example; isPedInVehicle( thePlayer ). That is also being done with commands that require more arguments then just the name of the command.

You got commands like;

/help, which doesn't take any other arguments and does something.

/ss 29, this commands (freeroam command) requires 1 argument. /ss is the command, and 29 is the first argument. If you would open the function it will look something like this;

function changeSkin (player, command, skinID) 

The "player" parameter is the element that triggered the command, the "command" parameter is the command name thats being triggered. The "skinID" parameter is the argument the player said in the command (in this example, its 29).

So whenever you trigger a command that requires arguments, its nothing more then the command name + another word/number/letter.

/ss 29 (command: ss / parameter: 29)

/cv 422 (command: cv / parameter: 422)

setElementPosition(0, 0, 15) (function: setElementPosition / parameter1: 0 / parameter2: 0 / parameter3: 15 )

Get it?:)

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