Weapon Component Sync 1.0.0

   (5 reviews)
Sign in to follow this  

2 Screenshots

About This File

This resource provides serverside weapon component API for developers and syncs applied weapon components.

 

Installing

  • Put the files you downloaded in their respective places
  • Add require('weaponcomponents') to client_packages/index.js
  • All done

 

Serverside API

PRO TIP: Check RAGEMP Wiki or my weapon data resource for component names/hashes.

/**
 * Adds the specified component to the player's specified weapon.
 * @param  {Number} weaponHash    The weapon's hash.
 * @param  {Number} componentHash The component's hash.
 * @throws {TypeError} If any of the arguments is not a number.
 */
player.giveWeaponComponent(weaponHash, componentHash);

/**
 * Returns whether the player's specified weapon has the specified component or not.
 * @param  {Number}  weaponHash    The weapon's hash.
 * @param  {Number}  componentHash The component's hash.
 * @returns {Boolean}
 * @throws {TypeError} If any of the arguments is not a number.
 */
player.hasWeaponComponent(weaponHash, componentHash);

/**
 * Returns the components of the player's specified weapon.
 * @param  {Number}  weaponHash    The weapon's hash.
 * @returns {Number[]} An array of component hashes.
 * @throws {TypeError} If weaponHash argument is not a number.
 */
player.getWeaponComponents(weaponHash);

/**
 * Removes the specified component from the player's specified weapon.
 * @param  {Number} weaponHash    The weapon's hash.
 * @param  {Number} componentHash The component's hash.
 * @throws {TypeError} If any of the arguments is not a number.
 */
player.removeWeaponComponent(weaponHash, componentHash);

/**
 * Removes all components of the player's specified weapon.
 * @param  {Number}  weaponHash    The weapon's hash.
 * @throws {TypeError} If weaponHash argument is not a number.
 */
player.removeAllWeaponComponents(weaponHash);

/**
 * Resets all components of the player's all weapons.
 */
player.resetAllWeaponComponents();

 

Example Commands

1) /prosniper and /loudsniper

Use /prosniper to get a sniper rifle with components and use /loudsniper to remove the suppressor.

const sniperHash = mp.joaat("weapon_sniperrifle");

// Will give the player a sniper rifle and components (suppressor, advanced scope and luxury finish)
mp.events.addCommand("prosniper", (player) => {
    player.giveWeapon(sniperHash, 9999);
    player.giveWeaponComponent(sniperHash, mp.joaat("COMPONENT_AT_AR_SUPP_02"));
    player.giveWeaponComponent(sniperHash, mp.joaat("COMPONENT_AT_SCOPE_MAX"));
    player.giveWeaponComponent(sniperHash, mp.joaat("COMPONENT_SNIPERRIFLE_VARMOD_LUXE"));
});

// Will remove the suppressor from the player's sniper rifle
mp.events.addCommand("loudsniper", (player) => {
    player.removeWeaponComponent(sniperHash, mp.joaat("COMPONENT_AT_AR_SUPP_02"));
});

 

2) Test commands

These are the commands I used while testing this script. 

// /weapon is taken from freeroam gamemode
mp.events.addCommand('weapon', (player, _, weaponName) => {
    if (weaponName.trim().length > 0)
        player.giveWeapon(mp.joaat(`weapon_${weaponName}`), 9999);
    else
        player.outputChatBox(`<b>Command syntax:</b> /weapon [weapon_name]`);
});

// Example: /addcomp carbinerifle COMPONENT_CARBINERIFLE_CLIP_03
mp.events.addCommand("addcomp", (player, _, weapon, compName) => {
    player.giveWeaponComponent(mp.joaat("weapon_" + weapon), mp.joaat(compName));
});

// Example: /remcomp carbinerifle COMPONENT_CARBINERIFLE_CLIP_03
mp.events.addCommand("remcomp", (player, _, weapon, compName) => {
    player.removeWeaponComponent(mp.joaat("weapon_" + weapon), mp.joaat(compName));
});

// Example: /remallcomps carbinerifle
mp.events.addCommand("remallcomps", (player, _, weapon) => {
    player.removeAllWeaponComponents(mp.joaat("weapon_" + weapon));
});

// Example: /resetcomps
mp.events.addCommand("resetcomps", (player) => {
    player.resetAllWeaponComponents();
});

 

Notes

  1. Thanks to @ragempdev and @Jaimuzu for their contributions and help during the tests.
  2. If there are any reproducible bugs, feel free to report them.
  3. This resource will be obsolete after 0.4's weapon attachment/customization API arrives.
  4. JS was a mistake.
  • Like 2
  • Sad 1



User Feedback

Create an account or sign in to leave a review

You need to be a member in order to leave a review

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

hubba

   2 of 2 members found this review helpful 2 / 2 members

💋

Share this review


Link to review
Jaimuzu

   0 of 1 member found this review helpful 0 / 1 member

youre welcome on ragemp 

Epic resource 

 

Share this review


Link to review
Djoe_

   0 of 1 member found this review helpful 0 / 1 member

It's not ok, C# when? 

Share this review


Link to review
attacking

   0 of 1 member found this review helpful 0 / 1 member

Nice

Share this review


Link to review
ragempdev

   0 of 3 members found this review helpful 0 / 3 members

it's ok

Share this review


Link to review