Hey there, i‘ve got a very strange issue.
if i try to give a player more than one weapon at the same time (SWEPs), the player will just receive the first one.
just if i remove the first weapon, he ist able to receive the second... so if you need a code example, here we go:
if not ply:HasWeapon(„ttt_weapon_harp“) then ply:Give(„ttt_weapon_harp“) end
And the same thing multiplied several times. I runned everything in the „TTTBeginRound“ Hook, everything works fine until i try to add more than one weapon.
do you know what happens? And how to fix? If i print the returned output of the second „ply:Give(„...“)“ i will get NULL.
What a hell are these quotation marks?
Sounds like something overwrote your Give function because that shouldn't happen.
post the output of
lua_run PrintTable(debug.getinfo(FindMetaTable("Player").Give))
Okay that's the output of your command @thegrb93
lua_run PrintTable(debug.getinfo(FindMetaTable("Player").Give))
> PrintTable(debug.getinfo(FindMetaTable("Player").Give))...
currentline = -1
func = function: 0xb196e698
isvararg = true
lastlinedefined = -1
linedefined = -1
namewhat =
nparams = 0
nups = 0
short_src = [C]
source = =[C]
what = C
Now all of the code:
if SERVER then
function plymeta:GiveClassWeapon(wep)
self.classWeapons = self.classWeapons or {}
local rt = self:Give(wep)
if rt then
table.insert(self.classWeapons, wep)
end
return rt
end
function plymeta:GiveClassEquipmentItem(id)
self.classEquipment = self.classEquipment or {}
local rt = self:GiveEquipmentItem(id)
if rt then
table.insert(self.classEquipment, id)
end
return rt
end
function plymeta:AddClassEquipmentItem(id)
self.classEquipment = self.classEquipment or {}
table.insert(self.classEquipment, id)
self:AddEquipmentItem(id)
end
function plymeta:AddClassEquipmentItemFix(id)
id = tonumber(id)
if not id then return end
self:GiveClassEquipmentItem(id)
self:AddBought(id)
if not self.classUpdateQueue then
self.classUpdateQueue = 0
end
self.classUpdateQueue = self.classUpdateQueue + 1
local t = 0.5
if self.classUpdateQueue > 1 then
t = t * self.classUpdateQueue
end
timer.Simple(t, function()
if not IsValid(self) then return end
self.classUpdateQueue = self.classUpdateQueue - 1
net.Start("TTT_BoughtItem")
net.WriteBit(true)
net.WriteUInt(id, 16)
net.Send(self)
end)
hook.Run("TTTOrderedEquipment", self, id, true)
end
function plymeta:GiveClassEquipmentWeapon(ply, cls)
-- Referring to players by SteamID because a player may disconnect while his
-- unique timer still runs, in which case we want to be able to stop it. For
-- that we need its name, and hence his SteamID.
if not ply or not IsValid(ply) then return end
local sid = ply:SteamID()
local tmr = "g_cwep_" .. sid .. "_" .. cls
-- giving attempt, will fail if we're in a crazy spot in the map or perhaps
-- other glitchy cases
local w = ply:GiveClassWeapon(cls)
if not IsValid(w) or not ply:HasWeapon(cls) then
print("\n\nTTTC: No Weapon for '" .. ply:Nick() .. "' (cls: " .. cls .. ")")
if not timer.Exists(tmr) then
timer.Create(tmr, 1, 0, function()
self:GiveClassEquipmentWeapon(ply, cls)
end)
end
-- we will be retrying
else
-- can stop retrying, if we were
timer.Remove(tmr)
if w.WasBought then
-- some weapons give extra ammo after being bought, etc
w:WasBought(ply)
end
end
end
function plymeta:AddClassEquipmentWeaponFix(id)
if not id then return end
self:GiveClassEquipmentWeapon(self, id)
self:AddBought(id)
if not self.classUpdateQueue then
self.classUpdateQueue = 0
end
self.classUpdateQueue = self.classUpdateQueue + 1
local t = 0.5
if self.classUpdateQueue > 1 then
t = t * self.classUpdateQueue
end
timer.Simple(t, function()
if not IsValid(self) then return end
self.classUpdateQueue = self.classUpdateQueue - 1
net.Start("TTT_BoughtItem")
net.WriteBit(false)
net.WriteString(id)
net.Send(self)
end)
hook.Run("TTTOrderedEquipment", self, id, false)
end
end
Here i'm running ply:AddClassEquipmentWeaponFix("...") to add a weapon. But the player still receives one instead of two or three weapons...
Are you going to answer that?
Why? That wont be in any case relevant? Quotation marks are quotation marks defining a string. No matter whether my or your device displays these quotation marks different.
To answer it, i believe that this is caused by my mobilephone. In the original file, there are normal quotation marks. In addition to that, that even woulnt cause this problem because i still receive the first weapon, not the following.
I simplified it and just runned the following code with the same result:
hook.Add("TTTBeginRound", "TTT2SelectClasses", function()
-- ... some code
hook.Run("TTT2_ReceiveCustomClass", v)
-- ... some code
end)
hook.Add("TTT2_ReceiveCustomClass", "TTT2BombersClassPackSetup", function(ply)
if ply:Alive() and ply:HasCustomClass() then -- this must be true because the player gets the first weapon
local cls = ply:GetCustomClass()
if cls == CLASSES.AGENT.index then -- in this case: this too
ply:Give("weapon_ttt_adv_disguiser")
ply:Give("weapon_ttt_cloak")
end
end
end)
Could be that a PlayerCanPickupWeapon hook is returning false somewhere.
to get a list of where all the hooks are, run this
lua_run for k, v in pairs(hook.GetTable().PlayerCanPickupWeapon) do PrintTable(debug.getinfo(v)) end
Thanks for you debugging functions The problem is that this hook will never be called if i use ply:Give("..."). I believe, the problem is that the SWEPs have the same slot. I will try to create a workaround.
Sorry, you need to Log In to post a reply to this thread.