cityrp.item
Shared item and item category library.
- Sharedcityrp.item.addCat(name, description, access) → numberSource ☍
-
Add a new category.
Parameters
- namestringThe name of the category to add.
- descriptionstring?The description of the category. Defaults to empty string.
- accessstring?The access for the category, defaults to 'b'.
Returns
- numberThe category index.
- Sharedcityrp.item.applyAppearance(panel, item)Source ☍
-
Applies an item's colour and material override to the model panel drawing it, so an icon or preview shows what the item will actually look like on the ground.
The colour goes on the panel rather than the entity: DModelPanel's paint pass calls render.SetColorModulation with its own colour every frame, which overrides anything Entity:SetColor put there. The material has no such equivalent and stays on the entity.
Both are set unconditionally rather than only when the item declares them: these panels are reused across the items they show, so an item that declares neither has to clear what the last one left behind.
A plain function rather than an ITEM method on purpose. cityrp.item.new points a new item's __index at its base item, not at ITEM, so a stored item is only as good as whatever its base chain happens to expose - the weed pot, for one, reaches none of ITEM's methods.
Parameters
- panelPanelThe DModelPanel drawing the item's model.
- itemtableThe item being drawn.
- Sharedcityrp.item.canAccessCategory(list, cat) → booleanSource ☍
-
True if
catis covered by any entry inlist(e.g. a team's canmake list). A parent entry (e.g. "Clothing") grants every sub-category under it; a sub-category entry (e.g. "Clothing - Government Clothing") grants only that exact category.Parameters
- liststring[]Array of allowed category strings.
- catstringThe category to check.
Returns
- booleanTrue if the category is allowed.
- Servercityrp.item.canUseItem(ply, itm, meta, metaContext) → boolean, string|nilSource ☍
-
Checks every non-cooldown, non-context gate on using/equipping itm -- Clothing's fireCanUse ban and membership requirement, the PlayerCanUseItem hook, reps, membershiplevel, and canUse. Pure, never notifies -- a nil reason means the PlayerCanUseItem hook blocked it and already notified the player itself (e.g. uniforms' cooldown), so callers shouldn't show a fallback for that case; every other false result carries a real reason string.
Parameters
- plyPlayer
- itmtableA registered item (cityrp.item.stored entry).
- metastring?The item meta value, forwarded to canUse's context.
- metaContexttable?A pre-built itemmeta context to reuse (cityrp.item.use passes its own so canUse's mutations carry through to onUse); built fresh from meta if omitted.
Returns
- 1boolean
- 2string|nil
- Sharedcityrp.item.categoryMatches(itemCat, selected) → booleanSource ☍
-
True if itemCat is exactly
selected, or itemCat's parent category isselected. Also true if itemCat has no sub-category of its own (e.g. "Mixtures") andselectedis that same parent's "Other" bucket (e.g. "Mixtures - Other") -- uncategorized items fall back into their parent's Other bucket once the parent has real sub-categories. Used both for shop/tab filtering and for team category-permission checks, so the matching rule can't drift between the two.Parameters
- itemCatstringAn item's raw category string.
- selectedstringThe category being filtered/checked against.
Returns
- booleanTrue if the category matches.
- Sharedcityrp.item.categorySplit(cat) → string, string?Source ☍
-
Splits a "Parent - Sub" category string into parent and sub parts.
Parameters
- catstringThe raw item category string.
Returns
- 1stringThe parent category.
- 2string?The sub-category, or nil if none.
- Servercityrp.item.convert(ply, item, meta) → booleanSource ☍
-
Converts a player's whole stack of a replaced item into what replaced it, keeping the amount.
Parameters
- plyPlayerThe player whose stack to convert.
- itemstringThe replaced item's unique ID.
- metastring?The stack's meta value.
Returns
- booleanWhether anything was converted.
- Sharedcityrp.item.createIcon(parent, item, meta) → PanelSource ☍
-
Creates the small model icon shown for an item in the inventory and market grids. A SpawnIcon renders only the model and skin (its SetBodyGroup records the value but never re-renders), so an item with a colour or bodygroups gets a live model panel instead.
Parameters
- parentPanelThe panel to create the icon in.
- itemtableThe item to show.
- metastring?The stack's meta value, for an item whose skin or bodygroups follow its meta.
Returns
- PanelThe created SpawnIcon or DScaleItemPanel.
- Servercityrp.item.destroy(ply, item, amt, meta) → booleanSource ☍
-
Destroys a player's item.
Parameters
- plyPlayerThe player to remove the item from.
- itemstringThe item ID to remove.
- amtnumberThe number of the item to destroy.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully destroyed.
- Servercityrp.item.drop(ply, item, amt, pos, meta) → booleanSource ☍
-
Drops an item from a player.
Parameters
- plyPlayerThe player to remove the item from.
- itemstringThe item index.
- amtnumberThe number of items to drop.
- posVector?The position to make the items. Defaults to ply's eye trace hit position.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully dropped.
- Sharedcityrp.item.findCat(name) → table?Source ☍
-
Retrieve a category.
Parameters
- namestringName of the category to find.
Returns
- table?Category data, or nil if not found.
- Sharedcityrp.item.forWeapon(class) → table?Source ☍
-
The item a held weapon stands for. A weapon that is not itself an item can name the one it is with
SWEP.ItemID, as the bought breach's SWEP does, so the restrained search still lists it.Parameters
- classstringThe weapon's class.
Returns
- table?The item table, or nil if the weapon stands for none.
- Sharedcityrp.item.get(name) → table?Source ☍
-
Get an item by its name (with fuzzy matching).
Parameters
- namestringThe name or unique ID of the item to get.
Returns
- table?The item table, or nil if not found.
- Sharedcityrp.item.getPreviewBodygroups(item, meta) → table<integer, integer>?Source ☍
-
The bodygroups an item's icon or preview is drawn with.
storebgsbelongs to the store model and wins; otherwise, when the preview shows the item's own model, it takes the bodygroups the dropped item would have for this meta.Parameters
- itemtableThe item being drawn.
- metastring?The stack's meta value, when the preview is of one stack.
Returns
- table<integer, integer>?Bodygroup values keyed by bodygroup index.
- Sharedcityrp.item.getPreviewSkin(item, meta) → integerSource ☍
-
The skin an item's icon or preview is drawn with:
storeskinwhen the item sets one, otherwise the skin the dropped item would have for this meta.Parameters
- itemtableThe item being drawn.
- metastring?The stack's meta value, when the preview is of one stack.
Returns
- integerThe skin index.
- Servercityrp.item.give(ply, item, amt, tObj, meta) → booleanSource ☍
-
Give an item to a player.
Parameters
- plyPlayerThe player giving the item.
- itemstringThe itemID.
- amtnumberThe number of items to give.
- tObjPlayerThe player being given to.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully given.
- Sharedcityrp.item.isGovernmentVehicle(cat) → booleanSource ☍
-
True if a vehicle item's category is one of the government vehicle sub-categories.
Parameters
- catstringThe raw item category string.
Returns
- booleanTrue if it's a government vehicle sub-category.
- Servercityrp.item.make(item, pos, ply, meta, amt) → boolean|EntitySource ☍
-
Makes an item at the specified position.
Parameters
- itemstringThe item ID to create.
- posVectorThe position to make the item at.
- plyPlayerThe player who owns the item.
- metastring?The item meta value.
- amtnumber?The quantity the item entity represents (defaults to 1).
Returns
- boolean|EntityThe created entity, or false on failure.
- Sharedcityrp.item.new(base) → tableSource ☍
-
Create a new item table inheriting from a base. A named base that is not registered yet still returns a usable item, but one that inherits nothing from it, so the miss is logged as an ERROR rather than left silent.
Parameters
- basestring?The uniqueID of the base item to inherit from.
Returns
- tableThe new item table with metatable set up.
- Servercityrp.item.pickup(ply, item, meta) → booleanSource ☍
-
Pick up a player's vehicle.
Parameters
- plyPlayerThe player to pickup.
- itemstringThe item ID to pickup.
- metastring?The item meta value.
Returns
- booleanWhether the vehicle was successfully picked up.
- Servercityrp.item.place(ply, item, amt, pos, meta) → booleanSource ☍
-
Places an item (i.e. food).
Parameters
- plyPlayerThe player to place the item from.
- itemstringThe item ID to place.
- amtnumberThe number of items to place.
- posVector?The position to place the items. Defaults to ply's eye trace hit position.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully placed.
- Servercityrp.item.placefood(item, pos, ply, meta) → boolean|EntitySource ☍
-
Makes a food entity at the specified position.
Parameters
- itemstringThe item ID to create.
- posVectorThe position to make the item at.
- plyPlayerThe player who owns the item.
- metastring?The item meta value.
Returns
- boolean|EntityThe created entity, or false on failure.
- Sharedcityrp.item.register(item, base) → boolean?Source ☍
-
Register a new item (LEGACY - use ITEM:New():Register() instead).
Deprecated
This function is deprecated and may be removed in a future version.
Use ITEM:New(...) with fluent setters and :Register() instead.
Parameters
- itemtableThe item table to register.
- basestring?The uniqueID of the base item to take properties from.
Returns
- boolean?
falseif the named base was not registered, otherwise nil.
- Servercityrp.item.remove(ply, item, meta) → booleanSource ☍
-
Remove an item from a player (like a hat).
Parameters
- plyPlayerThe player to remove the item from.
- itemstringThe item index.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully removed.
- Servercityrp.item.removemod(ply, item) → booleanSource ☍
-
Special function for removing a player's weapon mods on death. Added this because the other functions had bugs.
Parameters
- plyPlayerThe player to remove the item from.
- itemstringThe item ID to remove.
Returns
- booleanWhether the item was successfully removed.
- Sharedcityrp.item.resolve(itemOrID) → table?Source ☍
-
Resolve an item table from an item table or unique ID. Unlike cityrp.item.get, this does not perform fuzzy name matching.
Parameters
- itemOrID(string|table)?Item table or unique ID.
Returns
- table?The item table, or nil if not found.
- Sharedcityrp.item.resolveReplacement(itemID, meta) → string, anySource ☍
-
Follows an item's replacement chain to the item it converts into, and the meta that item gets.
Parameters
- itemIDstringThe item's unique ID.
- metaanyThe stack's own meta, kept unless a replacement names its own.
Returns
- 1stringThe item it converts into, or
itemIDitself if it isn't replaced or its replacement isn't registered. - 2anyThe meta for that item.
- Servercityrp.item.sell(ply, item, amt, meta) → booleanSource ☍
-
Sell a players item.
Parameters
- plyPlayerThe player to sell the item from.
- itemstringThe item ID to sell.
- amtnumberThe number of items to sell.
- metastring?The item meta value.
Returns
- booleanWhether the item was successfully sold.
- Servercityrp.item.spawn(class, item, pos, ply, meta) → boolean|EntitySource ☍
-
Create an item entity and set the player.
Parameters
- classstringThe entity class to spawn.
- itemstringThe item ID to create.
- posVectorThe position to make the item at.
- plyPlayerThe player who owns the item.
- metastring?The item meta value.
Returns
- boolean|EntityThe created entity, or false on failure.
- Servercityrp.item.takeStack(activator, ent)Source ☍
-
Gives a player as much of a dropped item stack as fits in their inventory, leaving any remainder in the world entity.
Parameters
- Servercityrp.item.tryMergeStack(a, b)Source ☍
-
Attempts to combine two touching dropped item entities into one stack. Only merges entities that are the same item, same meta, and dropped by the same player, so unrelated items lying near each other never combine.
Parameters
- Servercityrp.item.use(ply, item, meta, force) → booleanSource ☍
-
Have a player use an item.
Parameters
- plyPlayerThe player using an item.
- itemstringThe item index.
- metastring?The item meta value.
- forceboolean?Ignore the item-use cooldown.
Returns
- booleanWhether the item was successfully used.
- Sharedcityrp.item.catIndexSource ☍