> For the complete documentation index, see [llms.txt](https://cactus-code.gitbook.io/cactus-code-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cactus-code.gitbook.io/cactus-code-docs/documentation/scripts/advanced-crafting-v2/framework.md).

# Framework

## General Functions

These helper functions are shared across all frameworks:

#### `CombineName(first, last, fallback)`

Merges first/last name (if present) or falls back to another field.

```lua
local name = CombineName("John", "Doe", "Unknown")
-- "John Doe"
```

#### `IsWeaponName(name)`

Checks if a string is a weapon (starts with `"WEAPON_"`).

```lua
if IsWeaponName("WEAPON_REVOLVER_CATTLEMAN") then
   print("It’s a weapon!")
end
```

***

## Frameworks

### VORP

#### `GetUser(source)`

Returns the player object.

```lua
local user = Framework.GetUser(source)
```

#### `GetIdentifier(source)`

Returns the player’s unique identifier.

```lua
local id = Framework.GetIdentifier(source)
```

#### `GetJob(source)`

Returns the player’s job name.

```lua
local job = Framework.GetJob(source)
```

#### `GetCharacterName(source)`

Returns the player’s formatted character name.

```lua
local name = Framework.GetCharacterName(source)
```

#### `GetInventory(source, callback)`

Asynchronously retrieves items and weapons.

```lua
Framework.GetInventory(source, function(items, weapons)
    print(json.encode(items))
    print(json.encode(weapons))
end)
```

#### `CanUseItem(source, item, amount)`

Checks if the player has the required amount of an item/weapon.

```lua
if Framework.CanUseItem(source, "water", 2) then
   print("Player can use 2 water bottles.")
end
```

#### `GiveItem(source, item, amount)`

Gives an item.

```lua
Framework.GiveItem(source, "bread", 1)
```

#### `RemoveItem(source, item, amount)`

Removes an item or weapon.

```lua
Framework.RemoveItem(source, "bread", 2)
```

#### `GiveWeapon(source, weapon)`

Gives a crafted weapon with a generated serial number.

```lua
Framework.GiveWeapon(source, "WEAPON_REVOLVER_CATTLEMAN")
```

***

### RSG

#### `GetUser(source)`

Returns the player object.

```lua
local user = Framework.GetUser(source)
```

#### `GetIdentifier(source)`

Returns the `citizenid`.

```lua
local id = Framework.GetIdentifier(source)
```

#### `GetJob(source)`

Returns the job name.

```lua
local job = Framework.GetJob(source)
```

#### `GetCharacterName(source)`

Returns character name (from `charinfo`).

```lua
local name = Framework.GetCharacterName(source)
```

#### `GetInventory(source, callback)`

Retrieves all items and weapons.

```lua
Framework.GetInventory(source, function(items, weapons)
    print("Items: ", json.encode(items))
    print("Weapons: ", json.encode(weapons))
end)
```

#### `CanUseItem(source, item, amount)`

Checks if player has item(s).

```lua
if Framework.CanUseItem(source, "whiskey", 1) then
   print("Has whiskey")
end
```

#### `GiveItem(source, item, amount)`

Adds an item via **rsg-inventory**.

```lua
Framework.GiveItem(source, "apple", 5)
```

#### `RemoveItem(source, item, amount)`

Removes an item.

```lua
Framework.RemoveItem(source, "apple", 2)
```

#### `GiveWeapon(source, weapon)`

Adds a weapon as an item.

```lua
Framework.GiveWeapon(source, "WEAPON_BOW")
```

***

### RedEM

#### `GetUser(source)`

Returns the RedEM user object.

```lua
local user = Framework.GetUser(source)
```

#### `GetIdentifier(source)`

Returns the identifier from RedEM.

```lua
local id = Framework.GetIdentifier(source)
```

#### `GetJob(source)`

Returns the player’s job.

```lua
local job = Framework.GetJob(source)
```

#### `GetCharacterName(source)`

Returns formatted name.

```lua
local name = Framework.GetCharacterName(source)
```

#### `CanUseItem(source, item, amount)`

Checks item availability.

```lua
if Framework.CanUseItem(source, "meat", 3) then
   print("Enough meat")
end
```

#### `GiveItem(source, item, amount)`

Adds item to RedEM inventory.

```lua
Framework.GiveItem(source, "whiskey", 1)
```

#### `RemoveItem(source, item, amount)`

Removes item from RedEM inventory.

```lua
Framework.RemoveItem(source, "meat", 2)
```

#### `GiveWeapon(source, weapon)`

Adds weapon as inventory item.

```lua
Framework.GiveWeapon(source, "WEAPON_REPEATER_CARBINE")
```

***

### Custom (Ox + RSG)

#### `GetUser(source)`

Returns the RSG player object.

```lua
local user = Framework.GetUser(source)
```

#### `GetIdentifier(source)`

Returns `citizenid`.

```lua
local id = Framework.GetIdentifier(source)
```

#### `GetJob(source)`

Returns job name.

```lua
local job = Framework.GetJob(source)
```

#### `GetCharacterName(source)`

Returns combined first/last name.

```lua
local name = Framework.GetCharacterName(source)
```

#### `GetInventory(source, callback)`

Retrieves items from **ox\_inventory**, fallback to RSG.

```lua
Framework.GetInventory(source, function(items, weapons)
    print(json.encode(items))
end)
```

#### `CanUseItem(source, item, amount)`

Checks in **ox\_inventory**, fallback to RSG.

```lua
if Framework.CanUseItem(source, "bandage", 1) then
   print("Has bandage")
end
```

#### `GiveItem(source, item, amount)`

Adds item via **ox\_inventory**, fallback to RSG.

```lua
Framework.GiveItem(source, "meat", 2)
```

#### `RemoveItem(source, item, amount)`

Removes item via **ox\_inventory**, fallback to RSG.

```lua
Framework.RemoveItem(source, "meat", 1)
```

#### `GiveWeapon(source, weapon)`

Adds weapon via **ox\_inventory**, fallback to RSG.

```lua
Framework.GiveWeapon(source, "WEAPON_BOW")
```

***

## Examples

### Give a Crafted Weapon

```lua
Framework.GiveWeapon(source, "WEAPON_REVOLVER_CATTLEMAN")
```

### Remove Items

```lua
if Framework.RemoveItem(source, "apple", 3) then
   print("Removed 3 apples")
end
```

### Get Player Inventory

```lua
Framework.GetInventory(source, function(items, weapons)
    for _, item in pairs(items) do
        print(item.name, item.count)
    end
end)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cactus-code.gitbook.io/cactus-code-docs/documentation/scripts/advanced-crafting-v2/framework.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
