PivityGmodStore

#3 - Actions

As shown previously you can do things like :AddDrop

I call these actions, as it's something the user will be able to do with the item in the inventory.

If your addon has a functionality, like food can be eaten, you should add a Use action for it in the inventory. This will make people able to eat the food while in the inventory.


AddDrop

Realm: Server

Syntax:

ITEM:AddDrop(function(self, ply, ent, tbl, tr)

end)

Arguments:

  1. (table) self - ITEM template
  2. (player) ply - The player
  3. (entity) ent - The entity that have been spawned
  4. (table) tbl - The item table for the item that have just been spawned
  5. (TraceResult) tr - The trace performed by the drop function. It is range limited.


Amount/all

You can define if it should drop an amount that the player chooses, or if it should drop all.

I recommend having a normal drop function that drops 1 automatically for the most cases, but some cases like DarkRP money it wouldn't make sense to drop 1 by default.

You can only have one of normal drop/drop amount at a time, you can't have both! But you can always have drop all.


To change the drop case, simply add a second argument to :AddDrop

ITEM:AddDrop(function(self, ply, ent, tbl, tr, amt)
-- Notice the amt parameter now!
end, ITEM.DROP_ALL)

ITEM:AddDrop(function(self, ply, ent, tbl, tr, amt)
-- Notice the amt parameter now!
end, ITEM.DROP_AMOUNT)


AddUse/AddEquip

Realm: Shared

Syntax:

ITEM:AddEquip(function(self, ply, tbl)
-- Main code for execution
-- Remember this is shared!
-- Remember to always return true here, if you don't return it will allow people to infinitely use this


return true
end, function(self, ply, tbl)
-- This is a check for the first function to execute.
-- This function itself is optional. If you don't have it it'll always return true
-- Use this to check for things
-- Also shared


return true
end)


ITEM:AddUse(function(self, ply, tbl)
-- A use function instead of equip! Only difference is text displayed
return true
end)

Arguments:

  1. (table) self - ITEM template
  2. (player) ply - The player
  3. (table) tbl - The item table for the item that have just been spawned


Can't find what you're looking for?

Contact support