• Where should i put a net.receive to add it on everyplayer ?
    2 replies, posted
Hi, I wonder where i should put this : if CLIENT then   net.Receive("removeCallBackOnPlayer", function()     local targetPly = net.ReadEntity()     targetPly:RemoveCallback("BuildBonePositions", targetPly.bbpcbid)     targetPly.bbpcbid = nil   end) end If i need to add it to every players in the server ? It's meant to be used by a swep to send animation. Here is the code function SWEP:PrimaryAttack()   if not IsFirstTimePredicted() then return end   self:AddPlayerCallback() end function SWEP:SecondaryAttack()   if not IsFirstTimePredicted() then return end   self:BroadcastRemoveCallback() end function SWEP:BroadcastRemoveCallback()   if SERVER then     net.Start("removeCallBackOnPlayer")       net.WriteEntity(self.Owner)     net.Broadcast()   end end function SWEP:DrawWorldModel() return false end function SWEP:Deploy() self.Owner:DrawViewModel(false) end function SWEP:DoKickAnimation(ply)   local rightFoot = ply:LookupBone("ValveBiped.Bip01_R_Foot")   local head = ply:LookupBone("ValveBiped.Bip01_Head1")   local rShoulder = ply:LookupBone("ValveBiped.Bip01_R_Shoulder")   local lShoulder = ply:LookupBone("ValveBiped.Bip01_L_Shoulder")   local headPos,headAng = ply:GetBonePosition(head)   ply:SetBonePosition(head, headPos + Vector(0,0,10), headAng) end function SWEP:AddPlayerCallback()   if self.Owner.bbpcbid == nil then     print("triggered")     if self.Owner:IsValid() then       print("??")       self.Owner.bbpcbid = self.Owner:AddCallback("BuildBonePositions", function(ent) self:DoKickAnimation(ent) end)       print(self.Owner.bbpcbid)     end   end end function SWEP:Initialize()   self:SetHoldType(self.HoldType) end if CLIENT then   net.Receive("removeCallBackOnPlayer", function()     local targetPly = net.ReadEntity()     targetPly:RemoveCallback("BuildBonePositions", targetPly.bbpcbid)     targetPly.bbpcbid = nil   end) end Is that correct ?
Yes, that works out. Doing net.Broadcast() will send it to all the players, as soon as the weapon is taken out ALL the players will run this SWEP code, if you shoot it using PrimaryFire then ALL the clients will run the piece of code inside that function (So make sure to remember to use the owner of the SWEP and not LocalPlayer()). This means that they even run the "net.Receive" part of the code, so you're fine putting it there. If they receive the "removeCallBackOnPlayer" (Which is being broadcast by the server) then they will run the piece.
Thanks i tested it like 2 mins after posting the thread, it's working super fine i'm surprised. Thanks anyway ubre <3 here is a coin !
Sorry, you need to Log In to post a reply to this thread.