# giveWeapon (Server)

> Gives a weapon with ammo to a ped or player.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Peds
- **URL**: https://wiki.mymp.gg/en/giveWeapon

## Syntax

```lua
bool giveWeapon(ped ped, string weapon [, int ammo = 30, bool setAsCurrent = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `ped` | `ped` | The ped or player. |
| `weapon` | `string` | The weapon's name in the pack's weapon metadata, such as `PISTOL` or `AK47`. Case does not matter. |
| `ammo` | `int` | Ammo to give. *(default: `30`)* |
| `setAsCurrent` | `bool` | `true` to switch to the weapon at once. *(default: `false`)* |

## Returns

`true` if the weapon was given. `false` if the weapon name is unknown, the ammo is negative or the element is not a ped or a player.

If the ped already has the same weapon in its slot, the ammo is added. A different weapon in the same slot is replaced. A slot's ammo is capped at 99999.

## Example

```lua
addEventHandler("onPlayerSpawn", root, function()
    giveWeapon(source, "PISTOL", 60, true)
    giveWeapon(source, "KNIFE", 1)
end)
```

### Coming from MTA

Takes the weapon's name instead of its id.

## See also

- [getPedWeapon (Server)](https://wiki.mymp.gg/en/getPedWeapon-server.md): Gets the weapon a ped or player is holding.
- [setPedArmour (Server)](https://wiki.mymp.gg/en/setPedArmour.md): Sets the armour of a ped or player and sends it to the clients.
- [createPed (Server)](https://wiki.mymp.gg/en/createPed-server.md): Creates a ped on the server, seen by every player.
