Hey Guys,
at the moment im trying to call a weapon function from a different weapon:
The weapon from where the code is called..
function SWEP:Reload()
if self.Owner:HasWeapon("mutagen") then
--????
end
end
The code from the weapon where the function is defined..
function SWEP:PrimaryAttack()
if SERVER then
local ply = self.Owner
if ply.MutagenActiv == 1 then
ply:INNO_Notify("Mutagen noch aktiv!")
return
end
ply.MutagenActiv = 1
ply:INNO_Notify("Mutagen benutzt!")
ply:SetBASEWALKSPEEDMULT(ply:GetBASEWALKSPEEDMULT()+25)
ply:SetJumpPower(ply:GetJumpPower()+60)
ply:EmitSound(self.Secondary.Sound)
ply:INNO_GiveItem('mutagen_efect')
self:Remove()
timer.Simple(7.3,function()
if GetRoundState() ~= 2 then
ply:SetBASEWALKSPEEDMULT(ply:GetBASEWALKSPEEDMULT()-25)
ply:SetJumpPower(ply:GetJumpPower()-60)
end
ply:INNO_TakeItem('mutagen_efect')
ply.MutagenActiv = 0
end)
end
end
I have no idea how i would do that, any ideas?
There is probably a really simple solution but i've programmed quite a lot today so my brain is mush xD
-- Santifocus
You cannot do it unless the weapon you want to fire is active.
There's probably a simpler way of doing what you're trying to do.
What is the function you want to call from the differnet weapon?
Its the second code, yeah i could just write it in the actuall code but that would cause some problems... Actually let me try something
Use a NetworkVar for setting the next reload and checking it in the Reload function.
Because I don't work with NetworkVar I dont know how to use it so I just did it the ugly way:
self.Owner.ReloadCooldown = self.Owner.ReloadCooldown or 0
if self.Owner.ReloadCooldown > CurTime() then
return
else
self.Owner.ReloadCooldown = CurTime() + 1.5
end
An objections? ^^
Table variables aren't predicted so that method will cause jittering clientside - there are examples of how to use NetworkVars on the wiki page. If you declare a var "NextReload" then you will have self:SetNextReload() and self:GetNextReload() available to use.
Yeah i tried but i didnt knew where to define the NetworkVar, beacause putting it in SWEP:Reload would cause errors (nil methode)
Put it inside WEAPON:SetupDataTables
Alright did so,
function SWEP:Reload()
if self:GetReloadCooldown() > CurTime() then
return
else
self:SetReloadCooldown( CurTime() + 1.5 )
end
[...]
function SWEP:SetupDataTables()
self:NetworkVar("Int",0,"ReloadCooldown")
end
Knowing how this works gives me quite a lot more things I can do, thanks man
Sorry, you need to Log In to post a reply to this thread.