Networking is not-working? 2

Im not sure if im cursed when it comes to networking or just bad at it. Anyways this time I have been trying to network an entity to client.



function SetSuspectInfo(ply,headshots,viewsnaps,wallkills)

	net.Start( "SuspectShareData" )
	net.WriteEntity(ply)
	net.WriteInt(headshots,32)
	net.WriteInt(viewsnaps,32)
	net.WriteInt(wallkills,32)
	net.Broadcast()
	
	print(ply)
	print(headshots)
	print(viewsnaps)
	print(wallkills)
	
end

-- client below

net.Receive( "SuspectShareData", function()

	local ply = net.ReadEntity()
	local headshots = net.ReadInt(32)
	local viewsnaps = net.ReadInt(32)
	local wallkills = net.ReadInt(32)

	print(ply)
	print(headshots)
	print(viewsnaps)
	print(wallkills)

end )


This returns the following.



Player [1][Leafdroid]
1
2
3
-- client below
[NULL Entity]
1
2
3


Why is the float valid but the entity isnt?

I need help with this again. Last time I did a cheap fix by setting the weapons skins and then getting the damage by doing something like (SharedTable[weapon:GetSkin()].Damage) but I cant do that this time. Whats wrong with the code above? (Edited it from last time)

May this be something?

From the wiki

I don’t know what information you need from the player but maybe you can replace net.writeentity with something else?

You could write player’s userID in net message instead of the player entity itself, and then replace net.ReadEntity() with Player(net.ReadInt(32)) clienside.

I dont think I can since I need to set a variable to the players entity. Unless I turn it into an integer with the players ID and cycle through all the players and find the one who matches it.

Have you tried using a timer? Sometimes if the entity is freshly spawned on the server, it takes a few milliseconds for it to get networked correctly to the client.

Also, some entities only exist serverside.

Yep.

Dont think players are one of those entities.

Try this but with -noaddons -noworkshop

[editline]3rd October 2017[/editline]

ON THE server

Didn’t work either, instead I ran “ply.ID = #player.GetAll()” in initialspawn and networked the ID, then found the player using “player.GetByID()”.

Why would you do that though?

Imagine a situation: 2 players join a server, they have ids 1 and 2, then player 1 leaves and another player joins, #player.GetAll() is 2 because 2 players are online so player 3 gets id 2, result: both players have id 2.

Did my solution not work? http://forum.facepunch.com/showthread.php?t=1580556&p=52742325&viewfull=1#post52742325

Edit: example of using it


if SERVER then
    util.AddNetworkString("net_test")

    hook.Add("DoPlayerDeath", "Networking test", function(plr)
        net.Start("net_test")
        net.WriteInt(plr:UserID(), 32) -- edit : I forgot the '32' initially 
        net.Broadcast()
    end)
else
    net.Receive("net_test", function()
        local plr = Player(net.ReadInt(32))
        chat.AddText("Player ", plr:Nick(), " has died!")
    end)
end

This is what I tried first, but for some reason ply:UserID() returned like 29 even tho I was alone on the server and player.GetByID(29) wasnt valid.

Because player.GetByID() doesn’t return by UserID, Player() does, see my example.

Can you post the rest of your code or at least a small example so I can test?

No need I got it all figured out.