Entity turns 180 degress, when clearly stated 90



function SWEP:SecondaryAttack()
if(CLIENT)then
if(self.Rotation.y == 180)then
self.Rotation = Angle(0,0,0)
else 
self.Rotation = self.Rotation + Angle(0,90,0)
self.Owner:PrintMessage(HUD_PRINTCENTER, self.Rotation.y) 
end
self.Weapon:SetNextSecondaryFire(CurTime()+1)
end
end


why does this turn clientside prop 180 degress if i clearly state 90?

If the rotation is 180 and you set it to 0, then you turn it 180 degrees.

But the prop is just a box, which height and width are the same, and the lenght is a bit longer. So it doesnt matter if its 180 or 0 degrees.

Then I have no idea what you’re trying to achieve.

You’re changing this Rotation variable but now you’re talking about boxes?

You’re confusing me.

Tell me exactly what the tool should do.

This SWEP should act like STOOL ghost function (for example thruster or duplicator) and with right click you can rotate the ghost 90 degrees. Note that the model i want to ghost is ** not a cube ** but a box. So it doesnt matter if its rotated 0, or 180. I just need to rotate it 90 degrees.

[lua]Ghost:SetAngles( Ghost:GetAngles() + Angle( 0, 90, 0 ) )[/lua]

?

I don’t think this would help. My current script (above) works only sometimes. Now i noticed that sometimes it turns 90 degrees and other times it turns to 90 and then instantly jumps to 180(or 0).

EDIT:
Can it be caused because its “shared” even if i check if its client?
I just did a debug and noticed that sometimes the check for ==180 fails (sets SWEP:Rotation to 0,180,0, even if it should set it to 0,0,0). So wtf? Why does this happen?

The way Gmod shared works is that it’s executed on both the client and the server, that’s it. The variables aren’t shared in the sense I think you think it is

You’ll have to rely on console commands and usermessages if you want to actually share them.

I don’t know if you are missing it, but consider using Local Angles, too.

No, i use SetAngles(). Dr Magnusson, there is no reason to send that value to server, because i’m trying to create a ghost entity for client.

Is the ghost entity entirely clientside or are you creating it on the server then setting its angles only on the client?

It’d probably help if you posted the code for the whole SWEP.



if (SERVER) then
 
 
   AddCSLuaFile ("shared.lua");
 
 
   SWEP.Weight = 5;
   SWEP.AutoSwitchTo = false;
   SWEP.AutoSwitchFrom = false;
 
end
 
if (CLIENT) then
 
 
   SWEP.PrintName = "Ice spawner";
   SWEP.Slot = 1;
   SWEP.SlotPos = 1;
   SWEP.DrawAmmo = false;
   SWEP.DrawCrosshair = true;
 
end
 
 
SWEP.Author = "Alexaz";
SWEP.Contact = "alexaz.net";
SWEP.Purpose = "Spawn ice cubes.";
SWEP.Instructions = "Left click to spawn, right click to rotate.";
SWEP.Category = "Snowforts"
 
SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
 
SWEP.ViewModel = "models/weapons/v_pistol.mdl";
SWEP.WorldModel = "models/weapons/w_pistol.mdl";
--SWEP.Rotation=Angle(0,0,0)
 
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "none";
 
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";
 
local ShootSound = Sound("beams/beamstart5.wav");
 
function CreateGhost()
if(CLIENT)then
local ghost=ents.Create("prop_physics")
ghost:SetModel("models/alexaz/ice_brick.mdl")
ghost:SetPos(Vector(0,0,0))
ghost:Spawn()
return ghost
end
end
function UpdateGhost(ghoste, vector, angle)
if(CLIENT)then
ghoste:SetPos(vector)
ghoste:SetAngles(angle)
end
end
function SWEP:Reload()
end
function SWEP:Initialize()
self.Rotation=Angle(0,0,0)
end
function SWEP:Think()
if(self.Ghost == nil)then
self.Ghost = CreateGhost()
end
local tr=self.Owner:GetEyeTrace()
UpdateGhost(self.Ghost, tr.HitPos, self.Rotation)
end

function SWEP:PrimaryAttack()
end
 
function SWEP:SecondaryAttack()
if(CLIENT)then
if(self.Rotation == Angle(0,180,0))then
self.Rotation = Angle(0,0,0)
else 
self.Rotation = self.Rotation + Angle(0,90,0)
self.Owner:PrintMessage(HUD_PRINTCENTER, "Wtf") 
end
self.Weapon:SetNextSecondaryFire(CurTime()+1)
print("DEBUG:" .. self.Rotation.y)
else
return
end
end
function SWEP:Deploy()
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
	self.Ghost = CreateGhost()
    return true
end
function SWEP:Holster( wep )
	self.Ghost:Remove()
	return true
end


Here.

Oh and i did a little debug:




DEBUG:0
DEBUG:90
DEBUG:180
DEBUG:0
DEBUG:90


You can see that sometimes it turns to 180, even if “IF” checks that if its ==180

Use the [noparse][lua][/lua][/noparse] tags

Also, I still don’t understand why you’re doing that 180 -> 0 thing, if it doesn’t matter why are you doing it?

Also, the reason why it shows up is because you check before you set it.

So if you check, set it, then read it, it’s not gonna work. That’s why it goes from 180 and then to 0 right after, not 180 to 270.

Then i must keep adding 90 degrees and not bother about that it is out of 360 boundaries?

No, that doesn’t matter.

[lua]
ang = ang % 360
[/lua]