Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/30/19 in all areas

  1. Version 1.1.0

    2680 downloads

    This resource provides an inventory API to server developers. This resource will not save anything on its own, it just provides you the functions to make your own inventory system using CEF/NativeUI/commands. Installing Put the files you downloaded in their respective places Read the documentation and examples to set up some items etc. All done Features Easy to use (hopefully!) Events Custom attributes for items (see examples) Inventory API const invAPI = require("../inventory-api"); /** * Adds an item to the inventory system. * @param {string} key Item identifier, such as "item_medkit". * @param {string} name Item name, such as "Medkit". * @param {string} description Item description, such as "Gives you 10 health". * @param {function} [onUse] Optional - Function that gets called when the item is used. * @param {function} [nameFunc] Optional - Function that gets called when getItemName() is used. * @param {function} [descFunc] Optional - Function that gets called when getItemDescription() is used. * @return {object} The added item, will be null if there are any mistakes. * @fires itemDefined */ invAPI.addItem(key, name, description, onUse, nameFunc, descFunc); /** * Returns whether the specified key is a registered or not. * @param {string} key Item identifier, such as "item_medkit". * @return {Boolean} True if registered, false otherwise. */ invAPI.hasItem(key); /** * Returns the specified item. * @param {string} key Item identifier, such as "item_medkit". * @return {object} The item at the specified key, will be undefined if the key isn't registered. */ invAPI.getItem(key); /** * Returns all registered item identifiers. * @return {string[]} An array of registered item identifiers. */ invAPI.getAllItems(); /** * Returns the human readable name of the specified item. * @param {string} key Item identifier, such as "item_medkit". * @param {string} [data] Optional - An object that has item attributes. * @return {string} Human readable item name. */ invAPI.getItemName(key, data); /** * Returns the description of the specified item. * @param {string} key Item identifier, such as "item_medkit". * @param {string} [data] Optional - An object that has item attributes. * @return {string} Item's description. */ invAPI.getItemDescription(key, data); Inventory API Events /** * itemDefined * This event is called when an item is added to the system with invAPI.addItem() * @param {string} key Item identifier. * @param {string} name Human readable name of the item. * @param {string} description Description of the item. */ invAPI.on("itemDefined", (key, name, description) => { // Example: console.log(`Item defined, key: ${key} | name: ${name} | description: ${description}`); }); /** * itemAdded * This event is called when a player receives an item. * @param {player} player The player who received the item. * @param {string} key Item identifier. * @param {number} amount Amount the player received. * @param {object} data Item attributes. */ invAPI.on("itemAdded", (player, key, amount, data) => { // Example: console.log(`${player.name} received ${amount}x ${key}.`); }); /** * itemUsed * This event is called when a player uses an item. * @param {player} player The player who used the item. * @param {number} invIdx Index of the item in player's inventory. * @param {string} key Item identifier. * @param {object} data Item attributes. */ invAPI.on("itemUsed", (player, invIdx, key, data) => { // Example: console.log(`${player.name} used ${key}.`); }); /** * itemRemoved * This event is called when an item is removed from a player's inventory. * @param {player} player The player who lost an item. * @param {number} invIdx Index of the item that got removed in player's inventory. * @param {string} key Item identifier. * @param {number} amount Removed item amount. * @param {object} data Item attributes. */ invAPI.on("itemRemoved", (player, invIdx, key, amount, data) => { // Example: console.log(`${player.name} lost ${amount}x ${key}.`); }); /** * itemRemovedCompletely * This event is called when an item is no longer in a player's inventory. * @param {player} player The player who lost an item. * @param {string} key Item identifier. * @param {object} data Item attributes. */ invAPI.on("itemRemovedCompletely", (player, key, data) => { // Example: console.log(`${player.name} no longer has ${key} (${data ? "with data" : "without data"}) in their inventory.`); }); /** * inventoryReplaced * This event is called when a player's inventory array gets changed by player.setInventory() * @param {player} player The player who had an inventory change. * @param {object[]} oldInventory The player's old inventory array. * @param {object[]} newInventory The player's new inventory array. */ invAPI.on("inventoryReplaced", (player, oldInventory, newInventory) => { // Example: console.log(`${player.name} had their inventory replaced. (Old item count: ${oldInventory.length}, new: ${newInventory.length})`); }); Player API /** * Returns the inventory array of the player. * @return {object[]} An array that holds all items of the player. */ player.getInventory(); /** * Replaces the inventory array of the player with the specified one. * @param {Array} newInventory An array that's going to be the new inventory of the player. * @return {Boolean} True if successful, false otherwise. * @fires inventoryReplaced */ player.setInventory(newInventory); /** * Returns whether the player has the specified item or not. * @param {string} itemKey Item identifier. * @return {Boolean} True if player has the item, false otherwise. */ player.hasItem(itemKey); /** * Same as hasItem but for items with custom attributes. * @param {string} itemKey Item identifier. * @param {object} data An object that has item attributes. * @return {Boolean} True if player has the item, false otherwise. */ player.hasItemWithData(itemKey, data); /** * Gets the item's index in the player's inventory. * @param {string} itemKey Item identifier. * @return {number} Index of the item, -1 if not found. */ player.getItemIndex(itemKey); /** * Same as getItemIndex but for items with custom attributes. * @param {string} itemKey Item identifier. * @param {object} data An object that has item attributes. * @return {number} Index of the item, -1 if not found. */ player.getItemIndexWithData(itemKey, data); /** * Gets how many of the specified item exists in the player's inventory. * @param {string} itemKey Item identifier. * @return {number} Item amount. */ player.getItemAmount(itemKey); /** * Same as getItemAmount but for items with custom attributes. * @param {string} itemKey Item identifier. * @param {object} data An object that has item attributes. * @return {number} Item amount. */ player.getItemAmountWithData(itemKey, data); /** * Gets total amount of items the player has in their inventory. * @return {number} Amount of all items. */ player.getTotalItemAmount(); /** * Gives the specified item to the player. * @param {string} itemKey Item identifier. * @param {number} amount Amount to give. * @param {object} [data] Optional - An object that has item attributes. * @return {Boolean} True if successful, false otherwise. * @fires itemAdded */ player.giveItem(itemKey, amount, data); /** * Uses the item at the specified index of the player's inventory array. * @param {number} itemIdx Index of the item in player's inventory array. * @return {Boolean} True if successful, false otherwise. * @fires itemUsed */ player.useItem(itemIdx); /** * Removes the item at the specified index of the player's inventory array. * @param {number} itemIdx Index of the item in player's inventory array. * @param {number} [amount] Optional - Amount to remove. * @return {Boolean} True if successful, false otherwise. * @fires itemRemoved * @fires itemRemovedCompletely */ player.removeItem(itemIdx, amount); Examples Full Test Script (used during development): https://gist.github.com/root-cause/6f15f0ee2276872c2d15a5333fed6a10 Name/Description Function Test Script: https://gist.github.com/root-cause/500b6e197348e941aeebfa8f883486bb Source code is available on GitHub in case you don't want to download: https://github.com/root-cause/ragemp-inventory-api
    1 point
  2. Version 2.1.0

    2331 downloads

    Now with 200% more color. Clientside Functions: mp.game.ui.notifications.show(message, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) mp.game.ui.notifications.showWithPicture(title, sender, message, notifPic, icon = 0, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) Serverside Functions: player.notify(message, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) player.notifyWithPicture(title, sender, message, notifPic, icon = 0, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) As Events: BN_Show(message, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) BN_ShowWithPicture(title, sender, message, notifPic, icon = 0, flashing = false, textColor = -1, bgColor = -1, flashColor = [77, 77, 77, 200]) Example: // Clientside mp.game.ui.notifications.show("Normal message with custom text and background color.", false, 15, 20); mp.game.ui.notifications.showWithPicture("New Message", "Facebook", "You got some more of that data?", "CHAR_FACEBOOK", 1, false, 0, 139); // Serverside player.notify("This message is red which means you're doing something wrong.", false, 6); player.notifyWithPicture("Title", "Ammu-Nation", "Ammunation has all the equipment you need to protect your family from the evils of a liberal society! Fixed, mounted, and shoulder-held submachine guns. Mortars! Surface-to-air and all manner of heat-seeking missiles!", "CHAR_AMMUNATION"); Icons: You can specify an icon ID for picture notifications, here's a list of them: 0, 4, 5, 6 = No Icon 1 = Speech Bubble 2 = Message 3 = Friend Request 7 = Arrow 8 = RP 9 = Money Notes: textColor and bgColor parameters want a HUD color ID which you can find here. (it is a bit outdated now though) You can find notification pictures here. If you can't see picture notifications, you must enable Phone Alerts from Settings > Notifications > Phone Alerts. This script changes player.notify on serverside.
    1 point
  3. Version 1.0.0

    844 downloads

    Kill your way to victory! Gun game is a gamemode where players start with powerful weapons and get less powerful weapons once they score enough kills to level up. Winning First player to go through all weapons/levels will win. Player with the highest level will win if round timer ends. Config The config file is located in packages/gungame/config.json. gameTimeSeconds: Length of a round in seconds. 600 by default which converts to 10 minutes. healthOnKill: How much health players will get for killing someone. 0 by default which means players won't get any health from killing. respawnTimeSeconds: Seconds a player needs to wait for respawning. 8 by default. restartTimeSeconds: Seconds players need to wait before a new round begins. 10 by default. Loadouts The loadouts file is located in packages/gungame/loadouts.json. It's a JSON file with each loadout as an array. Each loadout array must contain at least one valid loadout item. Loadout items must have: Weapon: Weapon hash key as string, such as WEAPON_PISTOL. (Weapons list) Name: Human readable name of the weapon, such as Pistol. KillsForNext: Amount of kills a player need to get with this weapon before upgrading to the next one. (player will be declared winner if this item is the last in the loadout) Example Loadout (RPG > Minigun > Special Carbine > Heavy Revolver > Sawed-Off Shotgun > Machete, player needs 5 machete kills to win) [ { "Weapon": "WEAPON_RPG", "Name": "RPG", "KillsForNext": 1 }, { "Weapon": "WEAPON_MINIGUN", "Name": "Minigun", "KillsForNext": 1 }, { "Weapon": "WEAPON_SPECIALCARBINE", "Name": "Special Carbine", "KillsForNext": 1 }, { "Weapon": "WEAPON_REVOLVER", "Name": "Heavy Revolver", "KillsForNext": 1 }, { "Weapon": "WEAPON_SAWNOFFSHOTGUN", "Name": "Sawed-Off Shotgun", "KillsForNext": 1 }, { "Weapon": "WEAPON_MACHETE", "Name": "Machete", "KillsForNext": 5 } ] Maps Map files are located in packages/gungame/maps/. Maps must have: CenterOfMap: An object that has x, y, z and radius properties. This is used for defining game area and respawning players around the game area. SpawnPoints: Array of objects that has x, y, z and a (angle/heading) properties. This is used for spawning players for the first time in the map, like when they connect the server or when a round begins. Example Map (1 Spawn Point) { "CenterOfMap": { "x": -1108.71240234375, "y": 4918.75048828125, "z": 217.17044067382812, "radius": 70.0 }, "SpawnPoints": [ { "x": -1126.168212890625, "y": 4952.76025390625, "z": 220.46249389648438, "a": 191.99134826660156 } ] } Maps also have optional properties such as: World: An object that has time and weather properties. --> time: An object that has hour, minute and second properties. --> weather: A string property that contains the weather ID. (Weather ID list) Props: Array of objects that has model, position and rotation properties. --> model: A string property that contains the model name. Example: prop_fire_hydrant_1 --> position: An object that has x, y and z properties. --> rotation: An object that has x, y and z properties. Example Map (Night, Rainy Weather with 1 Prop) { "World": { "time": { "hour": 2, "minute": 0, "second": 0 }, "weather": "RAIN" }, "CenterOfMap": { "x": -1108.71240234375, "y": 4918.75048828125, "z": 217.17044067382812, "radius": 70.0 }, "SpawnPoints": [ { "x": -1126.168212890625, "y": 4952.76025390625, "z": 220.46249389648438, "a": 191.99134826660156 } ], "Props": [ { "model": "prop_fire_hydrant_1", "position": { "x": -1108.71240234375, "y": 4918.75048828125, "z": 217.05 }, "rotation": { "x": 0.0, "y": 0.0, "z": 0.0 } } ] } Source code is available on GitHub in case you don't want to download: https://github.com/root-cause/ragemp-gungame Have fun!
    1 point
×
×
  • Create New...