# special vector pos

hey, how could i make like this:

entity pos is 100 X
it auto sets to an 32 number, so 100 would be 96
but if its 330 X it should go to 320

so, that it must be an *x32 number

ehm… i dont know how i can explain it more hope its enough.

Use modulus.
x = x - x % 32

x % n will give you the remaining numbers after an integer division. So 1 % 4 = 1, 2 % 4 = 2, 3 % 4 = 3, 4 % 4 = 0, 5 % 4 = 1 and so on.

so,

local x = ply:GetPos().x - ply:GetPos().x % 32
correct?

Actually, yes. But you could improve the code by just calling ply:GetPos().x once:

local x = ply:GetPos().x;
x = x - x % 32;

This should work. Tell us, if it works for you as expected.

works great.
Thank you!

but 1 more thing, why are you using the “;” behind every line? since as far as i know its not needed

local x = ply:GetPos().x;
x = x - x % 32;

works same as whitout them?

“;” is C syntax that Garry added to make it easier for people who are used to C to code in Lua. It’s not required.

I code other languages such as JavaScript,PHP and C++. There it is necessary so I do it in Lua too (where it is not necessary).

[editline]11:36PM[/editline]

It’s valid in any Lua-Interpreter. Garry did not add it manually.

My bad. I was thinking of the other changes. Though “;” was custom.