ENT:(Set/Get)NWVector Does not seem to stanfer data cl-sv
9 replies, posted
Hello,
As i was Coding my New Sent I used the functions in question here:
[url]http://wiki.garrysmod.com/page/Entity/SetNWVector[/url]
[url]http://wiki.garrysmod.com/page/Entity/GetNWVector[/url]
My code is as follows:
[code]
-- SERVER
function TOOL:Think()
if(CLIENT) then return false end
Tr = self:GetOwner():GetEyeTrace()
if(not Tr) then return end
trEnt = Tr.Entity
if(not trEnt or not
trEnt:IsValid() or
trEnt:GetClass() ~= "gmod_magnetdipole")
then return end
print("SetNWVector: "..tostring(trEnt.MagData.SVec).." !")
trEnt:SetNWVector("magnetdipole_svec_dir", trEnt.MagData.SVec)
trEnt:SetNWVector("magnetdipole_nvec_dir", trEnt.MagData.NVec)
return true
end
[/code]
[code]
function TOOL:DrawHUD()
if(SERVER) then return false end
Tr = self:GetOwner():GetEyeTrace()
if(not Tr) then return end
trEnt = Tr.Entity
if(not trEnt or not trEnt:IsValid()) then return end
local SPos = Vector()
local NPos = Vector()
if(trEnt:GetClass() == "gmod_magnetdipole") then
local Length = tonumber(self:GetClientInfo("length")) or 0
local Ang = trEnt:GetAngles()
local SDir = trEnt:GetNWVector("magnetdipole_svec_dir",Vector(0,0,0))
print("GetNWVector: "..tostring(SDir).." !")
--- The rest is not important ( using this this data in surface.Draw ... )
[/code]
In the console I have like so ( something else ~= Vector(0,0,1) ):
[code]
SetNWVector: 0.000000 0.000001 1.000000 ! --- Data is read from the server correctly, but is it stored correctly ?
GetNWVector: 0.159599 -0.048604 -0.954226 ! --- Get gives Crappy data, not nil ( Vector(0,0,0) ) Read correctly or incorrectly
SetNWVector: 0.000000 0.000001 1.000000 !
GetNWVector: -0.271833 -0.102626 -0.924097 !
GetNWVector: -0.647282 -0.142769 -0.706416 !
SetNWVector: 0.000000 0.000001 1.000000 !
GetNWVector: -0.890651 -0.160897 -0.345303 !
SetNWVector: 0.000000 0.000001 1.000000 !
GetNWVector: -0.952609 -0.153335 0.086048 !
GetNWVector: -0.820600 -0.121617 0.500206 !
SetNWVector: 0.000000 0.000001 1.000000 !
[/code]
It's not supposed to.
I'm still trying to figure out whats going on here D:
Nice title. It's not supposed to transfer data cl -> sv, but it seems you are doing the proper way, sv -> cl.
Yes exactly what i thought !
I thought as much, but if he is doing it the right way why is he getting weird behaviour?
Try testing with something that is not a vector.
You could try 3 ints i guess.
The strange thing is on my other Addons it works flawlessly:
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=287015702[/url]
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=287015431[/url]
With Vector and Float
[editline]17th July 2014[/editline]
Should it be because of stepping over sample times ?
[code]
function ENT:Think()
local NextTime = CurTime() + 0.02
local Phys = self:GetPhysicsObject()
if(Phys:IsValid() and self.MagData.On) then
self.MagData.Centre:Set(self:LocalToWorld(self:OBBCenter()))
self.MagData.SPos:Set(vPosPlusVecMulNum(self.MagData.Centre,
self.MagData.SVec,
self.MagData.Length / 2) )
self.MagData.NPos:Set(vPosPlusVecMulNum(self.MagData.Centre,
self.MagData.NVec,
self.MagData.Length / 2) )
if(WireLib) then
WireLib.TriggerOutput(self,"eMagnet",self)
end
end
self:NextThink(NextTime)
return true
end
[/code]
[editline]17th July 2014[/editline]
But i doubt that ....
Transferring 3 floats instead of a vector works perfectly !
Sorry, you need to Log In to post a reply to this thread.