Version 1.0.0
1855 downloads
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
Thanks to @ragempdev and @Jaimuzu for their contributions and help during the tests.
If there are any reproducible bugs, feel free to report them.
This resource will be obsolete after 0.4's weapon attachment/customization API arrives.
JS was a mistake.