# Functions

{% hint style="info" %}
This feature is available from the version **1.0.1**
{% endhint %}

We can add items or licenses to player using our system instead of reinventing the wheel.

You need to paste the function into the onResult function, specifically in the `data.result == "passed"`, like this:

{% code title="config.lua" %}

```lua
...
       OnResult = function(data)
            -- Data contains the following values:
            --     id (number) - quiz id
            --     percent (number) - percentage of correct answers
            --     result (string) - result (passed/failed)
            -- EXAMPLE:
            if data.result == "passed" then
                -- PASTE THE FUNCTION HERE! <---
            else
                print("You failed the quiz!")
                print(data.percent .. " % of your answers were correct!")
            end
        end,
    },
```

{% endcode %}

## Give Item

We don't want hacker to be able to give themselves an item so we created a feature to whitelist certain items and assign an unique id to them.

{% code title="item\_list.lua" lineNumbers="true" %}

```lua
ItemList = {
    [1] = {
        itemName = "exampleItem",
        maxAmount = 1, -- Maximum amount of the item that can be given on each use
    },
    [2] = {
        itemName = "drivingLicense",
        maxAmount = 1, -- Maximum amount of the item that can be given on each use
    },
    -- 3 and so on. Dont forget to add a comma after each item
}
```

{% endcode %}

We can add as much items as we want, but make sure the ids are not same.

| Value     | Explanation                                                  |
| --------- | ------------------------------------------------------------ |
| itemName  | name of the item that will be given to the players inventory |
| maxAmount | **maximum** amount of items added on each exam pass          |

Now we just need to add our function to the config

<pre class="language-lua" data-title="config.lua" data-line-numbers><code class="lang-lua">OnResult = function(data)
            -- Data contains the following values:
            --     id (number) - quiz id
            --     percent (number) - percentage of correct answers
            --     result (string) - result (passed/failed)
            -- EXAMPLE:
            if data.result == "passed" then
            
            local itemId = 1 -- The id in the item_list.lua
            local amount = 1 -- amount given to the player. Don't forget about the limits you specified in the item_list.lua
            <a data-footnote-ref href="#user-content-fn-1">Basics.GiveItem(itemId, amount) -- &#x3C;-- This one</a>
            
            else
                print("You failed the quiz!")
                print(data.percent .. " % of your answers were correct!")
            end
        end,
</code></pre>

## Give license

{% code title="config.lua" lineNumbers="true" %}

```lua
OnResult = function(data)
            -- Data contains the following values:
            --     id (number) - quiz id
            --     percent (number) - percentage of correct answers
            --     result (string) - result (passed/failed)
            -- EXAMPLE:
            if data.result == "passed" then
               
               local license = "DMV" -- Which license you want to add
               Basics.AddLicense(license) -- <-- Add this function
               
            else
                print("You failed the quiz!")
                print(data.percent .. " % of your answers were correct!")
            end
        end,
```

{% endcode %}

[^1]:
