I made an entity and i want it to change the firerate with which the player using it will shoot. Here is my code, I used a timer to make a loop to be able to change the firerate of all the player's weapons and the weapons he will buy in the further. The problem is that it only change the firerate of the weapon he had in his hands (his activeweapon). Here is my code:
cl_init.lua:
net.Receive("SWEP_Change_Firerate", function(len)
local swepID = net.ReadInt(16)
local SWEP = Entity(swepID)
if !IsValid(SWEP) or !SWEP.Primary or !SWEP.Primary.Delay then return end
SWEP.Primary.Delay = (SWEP.Primary.Delay*0.01)
end)
init.lua:
local NextUse = {}
function ENT:Use(activator, caller)
if not self:GetObjectOwner():IsValid() then
self:SetObjectOwner(activator)
end
local owner = self:GetObjectOwner()
local owneruid = owner:IsValid() and owner:UniqueID() or "nobody"
local myuid = activator:UniqueID()
local wep = activator:GetActiveWeapon()
timer.Create( "reldelay", 1, 100, function()
if !IsValid(wep) then return end
net.Start("SWEP_Change_Firerate")
net.WriteInt(wep:EntIndex(), 16)
net.Send(activator)
end)
end
What exactly is the issue? It will only change the firerate of the active weapon of the player who used the entity as you made it.
What I'm trying to do is to change the firerate of all the weapons that the player has and will have. So I used a timer to make a loop, to constantly change the firerate of the activeweapon from the player and with this be sure that when he changes weapon it will also apply the net.Start("SWEP_Change_Firerate") on it.
Hope you see what I mean.
This would be better implemented in the actual weapon code instead of changing variables. You should make a GetFireRate function for the targeted weapons that scales its return based on some variable set by your ENT:Use.
Ok, so here I've tried to use a way but I would need help please
function ChangeFirerate( ply, entity )
if ( !IsValid( ent ) or !ent:GetClass() == "prop_fire" ) then
end
hook.Add( "PlayerUse", "ChangeFirerate", ChangeFirerate )
Sorry, you need to Log In to post a reply to this thread.