Does anyone know the technical reason why util.IsInWorld is serverside only? Has this ever been addressed before? If it hasn't, would it be appropriate to raise an issue on the garrysmod-issues GitHub?
Seeing as it's not in the GitHub repo anywhere, it's probably an engine issue or internal game issue then.
Even then, what does it matter? Nothing is stopping you from just defining ENT:IsInWorld() on the client like Entity/IsInWorld
-- Clientside ENT:IsInWorld
if CLIENT then
local ENTITY = FindMetaTable("Entity")
function ENTITY:IsInWorld()
return self:GetNWBool("IsInWorld")
end
end
if SERVER then
AddCSLuaFile()
local ENTS = ents.GetAll
hook.Add("Think", "IsInWorldThink", function()
for _, ent in ipairs(ENTS()) do
ent:SetNWBool("IsInWorld", ent:IsInWorld())
end
end)
end
The network traffic created is barely noticeable above the normal traffic. And if you don't need it all the time you could easily just use the net library to send messages back and forth for certain entities.
You could do as suggested by @Doctor Jew but hook onto ENTITY/CalcAbsolutePosition as then you only update the bool when needed as that hook is only updated when the position changes.
How would that work with different map sizes though?
Also not sure why the dumb ratings. Please, if others have a better solution then offer it.
The reason it is serverside only I think is because that is how it is defined inernally in the engine, so that the client cannot have invalid information (eq the position being in the world, but client thinks it is not), maybe it could lead to some problems (probably). If you need constantly checking if a position is in world on the client, you are most likely approaching the task wrong. If you just need to check it from time to time, you can ask the server using Net messages, as Doctor Jew suggested.
You can hook into it using Entity/AddCallback I believe
You can only hook into angle changes like that, not position changes. There really is no better way to do it without constantly networking the value or occasionally updating it with net messages. The former being always accurate but potentially slower, the latter being frames behind/outdated but way less network usage.
@TomatoSoup could you maybe provide more info on what are you trying to do so we can help you figure out the least painful way to do it?
If you must know, it is not possible because the serverside system IsInWorld function relies on doesn't exist on client. I did a quick look around and I haven't found anything to replace it.
You may be able to replicate it using traces or util.PointContents but I am not sure.
So...It doesn't use physics functions like tracehull?
Keep in mind this has nothing to do with any entity, it checks a position, which probably uses the map info to differ between world and outside of world positions.
I'm pretty sure it uses TraceBox on the world's PhysCollide which wouldn't work on the client since the world's physics object only exists serverside.
Are you referring to the fact that Entity:GetPhysicsObject doesn't return a physics object on the client? IIRC there's some code in the source sdk that initializes the world's physics object on the client
Please pardon my delay in responding to this thread.
I have a table that contains physically simulated bullets. They are not entities, just a table of positions, velocities, and a few other vital details. I'm interested in determining if, after moving a bullet forward one frame, if it is now out of bounds and should not be considered for simulation anymore. I appreciate the thoughts for networked variables and things like that, but they're not so applicable to this. Due to how the server and client create the bullets, I can't even guarantee that they have the same unique ID to allow the server to tell the client to delete a bullet. I appreciate the util.PointContents reference. I expect to use it for another problem even though its not applicable to this; the bullets can penetrate walls so simply checking if their position is inside a solid won't cut it.
It strikes me as odd that the client doesn't have the necessary mechanisms. How is it not determinable from only the map data? This is a rhetorical question, because to actually answer it I'm sure would take quite a dive through the Source engine.
Perhaps something with the World entity and it's bounding sphere/box? Does that sound sane? My true goal is only to cut off bullets that penetrate a map's outer walls and won't interact with anything interesting for the rest of their lifespan (they're removed after so many seconds at current).
No, it uses some sort of clustering system, which is also used in some entities for audio purposes.
Seeing as the maximum size of a map is 32768^3, any vector with an x, y or z with an absolute value over 16384 could be considered outside the world bounds, but that assumes the map is a full sized source map.
Although, this really shouldn't be a problem outside of highly specific edge cases if your bullets take the surfaces they hit into account. I understand you're trying to make bullets go through walls, but you can use the TraceResult Structure "FractionLeftSolid" with some traces to determine how thick a surface is when tracing through it, since outside the world is completely solid, this should delete them once they hit it.
Although, keep in mind that displacements are less than paper thin, and traces only interact with one side of them, so people can technically shoot through mountains. It's not ideal, but I disable penetration through displacements because of this in my ballistic system.
The traces do take in to account the distance of solid material they go through. I guess in the cases I've been testing that edge of the map was made with a displacement (and so it's sailing through the empty void). How can I tell if my trace has impacted a displacement?
Sorry, you need to Log In to post a reply to this thread.