How would i go about after i spawn a entity only make it visable to one baseplayer?
Limit entity network to player?
limit networking and send it to one or with hooks. also other bit more unusual ways using ingame networking system
The simplest way to consistently network an entity to only specific players is to use the CanNetworkTo hook. However, keep in mind that the method that hook is called in is called very often, especially in large bursts such as when a player spawns or teleports. When Oxide calls a hook that a plugin is subscribed to, it adds some overhead, which is very small, about a microsecond or less depending on the hardware. That is very fast, but consider that a burst of 10k entities would therefore translate to 10ms which is a significant portion of a frame's budget time. When you also add the computational cost if invoking your method that many times, the conclusion is that using a hook such as CanNetworkTo can cause FPS drops and even small frequent lag spikes, depending on sever population, entity count and player behavior.
There are some alternatives, but they will either be much more complex to implement, or only applicable in certain situations, or require using Harmony with sandboxing disabled (which will make it harder for your users to adopt). Therefore, my general recommendation is to try to think of an alternative solution to the original problem you are trying to solve. If you can share more about that problem, folks here may be able to provide some suggestions.
Im trying to limit the boombox visability/sound to a player
One approach you could explore would be to limit networking and then send a snapshot to the player explicitly.
The next problem would be that if the entity changes state, such as if the player changes the station, you would have to detect that and send the player an update. The preferred way to detect changes would be using hooks. I assume no hooks have been added for boomboxes yet, so you would need to add them. For prototyping the end to end solution before hooks are added, you could periodically check the boombox for changes to detect when something has changed.
Similarly, when the boombox is killed, you would probably have to send another update to the client to terminate it client side.
Nothing would change in the state that i spawn and despawn it..
Do you got an example on how i would limit networking and then send a snapshot to the player
I don't have an example since I've never implemented it. However, I believe it should be as simple as setting limitNetworking to true, spawning the entity, then calling something like SendAsSnapshot with the player connection as an argument. You can look around the game code to see how these properties and methods work. You can also look at TerminateOnClient to see how to tell a client to destroy an entity.
Thanks i tried but seems it works sending the snapshot i can see the entity but then it stops the sound.
I'm sure it's a solvable problem. You'll just have to debug it and figure it out. Good luck.Ts3hostingThanks i tried but seems it works sending the snapshot i can see the entity but then it stops the sound.