Coder Social home page Coder Social logo

monstertaeratto / altv-os-context-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stuyk/altv-os-context-menu

0.0 1.0 0.0 119 KB

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

Home Page: https://stuyk.com/

JavaScript 83.21% HTML 5.52% CSS 11.27%

altv-os-context-menu's Introduction

Open Source - Context Menu

Created by Stuyk (Trevor Wessel)

❤️ Please support my open source work by donating. I'm here to provide general context for complicated procedures for you new developers. ❤️

https://github.com/sponsors/Stuyk/

⭐ 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. 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.

alt.emit('context:CreateMenu')

Argument Description
identifier The name to identify this interaction with. Must be unique. Unless using isModel
entityOrModel The entity or model. If using model. Ensure to set isModel to true. This will work for all models across the map.
title The name of the menu.
isModel If you used a model # instead of an entity # you must specify true. Globally applies menu to all models across the map.

Example

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

Appending to Menu

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

alt.emit('context:CreateMenu')

identifier, menuName, callbackName, isServer = false

Argument Description
identifier The name to identify this interaction with. Must be unique.
menuName The name of the option.
callbackName 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', 'trashcan1', 49666, 'Trash Can');
    alt.emit('context:AppendToMenu', 'trashcan1', 'Look in Trash', 'trashcan:Look', false);
    alt.emit('context:AppendToMenu', 'trashcan1', '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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.