Skip to content

alt:V Context Menu for Right-Clicking on Objects In-Game. Runescape Style.

License

Notifications You must be signed in to change notification settings

Stuyk/altv-os-context-menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Open Source - Context Menu - alt:V

❤️ Become a Sponsor of my Open Source Work

⌨️ Learn how to script for alt:V

💡 Need a Roleplay Script? Try Athena!

⭐ This repository if you found it useful!


Description

This allows you to create a simple context menu for players to utilize. Which means they can hold left alt and right-click on objects to select different objects based on their models. Which is great for creating in-depth options for players to utilize.

Installing Dependencies / Installation

I cannot stress this enough. Ensure you have NodeJS 13+ or you will have problems.

  • NodeJS 13+
  • An Existing or New Gamemode
  • General Scripting Knowledge

After simply add the name of this resource to your server.cfg resource section.

altv-os-context-menu

Then simply clone this repository into your main server resources folder.

cd resources
git clone https://github.com/Stuyk/altv-os-context-menu

Ensure your package.json includes this property:

"type": "module"

Configuring A Menu

All menus must be created on client-side. They only need to be initialized once. They are attached to an identifier and an entity id.

Go in-game. Hold alt and right-click on any object. Open your console with F8 then look at the model number for the object.

alt.emit('context:CreateMenu')

Argument Description
model The model of the model you wish to append options to.
title The name of the menu.

Example

alt.on('context:Ready', () => {
    alt.emit('context:CreateMenu', 1329570871, 'Trash Can');
});

Appending to Menu

All menus have an identifier. Use the identifier to apply options to a menu.

alt.emit('context:CreateMenu')

Argument Description
model The model of the model you wish to append options to.
contextOptionName The name of the option you are appending.
eventCallbackName The event to call when the option is selected. Comes through alt.emit or alt.onClient
isServer If true. Then the callbackName event will come through alt.onClient. Otherwise alt.emit

Example

alt.on('context:Ready', () => {
    alt.emit('context:CreateMenu', 1329570871, 'Trash Can');
    alt.emit('context:AppendToMenu', 1329570871, 'Look in Trash', 'trashcan:Look', false);
    alt.emit('context:AppendToMenu', 1329570871, 'Dig in Trash', 'trashcan:Dig', true);
});

Example - Recieving the Event on Client-side.

alt.on('trashcan:Look', data => {
    alt.log(JSON.stringify(data));
});

Example - Recieving the Event on Server-side.

alt.onClient('trashcan:Dig', (player, data) => {
    console.log(data);
    alt.log(`${player.name} has dug in the trash. What an animal!`);
});

Other alt:V Open Source Resources

About

alt:V Context Menu for Right-Clicking on Objects In-Game. Runescape Style.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project