From 6f6cce0561c19e7af14bcc6e6b1c7de2d5efc530 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 29 Apr 2016 20:30:52 -0400 Subject: a halfway commit to show scott --- gamemode/itemsystem/common.lua | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 gamemode/itemsystem/common.lua (limited to 'gamemode/itemsystem/common.lua') diff --git a/gamemode/itemsystem/common.lua b/gamemode/itemsystem/common.lua new file mode 100644 index 0000000..f7d6c72 --- /dev/null +++ b/gamemode/itemsystem/common.lua @@ -0,0 +1,46 @@ +--This file holds a bunch of common functions that happen in items. They're seperated out here so that they're easy to change if there's a bug somewhere. + +--Freezes the player, creates the loading bar, and calls ondone when the timer is up. +function startProcessGeneric(player, string, time, ondone) + if(player.InProcess) then + self.Owner:SendMessage("You can't do that much at once!", 3, Color(255, 255, 255, 255)) + return + end + player.InProcess = true + player:Freeze(true) + player:MakeProcessBar( string, time, false ) + timer.Create( "process", time, 1, function() + player:Freeze(false) + player.InProcess = false + player:StopProcessBar() + ondone() + end) +end + +if(SERVER) then + util.AddNetworkString( "gms_dropresources" ) +end +function genericDropResource(player, resource, ammount) + if(CLIENT) then + net.Start("gms_dropresources") + net.WriteString(resource) + net.WriteInt(ammount,GMS.NETINT_BITCOUNT) + net.SendToServer() + end + if(SERVER) then + if(player.Resources[resource] <= ammount) then + player:SendMessage("You don't have that many to drop!", 3, Color(255, 255, 255, 255)) + return + end + local res = ply:GetResource( Type ) + + if ( ammount > res ) then + ammount = res + end + ply:DropResource( Type, int ) + ply:DecResource( Type, int ) + end +end +net.Receive( "gms_dropresources", function(len,pl) + genericDropResource(pl,net.ReadString(),net.ReadInt(GMS.NETINT_BITCOUNT)) +end) -- cgit v1.2.3-70-g09d2