forked from TeamUlysses/ulib
Fix Weapon SetClipErrors (#76)
* fix: result isn't used in this context. * fix: the docs say ply, we use ply. * perf: we don't need to call that twice. * fix: printname isn't a name, it's class. localise class. * fix: fix weapon error if not given. replace printname with class. only call getweapon if we can't get it through give. * fix: Make sure SetClip1 and SetClip2 actually exist before we call them.
This commit is contained in:
parent
f401c2a656
commit
bde520a16a
@ -207,26 +207,27 @@ end
|
|||||||
|
|
||||||
Updates player object to store health and armor. Has no effect unless ULib.Spawn is used later.
|
Updates player object to store health and armor. Has no effect unless ULib.Spawn is used later.
|
||||||
]]
|
]]
|
||||||
function ULib.getSpawnInfo( player )
|
function ULib.getSpawnInfo( ply )
|
||||||
local result = {}
|
|
||||||
|
|
||||||
local t = {}
|
local t = {}
|
||||||
player.ULibSpawnInfo = t
|
ply.ULibSpawnInfo = t
|
||||||
t.health = player:Health()
|
|
||||||
t.armor = player:Armor()
|
t.health = ply:Health()
|
||||||
if player:GetActiveWeapon():IsValid() then
|
t.armor = ply:Armor()
|
||||||
t.curweapon = player:GetActiveWeapon():GetClass()
|
|
||||||
|
local wep = ply:GetActiveWeapon()
|
||||||
|
if IsValid( wep ) then
|
||||||
|
t.curweapon = wep:GetClass()
|
||||||
end
|
end
|
||||||
|
|
||||||
local weapons = player:GetWeapons()
|
|
||||||
local data = {}
|
local data = {}
|
||||||
|
local weapons = ply:GetWeapons()
|
||||||
for _, weapon in ipairs( weapons ) do
|
for _, weapon in ipairs( weapons ) do
|
||||||
printname = weapon:GetClass()
|
local class = weapon:GetClass()
|
||||||
data[ printname ] = {}
|
data[ class ] = {}
|
||||||
data[ printname ].clip1 = weapon:Clip1()
|
data[ class ].clip1 = weapon:Clip1()
|
||||||
data[ printname ].clip2 = weapon:Clip2()
|
data[ class ].clip2 = weapon:Clip2()
|
||||||
data[ printname ].ammo1 = player:GetAmmoCount( weapon:GetPrimaryAmmoType() )
|
data[ class ].ammo1 = ply:GetAmmoCount( weapon:GetPrimaryAmmoType() )
|
||||||
data[ printname ].ammo2 = player:GetAmmoCount( weapon:GetSecondaryAmmoType() )
|
data[ class ].ammo2 = ply:GetAmmoCount( weapon:GetSecondaryAmmoType() )
|
||||||
end
|
end
|
||||||
t.data = data
|
t.data = data
|
||||||
end
|
end
|
||||||
@ -238,13 +239,24 @@ local function doWeapons( player, t )
|
|||||||
player:StripAmmo()
|
player:StripAmmo()
|
||||||
player:StripWeapons()
|
player:StripWeapons()
|
||||||
|
|
||||||
for printname, data in pairs( t.data ) do
|
for class, data in pairs( t.data ) do
|
||||||
player:Give( printname )
|
local weapon = player:Give( class )
|
||||||
local weapon = player:GetWeapon( printname )
|
if not IsValid( weapon ) then
|
||||||
weapon:SetClip1( data.clip1 )
|
weapon = player:GetWeapon( class )
|
||||||
weapon:SetClip2( data.clip2 )
|
end
|
||||||
player:SetAmmo( data.ammo1, weapon:GetPrimaryAmmoType() )
|
|
||||||
player:SetAmmo( data.ammo2, weapon:GetSecondaryAmmoType() )
|
if IsValid( weapon ) then
|
||||||
|
if weapon.SetClip1 then
|
||||||
|
weapon:SetClip1( data.clip1 )
|
||||||
|
end
|
||||||
|
|
||||||
|
if weapon.SetClip2 then
|
||||||
|
weapon:SetClip2( data.clip2 )
|
||||||
|
end
|
||||||
|
|
||||||
|
player:SetAmmo( data.ammo1, weapon:GetPrimaryAmmoType() )
|
||||||
|
player:SetAmmo( data.ammo2, weapon:GetSecondaryAmmoType() )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if t.curweapon then
|
if t.curweapon then
|
||||||
|
Loading…
Reference in New Issue
Block a user