net.WriteEntity() is always giving the client a NULL entity.
9 replies, posted
This is a basic prop protection script and for some reason when I try to set the owner of an entity on the client it says the entity sent over is NULL. I haven't been able to figure out what I am doing wrong, maybe someone else can tell?
I've tried including the entity in the SetPPOwner arguments just like pl but it still shows up NULL on the client. I have also tried setting where SetPPOwner is applied in the Test1 command to after the prop is spawned but still no luck.
[U]SERVER[/U]
[lua]
function ENTITY:SetPPOwner( pl )
print("sv:Set() "..pl:Nick().." "..type(self).." "..tostring(self:GetClass()))
if pl != NULL then
Prop_Protection.Entities[self:EntIndex()] = { pl, pl:Nick(), self }
else
Prop_Protection.Entities[self:EntIndex()] = { pl, "World", self }
end
net.Start( "Net_Prop_Protection" )
net.WriteFloat( 1 )
net.WriteEntity( pl )
net.WriteEntity( self )
net.Broadcast()
end
function Test1( pl, cmd, arg )
local ent = ents.Create("prop_physics")
ent:SetPPOwner( pl )
ent:SetPos( pl:GetPos()+Vector( 70, 0, 0 ) )
ent:SetAngles( pl:GetAngles() )
ent:Spawn()
ent:Activate()
end
concommand.Add( "Test1", Test1 )
[/lua]
[U]CLIENT[/U]
[lua]
net.Receive( "Net_Prop_Protection", function( len )
local Connection = tonumber( net.ReadFloat() )
if Connection == 1 then
local pl = net.ReadEntity()
local ent = net.ReadEntity()
Prop_Protection.Entities[ent:EntIndex()] = { pl, pl:Nick(), ent }
PrintTable(Prop_Protection.Entities[ent:EntIndex()])
end
end )
[/lua]
So i'm guessing you've already got this in the serverside files..
[lua]util.AddNetworkString( "Net_Prop_Protection" )[/lua]
Do this i had the same problem ;)
[lua]timer.Simple(0.1, function()
net.Start( "Net_Prop_Protection" )
net.WriteFloat( 1 )
net.WriteEntity( pl )
net.WriteEntity( self )
net.Broadcast()
end)[/lua]
Hmm... could be because you are calling SetPPOwner before spawning the entity, so it's not valid on the client yet
[QUOTE=TweaK2007;39925726]Hmm... could be because you are calling SetPPOwner before spawning the entity, so it's not valid on the client yet[/QUOTE]
Already tried that, doesn't work.
[QUOTE=RetTurtl3;39925699]So i'm guessing you've already got this in the serverside files..
[lua]util.AddNetworkString( "Net_Prop_Protection" )[/lua]
Do this i had the same problem ;)
[lua]timer.Simple(0.1, function()
net.Start( "Net_Prop_Protection" )
net.WriteFloat( 1 )
net.WriteEntity( pl )
net.WriteEntity( self )
net.Broadcast()
end)[/lua][/QUOTE]
That worked, how did you know that would work? And why does this happen?
[QUOTE=find me;39925872]Already tried that, doesn't work.
That worked, how did you know that would work? And why does this happen?[/QUOTE]
Net is delayed when sending entitys
[QUOTE=RetTurtl3;39925923]Net is delayed when sending entitys[/QUOTE]
You don't happen to know any other net secrets do you? haha
Has this ever caused a problem for you besides having to add the timer? I was thinking about using the entity index instead of the entity itself.
[QUOTE=find me;39925956]You don't happen to know any other net secrets do you? haha
Has this ever caused a problem for you besides having to add the timer? I was thinking about using the entity index instead of the entity itself.[/QUOTE]
If that detours the delay then why isn't that being used instead?
[QUOTE=Ice Tea;39926001]If that detours the delay then why isn't that being used instead?[/QUOTE]
If the delay has caused a problem before I would rather use entity index to not have to worry. Otherwise if the only problem it causes is a slight delay I can deal with that considering it would be faster just sending the entity.
Actually, if you create an Entity on the server and in the same swoop send that entity to the client via net message, it shows as null on the client. If you surround the net message with a timer.Simple with a delay of 0.1 then the entity will send through just fine.
I'd almost consider this a bug, and it's one of the reasons why I wrote and use this bit of code:
[lua]ENTITY = FindMetaTable("Entity");
function ENTITY:GetID( )
if ( !self.ID ) then
self.ID = string.gsub( tostring( self ), "%D", "");
return self.ID;
else
return self.ID;
end
end[/lua]
Get the id on the server side, send the id to the client, and have the client grab it using the entity by index or sub method. You're also reducing net traffic by doing it this route.
[QUOTE=Acecool;39926149]Actually, if you create an Entity on the server and in the same swoop send that entity to the client via net message, it shows as null on the client. If you surround the net message with a timer.Simple with a delay of 0.1 then the entity will send through just fine.
I'd almost consider this a bug, and it's one of the reasons why I wrote and use this bit of code:
[lua]ENTITY = FindMetaTable("Entity");
function ENTITY:GetID( )
if ( !self.ID ) then
self.ID = string.gsub( tostring( self ), "%D", "");
return self.ID;
else
return self.ID;
end
end[/lua]
Get the id on the server side, send the id to the client, and have the client grab it using the entity by index or sub method. You're also reducing net traffic by doing it this route.[/QUOTE]
That's exactly what I meant by using the entity index instead of the delayed entity because it would do exactly what you said by reducing net traffic.
Sorry, you need to Log In to post a reply to this thread.