diff options
Diffstat (limited to 'gamemode/shared/player_useitem.lua')
| -rw-r--r-- | gamemode/shared/player_useitem.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gamemode/shared/player_useitem.lua b/gamemode/shared/player_useitem.lua new file mode 100644 index 0000000..128146a --- /dev/null +++ b/gamemode/shared/player_useitem.lua @@ -0,0 +1,40 @@ +
+local meta = FindMetaTable("Player")
+
+if (SERVER) then
+ util.AddNetworkString("UseItem")
+ util.AddNetworkString("UseItemReq")
+
+ function meta:UseItem(item,bAccount)
+ if ((!bAccount and !self:HasItem(item)) or (bAccount and !self:HasAccountItem(item))) then return end
+
+ local IT = GetItemByName(item)
+
+ if (IT.OnUse) then
+ IT:OnUse(self)
+
+ net.Start("UseItem")
+ net.WriteEntity(self)
+ net.WriteString(item)
+ net.Broadcast()
+ end
+ end
+
+ net.Receive("UseItemReq",function(seq,pl) pl:UseItem(net.ReadString(),util.tobool(net.ReadBit())) end)
+else
+ net.Receive("UseItem",function()
+ local pl = net.ReadEntity()
+ local it = GetItemByName(net.ReadString())
+
+ if (it.OnUse) then it:OnUse(pl) end
+ end)
+
+ function RequestUseItem(item,bAccount)
+ net.Start("UseItemReq")
+ net.WriteString(item)
+ net.WriteBit(bAccount)
+ net.SendToServer()
+ end
+end
+
+
\ No newline at end of file |
