Making a number/float opposite

So… Heres the deal im trying to make a crosshair for a weapon base im currently working on… But im having one small issue…
I cannot get the left and upper part of the cross to work and as a result this is what i currently have

Im assuming i can get it fixed by reversing the x position with what im currently using at the moment… But i have absolutly no idea how though (its probably something obvious… :suicide:)



function SWEP:DrawHUD()
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)
    
    --This is the part where it goes wrong
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 * self.GunSpread * -1, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 * self.GunSpread * -1, ScrH() / 2 - 1, 20, 3)
    --End of the problem
    
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)
end


Replace self.GunSpread * -1 with self.GunSpread for upper & left ones.

Doing that results in this:

http://gyazo.com/a1b8dd7f2c6e06cbf17f3243565ff854.png

Incase you wonder what the “self.GunSpread” variable is its: 0.23



function SWEP:DrawHUD()
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)
    
    --This is the part where it goes wrong
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 * self.GunSpread, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 * self.GunSpread, ScrH() / 2 - 1, 20, 3)
    --End of the problem
    
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)
end


ScrW() / 2 + self.GunSpread, it’s plus, not multiply. Can you do like simple math and some common sense?



function SWEP:DrawHUD()
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 + 20 * self.GunSpread * 10, ScrH() / 2 - 1, 20, 3)
    
    --This is the part where it goes wrong
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 + self.GunSpread, ScrH() / 2 - 1, 20, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 + self.GunSpread, ScrH() / 2 - 1, 20, 3)
    --End of the problem
    
    surface.SetDrawColor( 255, 255, 255, 255)
    surface.DrawRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - 2, ScrH() / 2 + 20 * self.GunSpread * 10, 3, 20)
end


http://gyazo.com/7886fe537aad97969388b7d7c9a3f1e4.png

Good god man

[editline]01 February 2014[/editline]

“Also note that all these values are PIXELS, not a scale. (Unlike Gmod9 lua)” -Maurits
Its not even possible to plus a 0.23 variable when its in pixels



function SWEP:DrawHUD()
	local w = 20
    surface.SetDrawColor( 255, 255, 255, 255)--right
    surface.DrawRect( ScrW() / 2 + w * self.GunSpread * 10, ScrH() / 2 - 1, w, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 + w * self.GunSpread * 10, ScrH() / 2 - 1, w, 3)

    surface.SetDrawColor( 255, 255, 255, 255)--left
    surface.DrawRect( ScrW() / 2 - w * self.GunSpread * 10 - w, ScrH() / 2 - 1, w, 3)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - w * self.GunSpread * 10 - w, ScrH() / 2 - 1, w, 3)

    surface.SetDrawColor( 255, 255, 255, 255)--	bottom
    surface.DrawRect( ScrW() / 2 - 2, ScrH() / 2 + w * self.GunSpread * 10, 3, w)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - 2, ScrH() / 2 + w * self.GunSpread * 10, 3, w)

    surface.SetDrawColor( 255, 255, 255, 255)--	top
    surface.DrawRect( ScrW() / 2 - 2, ScrH() / 2 - w * self.GunSpread * 10 - w, 3, w)

    surface.SetDrawColor( 0, 0, 0, 255 )
    surface.DrawOutlinedRect( ScrW() / 2 - 2, ScrH() / 2 - w * self.GunSpread * 10 - w, 3, w)
end

Feels like you are ( Sorry, but it’s true ) too dumb to copy & paste and invert the variables. Like, replace + with -.

I even added a size parameter for you.

Jeez… I know i was bloody retarded but there wasnt need to point that out…
Anyway thanks! Its working now