Functions

Functions are events that are called on items, with (usually) the player who owns the item being the first argument, and then event specific extra arguments.

ITEM:OnBuy(ply)

Required: No
Arguments: Player ply
Realm: Server
Description: Called when the player buys the item.

function ITEM:OnBuy(ply)
    ply:Kill()
end

ITEM:OnSell(ply)

Required: No
Arguments: Player ply
Realm: Server
Description: Called when the player sells the item.

function ITEM:OnSell(ply)
    ply:Kill()
end

ITEM:OnEquip(ply, modifications)

Required: No
Arguments: Player ply, Table modifications
Realm: Server
Description: Called when the player equips the item.

function ITEM:OnEquip(ply)
    PrintTable(modifications)
end

ITEM:OnHolster(ply, modifications)

Required: No
Arguments: Player ply
Realm: Server
Description: Called when the player holsters the item.

function ITEM:OnEquip(ply)
    ply:Kill()
end

ITEM:OnModify(ply)

Required: No
Arguments: Player ply
Realm: Server
Description: Receives the modifications table from the client. The data is saved automatically.

function ITEM:OnModify(ply, modifications)
    PrintTable(modifications)
    self:OnEquip(ply, modifications) -- adds the item back again
end

ITEM:CanPlayerBuy(ply)

Required: No
Arguments: Player ply
Returns: Boolean
Realm: Server
Description: Called when the player tries to buy the item. Return true or false.

function ITEM:CanPlayerBuy(ply)
    return ply:Alive() -- only if alive
end

ITEM:CanPlayerSell(ply)

Required: No
Arguments: Player ply
Returns: Boolean
Realm: Server
Description: Called when the player tries to sell the item. Return true or false.

function ITEM:CanPlayerSell(ply)
    return ply:Alive() -- only if alive
end

ITEM:CanPlayerEquip(ply)

Required: No
Arguments: Player ply
Returns: Boolean
Realm: Server
Description: Called when the player tries to equip the item. Return true or false.

function ITEM:CanPlayerEquip(ply)
    return ply:Alive() -- only if alive
end

ITEM:CanPlayerHolster(ply)

Required: No
Arguments: Player ply
Returns: Boolean
Realm: Server
Description: Called when the player tries to holster the item. Return true or false.

function ITEM:CanPlayerHolster(ply)
    return ply:Alive() -- only if alive
end

ITEM:Modify(modifications)

Required: No
Arguments: Table modifications
Realm: Client
Description: Called when the 'Modify' option is selected in the menu.

function ITEM:Modify(modifications)
    PS:ShowColorChooser(self, modifications)
end

ITEM:ModifyClientsideModel(ply, model, pos, ang)

Required: No
Arguments: Player ply, CSModel model, Vector pos, Angle ang
Returns: CSModel, Vector, Angle
Realm: Client
Description: Called every frame to position hats and other attachments. Requires either ITEM.Attachment or ITEM.Bone, and ITEM.Model.

function ITEM:ModifyClientsideModel(ply, model, pos, ang)
    pos = pos + (ang:Forward() * -2.2)
    ang:RotateAroundAxis(ang:Up(), -90)

    return model, pos, ang
end
comments powered by Disqus