Hi!
I'm currently working on a stealth addon and I'm encountering this problem with Networking, whenever I trigger a net.Send to start the cloaking sound locally this error shows up in the console
Warning! A net message (StopCloakLoop) is already started! Discarding in favor of the new message! (PlayCloakLoop)
[Rogue Stealth] lua/weapons/weapon_roguestealth.lua:37: attempt to call field 'Send' (a nil value)
1. Cloak - lua/weapons/weapon_roguestealth.lua:37
2. unknown - lua/weapons/weapon_roguestealth.lua:60
Warning! A net message (PlayCloakLoop) is already started! Discarding in favor of the new message! (StopCloakLoop)
[Rogue Stealth] lua/weapons/weapon_roguestealth.lua:47: attempt to call field 'Send' (a nil value)
1. Uncloak - lua/weapons/weapon_roguestealth.lua:47
2. unknown - lua/weapons/weapon_roguestealth.lua:60
this only happens in multiplayer (I'm using the DarkRP gamemode for my server) below you'll find the code I'm using
SERVERSIDE:
function SWEP:Cloak( pl )
self:EmitSound( "roguestealth/shadowwalk_begin.wav" )
self.Owner:SetNWBool( "StealthCamo", true )
self.Owner:DrawShadow( false )
net.Start("PlayCloakLoop")
net.Send(self.Owner)
timer.Simple( 0.7, function( ply, surface )
self.Owner:ScreenFade( SCREENFADE.IN, Color( 0, 0, 0, 245 ), 0.25, 0.1 )
end )
end
function SWEP:Uncloak( pl, surface )
net.Start("StopCloakLoop")
net.Send(self.Owner)
self:EmitSound( "roguestealth/shadowwalk_end.wav" )
self.Owner:SetNWBool( "StealthCamo", false )
self.Owner:DrawShadow( true )
end
CLIENTSIDE:
net.Receive("PlayCloakLoop", function(len, ply)
LocalPlayer():StartLoopingSound("roguestealth/shadowwalk_loop.wav")
end)
net.Receive("StopCloakLoop", function(len, ply)
LocalPlayer():StopLoopingSound(0)
end)
net.Send is a serverside only function (marked by the blue square in the wiki) and you are attempting to run it shared. Simply put those net messages in an if server statement:
if (SERVER) then
net.Start()
net.Send()
end
You're a lifesaver! Now I also know about the colors in the wiki
One last thing, I don't wanna bother too much, I want to make it so if the player is entering a vehicle while being cloaked it automatically uncloaks itself, so far i've tried doing this:
if (SERVER) then
hook.Add("PlayerEnteredVehicle", "UncloakEnteringVehicle", function(ply, veh, seat) if SWEP:IsCloaked() and SWEP:Clip1() > 0 then SWEP:Uncloak() end
end)
end
but when I enter the vehicle it gives me this error
[Rogue Stealth] lua/weapons/weapon_roguestealth.lua:83: attempt to index global 'SWEP' (a nil value)
1. v - lua/weapons/weapon_roguestealth.lua:83
2. unknown - lua/includes/modules/hook.lua:84
how do I call a swep function from a GM hook?
The SWEP table exists only in the weapon files and SWEP is a metatable for all weapon objects, so calling SWEP in any in-game function will call a metatable not the current SWEP you hold
So how should I call these SWEP functions in this situation?
Player:GetActiveWeapon
if (SERVER) then
hook.Add("PlayerEnteredVehicle", "UncloakEnteringVehicle", function(ply, veh, seat)
local equippedweapon = ply:GetActiveWeapon()
if equippedweapon:IsCloaked() and equippedweapon:Clip1() > 0 then equippedweapon:Uncloak() end
end)
end
It worked, thanks for helping me
Sorry, you need to Log In to post a reply to this thread.