Hey, how can i do that?
An example.. i want to clamp SetPos to Max map size..
My code is:
[LUA]
local RSetPos = _R.Entity.SetPos
_R.Entity.SetPos = function(pos)
local MinMax = 16384
pos.x = clamp(pos.x,-MinMax,MinMax)
pos.y = clamp(pos.y,-MinMax,MinMax)
pos.z = clamp(pos.z,-MinMax,MinMax)
RSetPos(pos)
end
[/LUA]
but it ends in an Infite loop.. SetPos call RSetPos call SetPos call RSetPos.............
How do i do that?
It would be usefull, to clamp values that crash garrysmod (force, physic, position, angles etc.)
Your code is good as far as I can tell, but if it's ran more than once it can become unstable.
Change:
local RSetPos = _R.Entity.SetPos
To:
RSetPos = RSetPos or _R.Entity.SetPos
This ensures that the old function does not get 'lost'.
[editline]1st October 2012[/editline]
Yeah, also your prototype is wrong, it should be function(self, pos)
Your concept isn't going to work since VPhysics is calling functions from the engine, not the ones in the Lua state.
Sorry, you need to Log In to post a reply to this thread.