# @haworth/menu-store

[![npm](https://img.shields.io/npm/v/@haworth/menu-store)](https://www.npmjs.com/package/@haworth/menu-store)
![npm](https://img.shields.io/npm/dy/@haworth/menu-store)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/@haworth/menu-store)

A wrapper of the popular [SA-MP MenuStore library](https://github.com/Coystark/MenuStore) for samp-node-


## Getting started

```sh
pnpm add @infernus/core @haworth/menu-store
```

## Example

```ts
import { type Player, PlayerEvent } from "@infernus/core";
import {
  MenuStore_InitializeGameMode,
  MenuStore_InitializePlayerEvents,
  MenuStore_InitializePlayer,
  MenuStore_AddItem,
  MenuStore_Open,
  MenuStore_Close,
  MenuStore_IsOpen,
  MenuStore_CleanupPlayer
} from "@haworth/menu-store";

// Initialize once on server start
GameMode.onInit(({ next }) => {
  MenuStore_InitializeGameMode();
  MenuStore_InitializePlayerEvents();
  return next();
});

// When a player connects
PlayerEvent.onConnect(({ player }) => {
  MenuStore_InitializePlayer(player);
});

// Example command to open the store
PlayerEvent.onCommandText("weaponshop", ({ player, subcommand, next }) => {
  // Add items to the store for this player
  MenuStore_AddItem(player, 1, 371, "Parachute", 500, "A parachute for jumping", 7.5, true, 1);
  MenuStore_AddItem(player, 2, 355, "AK-47", 2500, "Automatic rifle", 7.5, true, 1);

  // Open the store
  MenuStore_Open(
    player,
    "gun_store",
    "Weapon Shop",
    (player, purchased, itemID, model, totalPrice, amount, itemName) => {
      if (purchased) {
        player.sendClientMessage(0x00FF00FF, `You bought ${amount}x ${itemName} for $${totalPrice}!`);
        // Give the item to the player here
      }
    },
    "$", // currency sign
    "BUY" // confirm button text
  );
});
```

## API

### `MenuStore_InitializeGameMode()`
Initializes global store elements. Call once on server start.

### `MenuStore_InitializePlayerEvents()`
Registers TextDraw events for all players. Call once on server start.

### `MenuStore_InitializePlayer(player)`
Prepares the store system for a specific player. Call when a player connects.

### `MenuStore_AddItem(player, itemID, modelID, name, price, description?, descriptionSize?, descriptionLineJump?, stack?, rotX?, rotY?, rotZ?, zoom?)`
Adds an item to the player's store inventory.

### `MenuStore_Open(player, storeID, storeName, callback, moneySign?, buttonConfirm?)`
Opens the store for the player.

### `MenuStore_Close(player)`
Closes the store for the player.

### `MenuStore_IsOpen(player)`
Returns whether the store is open for the player.

### `MenuStore_CleanupPlayer(player)`
Cleans up all store data for a player.