-
Notifications
You must be signed in to change notification settings - Fork 77
Item
Brian edited this page Jun 11, 2015
·
15 revisions
The item object is pretty important object in the NutScript framework. If you're making some item based roleplay like STALKER, Metro or CityRP, You must look at this document pretty well.
The item object can be accessed by traversal of inventory object or by specifiyng the id of the item. Remember, Item is "Object". It's not just group of table just like NS 1.0.
By having the Item Object, Each item in the gamemode is very unqiue, which means you can make every item special without making another items in a row. But, To make more awesome stuffs with NS 1.1's Item System, You need to understand how it's working first.
Customizing Your Schema: Adding New Items
id
- This is the numeric key for the item in the database. This is unique for each item and is shared.
uniqueID
- This is the string for the item in the database. This is referring the actual item data.
data
- This is the table for the item in the database. You can access/set variables on the specific item with ItemObject:getData(key), ItemObject:setData(key, value).
invID
- This is the numeric value for the item in the database. This value displays where is item is parented. If the invID is 0 or nil, The item is on the ground or in the virtual space. The position value is gridX and gridY
item:getID()
- Returns the
id
property. item:getDesc()
- Returns the description of the item.
item:print(isDetail)
- Prints simple data of object. (tostring only returns id).
item:printData()
- Prints all data of the item object.
item:call(method, client, entity[, ...])
- Calls the function of the item.
item:hook(name, callback)
- Hooks on to a call for an item function. This makes it easy to add on to item functions like dropping.
item:getOwner()
- Returns the actual owner (a player) of the item.
item:setData(key, value, receivers, noSave, checkEntity)
- Sets persisting value to the item object.
IfcheckEntity
is true, When you set the data of the item, It will check the entity on the ground if the entity is valid(Which means, Check all dropped items.). If the entity is valid, it will sync the variable to all players. item:getData(key[, default])
- Gets persisting value of the item object.
item:remove()
- Removes the item from existence and deletes the entity for the item if dropped.
item:spawn(spawnPosition, spawnAngles)
- Spawn item on the world.
item:getEntity()
- Gets the current entity that represents the item in the world.
item:transfer(invID[, x, y, client, noReplication, isLogical])
- Transfers the item to the other Inventory Object.
local item = nut.item.instances[data.id]
if (item) then
item:setData("cooked", true)
end
local itemTable = nut.item.list[unique]
if (itemTable) then
local position = (self:LocalToWorld(self:OBBCenter()) + ...
local x, y = position.x, position.y
nut.util.drawText(itemTable.name, x, y, ...)
nut.util.drawText(itemTable.desc, x, y + 16, ...)
end