diff options
| author | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-02 14:08:45 -0500 |
|---|---|---|
| committer | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-01-02 14:08:45 -0500 |
| commit | 24667cceed26e03d49103b359f8da05c62bc213b (patch) | |
| tree | 1d854d3d42affb8e336f7323035f0d62e37f2e9e /gamemode/shared/weaponswap.lua | |
| parent | 1b250402f702ca5feef10f3defc27458ebcd7720 (diff) | |
| parent | 2bac92e03443e432597281ee0ddd2b878d4fc76f (diff) | |
| download | wintersurvival2-24667cceed26e03d49103b359f8da05c62bc213b.tar.gz wintersurvival2-24667cceed26e03d49103b359f8da05c62bc213b.tar.bz2 wintersurvival2-24667cceed26e03d49103b359f8da05c62bc213b.zip | |
Merge branch 'alt-hotbar-selection' into queue
Diffstat (limited to 'gamemode/shared/weaponswap.lua')
| -rw-r--r-- | gamemode/shared/weaponswap.lua | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/gamemode/shared/weaponswap.lua b/gamemode/shared/weaponswap.lua index f6e0a5c..aa82d53 100644 --- a/gamemode/shared/weaponswap.lua +++ b/gamemode/shared/weaponswap.lua @@ -6,45 +6,62 @@ if (CLIENT) then local STi = CurTime()
hook.Add("PlayerBindPress","SwapWeapons",function(pl,bind,pressed)
- if (LocalPlayer():IsPigeon()) then
+ if (LocalPlayer():IsPigeon()) then
if (bind:find("invprev")) then return true
elseif (bind:find("invnext")) then return true end
end
-
+
if (pressed) then
local Wep = pl:GetActiveWeapon()
-
- if (bind:find("invprev")) then
+
+ if (bind:find("invprev")) then
Num = Num+1
STi = CurTime()
-
+
if (Num > 9) then Num = 0 end
-
+
net.Start("Select") net.WriteUInt(Num,4) net.SendToServer()
-
+
surface.PlaySound("wintersurvival2/hud/itemequip.wav")
-
+
if (IsValid(Wep)) then
- if (pl.Weapons and pl.Weapons[Num]) then Wep:SetWeaponHoldType(pl.Weapons[Num].Item.HoldType)
+ if (pl.Weapons and pl.Weapons[Num]) then Wep:SetWeaponHoldType(pl.Weapons[Num].Item.HoldType)
else Wep:SetWeaponHoldType("normal") end
end
-
+
return true
- elseif (bind:find("invnext")) then
+ elseif (bind:find("invnext")) then
Num = Num-1
STi = CurTime()
-
+
+ if (Num < 0) then Num = 9 end
+
+ net.Start("Select") net.WriteUInt(Num,4) net.SendToServer()
+
+ surface.PlaySound("wintersurvival2/hud/itemequip.wav")
+
+ if (IsValid(Wep)) then
+ if (pl.Weapons and pl.Weapons[Num]) then Wep:SetWeaponHoldType(pl.Weapons[Num].Item.HoldType)
+ else Wep:SetWeaponHoldType("normal") end
+ end
+
+ return true
+
+ elseif (bind:find("slot")) then
+ Num = tonumber(string.sub(bind,5,5))
+ STi = CurTime()
+
if (Num < 0) then Num = 9 end
-
+
net.Start("Select") net.WriteUInt(Num,4) net.SendToServer()
-
+
surface.PlaySound("wintersurvival2/hud/itemequip.wav")
-
+
if (IsValid(Wep)) then
- if (pl.Weapons and pl.Weapons[Num]) then Wep:SetWeaponHoldType(pl.Weapons[Num].Item.HoldType)
+ if (pl.Weapons and pl.Weapons[Num]) then Wep:SetWeaponHoldType(pl.Weapons[Num].Item.HoldType)
else Wep:SetWeaponHoldType("normal") end
end
-
+
return true
end
end
@@ -57,49 +74,49 @@ if (CLIENT) then function GetRecentSwapTime()
return STi
end
-
- net.Receive("ReceiveSelect",function()
+
+ net.Receive("ReceiveSelect",function()
local pl = net.ReadEntity()
if (!IsValid(pl)) then return end
-
- pl.Select = net.ReadUInt(4)
+
+ pl.Select = net.ReadUInt(4)
local wep = pl:GetActiveWeapon()
-
+
if (!IsValid(wep)) then return end
-
+
if (pl.Weapons and pl.Weapons[pl.Select]) then wep:SetWeaponHoldType(pl.Weapons[pl.Select].Item.HoldType)
else wep:SetWeaponHoldType("normal") end
end)
-
- net.Receive("SetSlot",function()
+
+ net.Receive("SetSlot",function()
local pl = net.ReadEntity()
-
+
if (!IsValid(pl)) then return end
if (!pl.Weapons) then pl.Weapons = {} end
-
+
local id = net.ReadUInt(5)
local na = net.ReadString()
local A = GetItemByName(na)
-
+
if (A) then pl.Weapons[id] = {Name = na,Item = A}
else pl.Weapons[id] = nil end
-
+
pl:EmitSound("wintersurvival2/hud/itemequip.wav")
end)
-
+
function RequestEquip(id,item)
net.Start("SetSlotReq")
net.WriteUInt(id,5)
net.WriteString(item)
net.SendToServer()
end
-
+
function RequestUnEquip(id)
net.Start("SetSlotReqUn")
net.WriteUInt(id,5)
net.SendToServer()
end
-
+
function EraseSlot(id)
net.Start("EraseSlot")
net.WriteUInt(id,5)
@@ -112,50 +129,50 @@ else util.AddNetworkString("SetSlotReq")
util.AddNetworkString("SetSlotReqUn")
util.AddNetworkString("EraseSlot")
-
+
net.Receive("Select",function(siz,pl) pl.Select = net.ReadUInt(4) pl:UpdateSelection() end)
net.Receive("SetSlotReq",function(siz,pl) pl:SetWeaponSlot(net.ReadUInt(5),net.ReadString()) end)
net.Receive("SetSlotReqUn",function(siz,pl) pl:UnEquipWeaponSlot(net.ReadUInt(5)) end)
net.Receive("EraseSlot",function(siz,pl) pl:UnEquipWeaponSlot(net.ReadUInt(5),true) end)
-
+
function meta:UpdateSelection(pl)
- if (self.Select) then
- net.Start("ReceiveSelect")
+ if (self.Select) then
+ net.Start("ReceiveSelect")
net.WriteEntity(self)
net.WriteUInt(self.Select,4)
if (IsValid(pl)) then net.Send(pl)
else net.Broadcast() end
end
-
+
if (self:CanPlaceStructure()) then self:GhostRemove() end
end
-
+
function meta:SetWeaponSlot(id,item)
if (!self:HasItem(item)) then return end
if (!self.Weapons) then self.Weapons = {} end
-
+
self:RemoveItem(item,1)
-
+
local A = GetItemByName(item)
-
+
if (self.Weapons[id]) then self:AddItem(self.Weapons[id].Name,1) end
-
+
self.Weapons[id] = {Name = item,Item = A}
-
+
net.Start("SetSlot")
net.WriteEntity(self)
net.WriteUInt(id,5)
net.WriteString(item)
net.Broadcast()
end
-
+
function meta:UnEquipWeaponSlot(id,bErase)
if (!self.Weapons or !self.Weapons[id]) then return end
-
+
if (!bErase) then self:AddItem(self.Weapons[id].Name,1) end
-
+
self.Weapons[id] = nil
-
+
net.Start("SetSlot")
net.WriteEntity(self)
net.WriteUInt(id,5)
@@ -165,4 +182,4 @@ end function meta:GetSelectedWeapon()
return self.Select or 0
-end
\ No newline at end of file +end
|
